eslint-plugin-square

Linting plugin containing Square's custom lint rules and configuration for JavaScript and related technologies.

Usage no npm install needed!

<script type="module">
  import eslintPluginSquare from 'https://cdn.skypack.dev/eslint-plugin-square';
</script>

README

eslint-plugin-square

npm version CI

This plugin contains lint rule definitions and configurations for ESLint specific to Square's needs. It serves mainly to consolidate Square's web frontend linting setup in one place. It is generally not recommended for public usage outside of Square.

Requirements

Usage

Install via yarn (or npm):

yarn add --dev eslint-plugin-square

Edit your .eslintrc.js configuration file to extend one of the available configurations from this plugin:

module.exports = {
  extends: ['plugin:square/base'], // Or other configuration.
};

Configurations

Name Description
base Rules and configuration for any JavaScript-based project. Includes recommended and optional rules from eslint, prettier, eslint-plugin-eslint-comments, eslint-plugin-import, eslint-plugin-unicorn, and more.
🔥 ember Ember.js-specific additions on top of base. Includes recommended and optional rules from eslint-plugin-ember, kebab-case filename enforcement with eslint-plugin-filenames, and more.
react React-specific additions on top of base.
strict A variety of stricter lint rules on top of base.
typescript TypeScript-specific additions on top of base. Use with @typescript-eslint/parser.

Rules enabled by these configurations should meet the following criteria:

  • They make sense in a wide variety of codebases (and have been tested in a variety of Square's applications).
  • They are generally acceptable and desirable (in terms of enforcing best practices, consistency, avoiding bugs) to most developers.
  • There is a practical migration path (autofixers, codemod, find-and-replace, manual fixes) for enabling them in most applications.

Custom rules

Each rule has emojis denoting:

  • What configuration it belongs to
  • 🔧 if some problems reported by the rule are automatically fixable by the --fix command line option
  • 💡 if some problems reported by the rule are manually fixable by editor suggestions
Name Category 🔥 🔧 💡
no-assert-ok-find Ember Testing 🔥 💡
no-handlebar-interpolation Ember
no-missing-tests Testing
no-restricted-files JavaScript
no-test-return-value Testing 🔥 💡
no-translation-key-interpolation Ember 🔥
require-await-function JavaScript 🔥 🔧
use-call-count-test-assert Testing 🔥 🔧
use-ember-find Ember Testing 🔥 🔧

Note that we prefer to upstream our custom lint rules to third-party ESLint plugins whenever possible. The rules that still remain here are typically here because:

  • We haven't found the appropriate ESLint plugin to upstream them to.
  • We haven't found the time to upstream them.
  • They are specific to Square in some way / not generic enough.

License

Copyright 2020 Square Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.