Home

Awesome

eslint-plugin-coffee

ESLint custom parser + rules for linting CoffeeScript source files

Table of Contents

Getting Started

The following sections will give you an overview of what this project is, why it exists and how it works.

If you are ready to get started you can jump to Installation.

Why does this project exist?

ESLint is the preeminent linter in the JavaScript world.

As of CoffeeScript v2.5.0, the CoffeeScript compiler exposes an Abstract Syntax Tree (AST) representation of your source code which enables usage with AST-based tools like ESLint.

eslint-plugin-coffee is the package that allows you to use ESLint in CoffeeScript-based projects :sparkles: :rainbow: :sparkles:

How does eslint-plugin-coffee work?

The AST (see above) produced by CoffeeScript is different than the AST format that ESLint requires to work.

This means that by default, the CoffeeScript AST is not compatible with the 1000s of rules which have been written by and for ESLint users over the many years the project has been going.

The great thing is, though, we can provide ESLint with an alternative parser to use - that is a first-class use case offered by ESLint. eslint-plugin-coffee provides ESLint with that alternative parser for CoffeeScript.

At that point, ESLint is capable of "digesting" CoffeeScript source code. But what about the rules? Keep reading...

Can I use all of the existing ESLint plugins and rules without any changes?

The short answer is, no.

The great news is, there are many rules which will "just work" without you having to change anything about them or provide any custom alternatives.

For rules which don't "just work" for CoffeeScript, eslint-plugin-coffee aims to provide a CoffeeScript-compatible custom alternative rule - this includes rules that come with ESLint, as well as from the popular ESLint plugins eslint-plugin-react, eslint-plugin-import, eslint-plugin-react-native, and eslint-plugin-jsx-a11y.

Here's a guide to all of the supported rules.

Installation

Make sure you have supported versions of CoffeeScript and ESLint installed and install the plugin:

yarn:

yarn add --dev coffeescript@^2.5.0 eslint@^6.0.0 eslint-plugin-coffee

npm:

npm install --save-dev coffeescript@^2.5.0 eslint@^6.0.0 eslint-plugin-coffee

Usage

Add eslint-plugin-coffee to the parser field and coffee to the plugins section of your .eslintrc configuration file, and disable ESLint rules that aren't compatible with CoffeeScript:

{
  "parser": "eslint-plugin-coffee",
  "plugins": ["coffee"],
  "extends": [
    "plugin/coffee:disable-incompatible"
  ]
}

Then configure the rules you want to use under the rules section.

{
  "parser": "eslint-plugin-coffee",
  "plugins": ["coffee"],
  "rules": {
    // Can include existing rules that "just work":
    "no-undef": "error",
    "react/no-array-index-key": "error",
    // ...CoffeeScript-specific rules:
    "coffee/spread-direction": ["error", "postfix"],
    // ...and CoffeeScript custom overriding rules.
    // For these, the corresponding existing rule should also be disabled if need be:
    "no-unused-vars": "off",
    "coffee/no-unused-vars": "error"
}

To apply eslint:recommended (the set of rules which are recommended for all projects by the ESLint team) with this plugin, add plugin:coffee/eslint-recommended (which will adjust the eslint:recommended config appropriately for CoffeeScript) to your config:

{
  "extends": [
    "plugin:coffee/eslint-recommended"
  ]
}

To apply the well-known Airbnb config with this plugin, add plugin:coffee/airbnb (for React projects) or plugin:coffee/airbnb-base (for non-React projects) to your config:

{
  "extends": [
    // for React projects:
    "plugin:coffee/airbnb",
    // OR for non-React projects:
    "plugin:coffee/airbnb-base"
  ],
  "rules": {
    // You may then want to disable some of the more "controversial" Airbnb rules
    // when applied to CoffeeScript, e.g.:
    "coffee/implicit-arrow-linebreak": "off",
    "coffee/comma-style": "off",
    "coffee/jsx-wrap-multilines": "off"
  }
}

eslint-plugin-import

If you want to use rules from eslint-plugin-import (whether rules that "just work" or CoffeeScript custom overrides), add plugin:coffee/import (which configures eslint-plugin-import to work with CoffeeScript) to your config, along with the rules you want to use:

{
  "extends": [
    "plugin:coffee/import"
  ],
  "rules": {
    // Can include existing rules that "just work":
    "import/no-unresolved": "error",
    // ...and CoffeeScript custom overriding rules.
    // For these, the corresponding existing rule should also be disabled if need be:
    "import/no-anonymous-default-export": "off",
    "coffee/no-anonymous-default-export": "error",
  }
}

See below for a list of all supported rules from eslint-plugin-import.

eslint-plugin-react, eslint-plugin-react-native, eslint-plugin-jsx-a11y

If you want to use rules from eslint-plugin-react, eslint-plugin-react-native and/or eslint-plugin-jsx-a11y (whether rules that "just work" or CoffeeScript custom overrides), add those plugins and rules to your config:

{
  "plugins": [
    "coffee",
    "react",
    "react-native",
    "jsx-a11y"
  ],
  "rules": {
    // Can include existing rules that "just work":
    "react/no-array-index-key": "error",
    "react-native/no-inline-styles": "error",
    "jsx-a11y/accessible-emoji": "error",
    // ...and CoffeeScript custom overriding rules.
    // For these, the corresponding existing rule should also be disabled if need be:
    "react/prop-types": "off",
    "coffee/prop-types": "error",
    "react-native/no-unused-styles": "off",
    "coffee/no-unused-styles": "error",
  }
} 

To apply the recommended config from eslint-plugin-react, add plugin:coffee/react-recommended to your config:

{
  "extends": [
    "plugin:coffee/react-recommended"
  ]
}

To apply the all config from eslint-plugin-react, add plugin:coffee/react-all to your config:

{
  "extends": [
    "plugin:coffee/react-all"
  ]
}

To apply the recommended config from eslint-plugin-jsx-a11y, add plugin:jsx-a11y/recommended to your config:

{
  "plugins: [
    "coffee",
    "jsx-a11y"
  ],
  "extends": [
    "plugin:jsx-a11y/recommended"
  ]
}

To apply the strict config from eslint-plugin-jsx-a11y, add plugin:jsx-a11y/strict to your config:

{
  "plugins: [
    "coffee",
    "jsx-a11y"
  ],
  "extends": [
    "plugin:jsx-a11y/strict"
  ]
}

See below for a list of all supported rules from eslint-plugin-react, eslint-plugin-react-native and eslint-plugin-jsx-a11y.

Running from the command line

To invoke ESLint from the command line, you can add an appropriate script to your package.json scripts section, for example:

{
  "scripts": {
    "lint": "eslint 'src/**/*.coffee'",
    "lint-fix": "eslint --fix 'src/**/*.coffee'"
  }
}

Then you can invoke those scripts as needed from the command line to lint the CoffeeScript source files in your project:

npm run lint

Running from your editor

Running ESLint directly from your code editor (e.g. on save) provides a quick feedback loop while developing.

Depending on your editor, there may or may not currently be a straightforward way to get ESLint running against .coffee files (e.g. using an ESLint editor plugin).

If you're having trouble getting ESLint running in your editor (and it's not listed below), please file an issue and we'll try and help with support for your editor.

VS Code

To run ESLint from VS Code, first install the VS Code ESLint extension.

Then add to your VS Code settings.json:

"eslint.validate": [
    // "javascript", "javascriptreact" is the default setting
    "javascript",
    "javascriptreact",
    {
        "language": "coffeescript",
        "autoFix": true
    },
]

Sublime Text

From @PatrickKing:

"linters": {
    "eslint": {
        "selector": "source.js - meta.attribute-with-value, source.coffee"
    }
}

Other editors

We will add instructions for different code editors here as they become supported.

If you've gotten ESLint running in an editor not listed here and would like to share back, please file an issue!

Usage with Prettier

You can now use Prettier to format your CoffeeScript code, see the Prettier CoffeeScript plugin README for instructions.

To disable our code formatting related rules, install eslint-config-prettier:

npm install --save-dev eslint-config-prettier

Then use the prettier config exposed by this plugin:

{
  "extends": ["plugin:coffee/prettier"]
}

Alternatively, if you want to run Prettier as an ESLint rule (a nice option especially if you're running ESLint in fix mode via your editor):

npm install --save-dev eslint-config-prettier eslint-plugin-prettier

Then use the prettier-run-as-rule config exposed by this plugin:

{
  "extends": ["plugin:coffee/prettier-run-as-rule"]
}

Supported Rules

Key: :heavy_check_mark: = ESLint recommended, :wrench: = fixable

ESLint-included rules

Possible Errors

NameDescription
:heavy_check_mark:coffee/no-async-promise-executordisallow using an async function as a Promise executor
coffee/no-await-in-loopdisallow await inside of loops
:heavy_check_mark:coffee/no-compare-neg-zerodisallow comparing against -0
:heavy_check_mark:coffee/no-cond-assigndisallow assignment operators in conditional expressions
no-consoledisallow the use of console
:heavy_check_mark:coffee/no-constant-conditiondisallow constant expressions in conditions
:heavy_check_mark:no-control-regexdisallow control characters in regular expressions
:heavy_check_mark:no-debuggerdisallow the use of debugger
:heavy_check_mark:no-dupe-keysdisallow duplicate keys in object literals
:heavy_check_mark:no-duplicate-casedisallow duplicate case labels
:heavy_check_mark:no-emptydisallow empty block statements
:heavy_check_mark:coffee/no-empty-character-classdisallow empty character classes in regular expressions
:heavy_check_mark:no-ex-assigndisallow reassigning exceptions in catch clauses
:heavy_check_mark:coffee/no-extra-boolean-castdisallow unnecessary boolean casts <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
:heavy_check_mark:coffee/no-inner-declarationsdisallow variable or function "declarations" in nested blocks
:heavy_check_mark:no-invalid-regexpdisallow invalid regular expression strings in RegExp constructors
:heavy_check_mark:no-irregular-whitespacedisallow irregular whitespace
:heavy_check_mark:no-misleading-character-classdisallow characters which are made with multiple code points in character class syntax
:heavy_check_mark:no-obj-callsdisallow calling global object properties as functions
:heavy_check_mark:no-prototype-builtinsdisallow calling some Object.prototype methods directly on objects
:heavy_check_mark::wrench:coffee/no-regex-spacesdisallow multiple spaces in regular expressions
:heavy_check_mark:no-sparse-arraysdisallow sparse arrays
coffee/no-template-curly-in-stringdisallow template literal placeholder syntax in regular strings
:heavy_check_mark:coffee/no-unreachabledisallow unreachable code after return, throw, continue, and break statements
:heavy_check_mark:no-unsafe-finallydisallow control flow statements in finally blocks
:heavy_check_mark:coffee/no-unsafe-negationdisallow negating the left operand of relational operators
:heavy_check_mark:require-atomic-updatesdisallow assignments that can lead to race conditions due to usage of await or yield
:heavy_check_mark:coffee/use-isnanrequire calls to isNaN() when checking for NaN
:heavy_check_mark:coffee/valid-typeofenforce comparing typeof expressions against valid strings

Best Practices

NameDescription
accessor-pairsenforce getter and setter pairs in objects and classes <br> :warning: Only checks e.g. Object.defineProperty() since CoffeeScript doesn't support getters/setters
coffee/block-scoped-varenforce the use of variables within the scope they are defined
coffee/class-methods-use-thisenforce that class methods utilize this
coffee/complexityenforce a maximum cyclomatic complexity allowed in a program
default-caserequire else cases in switch statements
:wrench:coffee/dot-locationenforce consistent newlines before and after dots
:wrench:coffee/dot-notationenforce dot notation whenever possible
coffee/guard-for-inrequire for-of loops to include own or an if statement
max-classes-per-fileenforce a maximum number of classes per file
no-alertdisallow the use of alert, confirm, and prompt
no-callerdisallow the use of arguments.caller or arguments.callee
:wrench:coffee/no-div-regexdisallow division operators explicitly at the beginning of regular expressions
coffee/no-else-returndisallow else blocks after return statements in if statements <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
coffee/no-empty-functiondisallow empty functions
:heavy_check_mark:no-empty-patterndisallow empty destructuring patterns
no-evaldisallow the use of eval()
no-extend-nativedisallow extending native types
:wrench:coffee/no-extra-binddisallow unnecessary calls to .bind()
:wrench:no-floating-decimaldisallow leading or trailing decimal points in numeric literals
:heavy_check_mark:no-global-assigndisallow assignments to native objects or read-only global variables <br> :warning: Only applies to e.g. ++ operations since CoffeeScript generates declarations on other write references.
:wrench:coffee/no-implicit-coerciondisallow shorthand type conversions
no-implied-evaldisallow the use of eval()-like methods
coffee/no-invalid-thisdisallow this keywords outside of classes or class-like objects
no-iteratordisallow the use of the __iterator__ property
coffee/no-loop-funcdisallow function declarations that contain unsafe references inside loop statements
coffee/no-magic-numbersdisallow magic numbers
:wrench:coffee/no-multi-spacesdisallow multiple spaces
coffee/no-newdisallow new operators outside of assignments or comparisons
no-new-funcdisallow new operators with the Function object
no-new-wrappersdisallow new operators with the String, Number, and Boolean objects
no-param-reassigndisallow reassigning function parameters
no-protodisallow the use of the __proto__ property
no-restricted-propertiesdisallow certain properties on certain objects
coffee/no-return-assigndisallow assignment operators in return statements <br> :warning: Currently, this also flags assignments in implicit return statements
no-script-urldisallow javascript: urls
:heavy_check_mark:coffee/no-self-assigndisallow assignments where both sides are exactly the same
coffee/no-self-comparedisallow comparisons where both sides are exactly the same
coffee/no-sequencesdisallow semicolon operators
no-throw-literaldisallow throwing literals as exceptions
coffee/no-unmodified-loop-conditiondisallow unmodified loop conditions
coffee/no-unused-expressionsdisallow unused expressions
no-useless-calldisallow unnecessary calls to .call() and .apply()
:heavy_check_mark:no-useless-catchdisallow unnecessary catch clauses
no-useless-concatdisallow unnecessary concatenation of literals or template literals
:heavy_check_mark:coffee/no-useless-escapedisallow unnecessary escape characters
:wrench:coffee/no-useless-returndisallow redundant return statements
no-warning-commentsdisallow specified warning terms in comments
prefer-promise-reject-errorsrequire using Error objects as Promise rejection reasons
radixenforce the consistent use of the radix argument when using parseInt()
require-unicode-regexpenforce the use of u flag on RegExp
coffee/vars-on-toprequire "declarations" be placed at the top of their containing scope
coffee/yodarequire or disallow "Yoda" conditions <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
:heavy_check_mark:no-delete-vardisallow deleting variables
no-restricted-globalsdisallow specified global variables
coffee/no-shadowdisallow variable declarations from shadowing variables declared in the outer scope
:heavy_check_mark:no-undefdisallow the use of undeclared variables unless mentioned in ###global ### comments
:heavy_check_mark:coffee/no-unused-varsdisallow unused variables
coffee/no-use-before-definedisallow the use of variables before they are "defined"

Node.js and CommonJS

NameDescription
coffee/callback-returnrequire return statements after callbacks
global-requirerequire require() calls to be placed at top-level module scope
handle-callback-errrequire error handling in callbacks
no-buffer-constructordisallow use of the Buffer() constructor
no-new-requiredisallow new operators with calls to require
no-path-concatdisallow string concatenation with __dirname and __filename
no-process-envdisallow the use of process.env
no-process-exitdisallow the use of process.exit()
no-restricted-modulesdisallow specified modules when loaded by require
no-syncdisallow synchronous methods

Stylistic Issues

NameDescription
coffee/array-bracket-newlineenforce linebreaks after opening and before closing array brackets <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
:wrench:coffee/array-bracket-spacingenforce consistent spacing inside array brackets
coffee/array-element-newlineenforce line breaks after each array element <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
coffee/camelcaseenforce camelcase naming convention
:wrench:coffee/capitalized-commentsenforce or disallow capitalization of the first letter of a comment
:wrench:comma-spacingenforce consistent spacing before and after commas
coffee/comma-styleenforce consistent comma style <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
:wrench:computed-property-spacingenforce consistent spacing inside computed property brackets
coffee/consistent-thisenforce consistent naming when capturing the current execution context
:wrench:eol-lastrequire or disallow newline at the end of files
coffee/function-paren-newlineenforce consistent line breaks inside function parentheses <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
id-blacklistdisallow specified identifiers
coffee/id-lengthenforce minimum and maximum identifier lengths
coffee/id-matchrequire identifiers to match a specified regular expression
coffee/implicit-arrow-linebreakenforce the location of function bodies <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
:wrench:jsx-quotesenforce the consistent use of either double or single quotes in JSX attributes
:wrench:key-spacingenforce consistent spacing between keys and values in object literal properties
:wrench:coffee/keyword-spacingenforce consistent spacing before and after keywords
line-comment-positionenforce position of line comments
:wrench:linebreak-styleenforce consistent linebreak style
:wrench:coffee/lines-around-commentrequire empty lines around comments
coffee/lines-between-class-membersrequire or disallow an empty line between class members <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
coffee/max-depthenforce a maximum depth that blocks can be nested
coffee/max-lenenforce a maximum line length
max-linesenforce a maximum number of lines per file
coffee/max-lines-per-functionenforce a maximum number of line of code in a function
max-nested-callbacksenforce a maximum depth that callbacks can be nested
max-paramsenforce a maximum number of parameters in function definitions
max-statementsenforce a maximum number of statements allowed in function blocks
:wrench:coffee/multiline-comment-styleenforce a particular style for multiline comments
new-caprequire constructor names to begin with a capital letter
:wrench:new-parensenforce or disallow parentheses when invoking a constructor with no arguments
coffee/newline-per-chained-callrequire a newline after each call in a method chain <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
no-array-constructordisallow Array constructors
no-bitwisedisallow bitwise operators
no-continuedisallow continue statements
no-inline-commentsdisallow inline comments after code
coffee/no-lonely-ifdisallow if statements as the only statement in else blocks <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
coffee/no-mixed-operatorsdisallow mixed binary operators
no-multi-assigndisallow use of chained assignment expressions
:wrench:coffee/no-multiple-empty-linesdisallow multiple empty lines
coffee/no-negated-conditiondisallow negated conditions
no-new-objectdisallow Object constructors
no-plusplusdisallow the unary operators ++ and --
no-restricted-syntaxdisallow specified syntax
no-tabsdisallow all tabs
:wrench:no-trailing-spacesdisallow trailing whitespace at the end of lines
coffee/no-underscore-dangledisallow dangling underscores in identifiers
:wrench:coffee/no-unneeded-ternarydisallow if/else expressions when simpler alternatives exist
:wrench:coffee/no-whitespace-before-propertydisallow whitespace before properties
:wrench:coffee/object-curly-spacingenforce consistent spacing inside braces
coffee/object-property-newlineenforce placing object properties on separate lines <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
:wrench:coffee/operator-assignmentrequire or disallow assignment operator shorthand where possible
coffee/operator-linebreakenforce consistent linebreak style for operators <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
coffee/prefer-object-spreaddisallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
:wrench:quote-propsrequire quotes around object literal property names
sort-keysrequire object keys to be sorted
:wrench:space-in-parensenforce consistent spacing inside parentheses
:wrench:coffee/space-infix-opsrequire spacing around infix operators
:wrench:coffee/space-unary-opsenforce consistent spacing before or after unary operators
:wrench:coffee/spaced-commentenforce consistent spacing after the # or ### in a comment
:wrench:unicode-bomrequire or disallow Unicode byte order mark (BOM)
:wrench:coffee/wrap-regexrequire parenthesis around regex literals

"ECMAScript 6"

NameDescription
:wrench:coffee/arrow-spacingenforce consistent spacing before and after the arrow in functions
:heavy_check_mark:constructor-superrequire super() calls in constructors
:heavy_check_mark:coffee/no-class-assigndisallow reassigning class members
:heavy_check_mark:no-dupe-class-membersdisallow duplicate class members
no-duplicate-importsdisallow duplicate module imports
:heavy_check_mark:no-new-symboldisallow new operators with the Symbol object
no-restricted-importsdisallow specified modules when loaded by import
:heavy_check_mark:coffee/no-this-before-superdisallow this/super before calling super() in constructors
:wrench:coffee/no-useless-computed-keydisallow unnecessary computed property keys in objects and classes
coffee/no-useless-constructordisallow unnecessary constructors
:wrench:no-useless-renamedisallow renaming import, export, and destructured assignments to the same name
coffee/object-shorthandrequire or disallow method and property shorthand syntax for object literals <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
coffee/prefer-destructuringrequire destructuring from arrays and/or objects <br> :warning: Unlike the ESLint rule, the CoffeeScript version is not fixable
:wrench:prefer-numeric-literalsdisallow parseInt() and Number.parseInt() in favor of binary, octal, and hexadecimal literals
prefer-rest-paramsrequire rest parameters instead of arguments
prefer-spreadrequire spread operators instead of .apply()
:wrench:coffee/prefer-templaterequire interpolated strings instead of string concatenation
:wrench:coffee/rest-spread-spacingenforce spacing between rest and spread operators and their expressions
:wrench:sort-importsenforce sorted import declarations within modules
symbol-descriptionrequire symbol descriptions
:wrench:coffee/template-curly-spacingrequire or disallow spacing around embedded expressions of template strings

CoffeeScript-specific rules

NameDescription
coffee/capitalized-class-namesEnforce capitalization of the first letter of a class name
coffee/no-backticksDisallow use of the backtick operator
coffee/english-operatorsEnforce or disallow use of "English" operators
coffee/implicit-objectDisallow implicit objects
coffee/implicit-callDisallow implicit function calls
coffee/empty-func-parensEnforce or disallow the use of parentheses for empty parameter lists
coffee/shorthand-thisEnforce or disallow use of @ vs this
coffee/spread-directionEnforce consistent use of prefix vs postfix ...
:wrench:coffee/postfix-comprehension-assign-parensRequire parentheses around potentially confusing assignments in postfix comprehensions
coffee/no-nested-interpolationDisallow nesting interpolations
coffee/no-private-function-fat-arrowsDisallow use of => for "private" functions in class bodies
coffee/no-unnecessary-double-quotesDisallow use of double quotes for strings when single quotes would suffice
:wrench:coffee/boolean-keywordsRequire or disallow usage of specific boolean keywords

eslint-plugin-react rules

Key: :heavy_check_mark: = recommended, :wrench: = fixable

NameDescription
coffee/boolean-prop-namingEnforces consistent naming for boolean props
react/button-has-typeForbid "button" element without an explicit "type" attribute
coffee/default-props-match-prop-typesPrevent extraneous defaultProps on components
coffee/destructuring-assignmentRule enforces consistent usage of destructuring assignment in component
:heavy_check_mark:coffee/display-namePrevent missing displayName in a React component definition
react/forbid-component-propsForbid certain props on Components
react/forbid-dom-propsForbid certain props on DOM Nodes
react/forbid-elementsForbid certain elements
coffee/forbid-prop-typesForbid certain propTypes
react/forbid-foreign-prop-typesForbid foreign propTypes
coffee/no-access-state-in-setstatePrevent using this.state inside this.setState
react/no-array-index-keyPrevent using Array index in key props
:heavy_check_mark:react/no-children-propPrevent passing children as props
react/no-dangerPrevent usage of dangerous JSX properties
:heavy_check_mark:coffee/no-danger-with-childrenPrevent problem with children and props.dangerouslySetInnerHTML
:heavy_check_mark:coffee/no-deprecatedPrevent usage of deprecated methods, including component lifecycle methods
react/no-did-mount-set-statePrevent usage of setState in componentDidMount
react/no-did-update-set-statePrevent usage of setState in componentDidUpdate
:heavy_check_mark:react/no-direct-mutation-statePrevent direct mutation of this.state
:heavy_check_mark:react/no-find-dom-nodePrevent usage of findDOMNode
:heavy_check_mark:react/no-is-mountedPrevent usage of isMounted
coffee/no-multi-compPrevent multiple component definition per file
coffee/no-redundant-should-component-updatePrevent usage of shouldComponentUpdate when extending React.PureComponent
:heavy_check_mark:coffee/no-render-return-valuePrevent usage of the return value of React.render
react/no-set-statePrevent usage of setState
coffee/no-typosPrevent common casing typos
:heavy_check_mark:react/no-string-refsPrevent using string references in ref attribute.
coffee/no-this-in-sfcPrevent using this in stateless functional components
:heavy_check_mark:coffee/no-unescaped-entitiesPrevent invalid characters from appearing in markup
:heavy_check_mark::wrench:react/no-unknown-propertyPrevent usage of unknown DOM property
react/no-unsafePrevent usage of unsafe lifecycle methods
coffee/no-unused-prop-typesPrevent definitions of unused prop types
coffee/no-unused-statePrevent definitions of unused state properties
react/no-will-update-set-statePrevent usage of setState in componentWillUpdate
react/prefer-es6-classEnforce ES5 or ES6 class for React Components
coffee/prefer-stateless-functionEnforce stateless React Components to be written as a pure function
:heavy_check_mark:coffee/prop-typesPrevent missing props validation in a React component definition
:heavy_check_mark:react/react-in-jsx-scopePrevent missing React when using JSX
coffee/require-default-propsEnforce a defaultProps definition for every prop that is not a required prop
react/require-optimizationEnforce React components to have a shouldComponentUpdate method
:wrench:react/self-closing-compPrevent extra closing tags for components without children
coffee/sort-compEnforce component methods order <br> :warning: Unlike the eslint-plugin-react rule, the CoffeeScript version is not fixable
coffee/sort-prop-typesEnforce propTypes declarations alphabetical sorting
react/static-property-placementEnforces where React component static properties should be positioned
coffee/style-prop-objectEnforce style prop value being an object
react/void-dom-elements-no-childrenPrevent void DOM elements (e.g. <img />, <br />) from receiving children

JSX-specific rules

NameDescription
coffee/jsx-boolean-valueEnforce boolean attributes notation in JSX <br> :warning: Unlike the eslint-plugin-react rule, the CoffeeScript version is not fixable
react/jsx-child-element-spacingEnforce or disallow spaces inside of curly braces in JSX attributes and expressions.
:wrench:coffee/jsx-closing-bracket-locationValidate closing bracket location in JSX
:wrench:react/jsx-closing-tag-locationValidate closing tag location in JSX
coffee/jsx-curly-newlineEnforce or disallow newlines inside of curly braces in JSX attributes and expressions <br> :warning: Unlike the eslint-plugin-react rule, the CoffeeScript version is not fixable
:wrench:react/jsx-curly-spacingEnforce or disallow spaces inside of curly braces in JSX attributes and expressions
:wrench:react/jsx-equals-spacingEnforce or disallow spaces around equal signs in JSX attributes
react/jsx-filename-extensionRestrict file extensions that may contain JSX
coffee/jsx-first-prop-new-lineEnforce position of the first prop in JSX <br> :warning: Unlike the eslint-plugin-react rule, the CoffeeScript version is not fixable
coffee/jsx-handler-namesEnforce event handler naming conventions in JSX
:wrench:coffee/jsx-indentValidate JSX indentation
:wrench:react/jsx-indent-propsValidate props indentation in JSX
:heavy_check_mark:coffee/jsx-keyValidate JSX has key prop when in array or iterator
react/jsx-max-depthValidate JSX maximum depth
coffee/jsx-max-props-per-lineLimit maximum of props on a single line in JSX <br> :warning: Unlike the eslint-plugin-react rule, the CoffeeScript version is not fixable
coffee/jsx-no-bindPrevent usage of .bind() and arrow functions in JSX props
:heavy_check_mark:coffee/jsx-no-comment-textnodesPrevent comments from being inserted as text nodes
:heavy_check_mark:react/jsx-no-duplicate-propsPrevent duplicate props in JSX
react/jsx-no-literalsPrevent usage of unwrapped JSX strings
:heavy_check_mark:coffee/jsx-no-target-blankPrevent usage of unsafe target='_blank'
:heavy_check_mark:react/jsx-no-undefDisallow undeclared variables in JSX
coffee/jsx-one-expression-per-lineLimit to one expression per line in JSX
:wrench:react/jsx-curly-brace-presenceEnforce curly braces or disallow unnecessary curly braces in JSX
:wrench:coffee/jsx-fragmentsEnforce shorthand or standard form for React fragments
react/jsx-pascal-caseEnforce PascalCase for user-defined JSX components
:wrench:react/jsx-props-no-multi-spacesDisallow multiple spaces between inline JSX props
react/jsx-props-no-spreadingDisallow JSX props spreading
coffee/jsx-sort-default-propsEnforce default props alphabetical sorting
:wrench:react/jsx-sort-propsEnforce props alphabetical sorting
:wrench:coffee/jsx-tag-spacingValidate whitespace in and around the JSX opening and closing brackets
:heavy_check_mark:react/jsx-uses-reactPrevent React to be incorrectly marked as unused
:heavy_check_mark:react/jsx-uses-varsPrevent variables used in JSX to be incorrectly marked as unused
coffee/jsx-wrap-multilinesPrevent missing parentheses around multilines JSX <br> :warning: Unlike the eslint-plugin-react rule, the CoffeeScript version is not fixable

eslint-plugin-import rules

Static analysis

NameDescription
import/no-unresolvedEnsure imports point to a file/module that can be resolved
import/namedEnsure named imports correspond to a named export in the remote file
import/defaultEnsure a default export is present, given a default import
coffee/namespaceEnsure imported namespaces contain dereferenced properties as they are dereferenced
import/no-restricted-pathsRestrict which files can be imported in a given folder
import/no-absolute-pathForbid import of modules using absolute paths
import/no-dynamic-requireForbid require() calls with expressions
import/no-internal-modulesPrevent importing the submodules of other modules
import/no-webpack-loader-syntaxForbid webpack loader syntax in imports
import/no-self-importForbid a module from importing itself
import/no-cycleForbid a module from importing a module with a dependency path back to itself
import/no-useless-path-segmentsPrevent unnecessary path segments in import and require statements
import/no-relative-parent-importsForbid importing modules from parent directories
coffee/no-unused-modulesForbid modules without any export, and exports not imported by any modules

Helpful warnings

NameDescription
coffee/exportReport any invalid exports, i.e. re-export of the same name
import/no-named-as-defaultReport use of exported name as identifier of default export
coffee/no-named-as-default-memberReport use of exported name as property of default export
coffee/no-deprecated--importReport imported names marked with @deprecated documentation tag
import/no-extraneous-dependenciesForbid the use of extraneous packages

Module systems

NameDescription
coffee/no-commonjsReport CommonJS require calls and module.exports or exports.*.
import/no-amdReport AMD require and define calls.
import/no-nodejs-modulesNo Node.js builtin modules.

Style guide

NameDescription
:wrench:import/firstEnsure all imports appear before other statements
import/exports-lastEnsure all exports appear after other statements
:wrench:import/no-duplicatesReport repeated import of the same module in multiple places
import/no-namespaceForbid namespace (a.k.a. "wildcard" *) imports <br> :warning: Unlike the eslint-plugin-import rule, the CoffeeScript version is not fixable
import/extensionsEnsure consistent use of file extension within the import path
:wrench:coffee/orderEnforce a convention in module import order
:wrench:import/newline-after-importEnforce a newline after import statements
import/prefer-default-exportPrefer a default export if module exports a single name
import/max-dependenciesLimit the maximum number of dependencies a module can have
import/no-unassigned-importForbid unassigned imports
import/no-named-defaultForbid named default exports
coffee/no-default-exportForbid default exports
coffee/no-named-exportForbid named exports
coffee/no-anonymous-default-exportForbid anonymous values as default exports
import/group-exportsPrefer named exports to be grouped together in a single export declaration
coffee/dynamic-import-chunknameEnforce a leading comment with the webpackChunkName for dynamic imports

eslint-plugin-react-native rules

NameDescription
coffee/no-unused-stylesDetect StyleSheet rules which are not used in your React components
coffee/split-platform-componentsEnforce using platform specific filenames when necessary
react-native/no-inline-stylesDetect JSX components with inline styles that contain literal values
coffee/no-color-literalsDetect StyleSheet rules and inline styles containing color literals instead of variables

eslint-plugin-jsx-a11y rules

NameDescription
jsx-a11y/accessible-emojiEnforce emojis are wrapped in <span> and provide screenreader access
jsx-a11y/alt-textEnforce all elements that require alternative text have meaningful information to relay back to end user
jsx-a11y/anchor-has-contentEnforce all anchors to contain accessible content
jsx-a11y/anchor-is-validEnforce all anchors are valid, navigable elements
jsx-a11y/aria-activedescendant-has-tabindexEnforce elements with aria-activedescendant are tabbable
jsx-a11y/aria-propsEnforce all aria-* props are valid
jsx-a11y/aria-proptypesEnforce ARIA state and property values are valid
jsx-a11y/aria-roleEnforce that elements with ARIA roles must use a valid, non-abstract ARIA role
jsx-a11y/aria-unsupported-elementsEnforce that elements that do not support ARIA roles, states, and properties do not have those attributes
jsx-a11y/click-events-have-key-eventsEnforce a clickable non-interactive element has at least one keyboard event listener
jsx-a11y/heading-has-contentEnforce heading (h1, h2, etc) elements contain accessible content
jsx-a11y/html-has-langEnforce <html> element has lang prop
jsx-a11y/iframe-has-titleEnforce iframe elements have a title attribute
jsx-a11y/img-redundant-altEnforce <img> alt prop does not contain the word "image", "picture", or "photo"
jsx-a11y/interactive-supports-focusEnforce that elements with interactive handlers like onClick must be focusable
jsx-a11y/label-has-associated-controlEnforce that a label tag has a text label and an associated control
jsx-a11y/langEnforce lang attribute has a valid value
jsx-a11y/mouse-events-have-key-eventsEnforce that onMouseOver/onMouseOut are accompanied by onFocus/onBlur for keyboard-only users
jsx-a11y/no-autofocusEnforce autoFocus prop is not used
jsx-a11y/no-distracting-elementsEnforce distracting elements are not used
jsx-a11y/no-interactive-element-to-noninteractive-roleInteractive elements should not be assigned non-interactive roles
jsx-a11y/no-noninteractive-element-interactionsNon-interactive elements should not be assigned mouse or keyboard event listeners
jsx-a11y/no-noninteractive-element-to-interactive-roleNon-interactive elements should not be assigned interactive roles
jsx-a11y/no-noninteractive-tabindextabIndex should only be declared on interactive elements
jsx-a11y/no-onchangeEnforce usage of onBlur over onChange on select menus for accessibility
jsx-a11y/no-redundant-rolesEnforce explicit role property is not the same as implicit/default role property on element
jsx-a11y/no-static-element-interactionsEnforce that non-interactive, visible elements (such as <div>) that have click handlers use the role attribute
jsx-a11y/role-has-required-aria-propsEnforce that elements with ARIA roles must have all required attributes for that role
jsx-a11y/role-supports-aria-propsEnforce that elements with explicit or implicit roles defined contain only aria-* properties supported by that role
jsx-a11y/scopeEnforce scope prop is only used on <th> elements
jsx-a11y/tabindex-no-positiveEnforce tabIndex value is not greater than zero

Non-applicable ESLint-included rules

Some rules included with ESLint, eslint-plugin-react and eslint-plugin-import don't apply to CoffeeScript. These include:

Supported CoffeeScript version

We will always endeavor to support the latest stable version of CoffeeScript.

The version range of CoffeeScript currently supported by this plugin is >=2.5.0.

Supported ESLint version

The version range of ESLint currently supported by this plugin is >=6.0.0.

Supported versions of eslint-plugin-react, eslint-plugin-import, eslint-plugin-react-native, eslint-plugin-jsx-a11y

The version range of eslint-plugin-react currently supported by this plugin is >=7.17.0.

The version range of eslint-plugin-import currently supported by this plugin is >=2.19.0.

The version range of eslint-plugin-react-native currently supported by this plugin is >=3.8.0.

The version range of eslint-plugin-jsx-a11y currently supported by this plugin is >=6.2.3.

Migrating from CoffeeLint

Here is a mapping from CoffeeLint rules to their corresponding ESLint rules:

CoffeeLint ruleESLint rule
arrow_spacingcoffee/arrow-spacing
braces_spacingcoffee/object-curly-spacing
camel_case_classescoffee/camelcase + coffee/capitalized-class-names
coffeescript_errorIf the CoffeeScript compiler fails to parse/produce AST for a source file, ESLint will report it as a parsing error.
colon_assignment_spacingkey-spacing
cyclomatic_complexitycoffee/complexity
duplicate_keyno-dupe-keys
empty_constructor_needs_parensnew-parens
ensure_comprehensionscoffee/postfix-comprehension-assign-parens <br> (this behavior is also covered if you're using Prettier)
eol_lasteol-last
indentationNot yet implemented. <br> (this behavior is also covered if you're using Prettier)
line_endingslinebreak-style
max_line_lengthcoffee/max-len
missing_fat_arrowscoffee/no-invalid-this
newlines_after_classesNot yet implemented. <br> (this behavior is also partially covered if you're using Prettier)
no_backtickscoffee/no-backticks
no_debuggerno-debugger
no_empty_functionscoffee/no-empty-function
no_empty_param_listcoffee/empty-func-parens
no_implicit_bracescoffee/implicit-object
no_implicit_parenscoffee/implicit-call
no_interpolation_in_single_quotescoffee/no-template-curly-in-string
no_nested_string_interpolationcoffee/no-nested-interpolation
no_plusplusno-plusplus
no_private_function_fat_arrowscoffee/no-private-function-fat-arrows
no_stand_alone_atcoffee/shorthand-this
no_tabsno-tabs
no_thiscoffee/shorthand-this
no_throwing_stringsno-throw-literal
no_trailing_semicolonsNot yet implemented. <br> (this behavior is also covered if you're using Prettier)
no_trailing_whitespaceno-trailing-spaces
no_unnecessary_double_quotescoffee/no-unnecessary-double-quotes
no_unnecessary_fat_arrowscoffee/no-unnecessary-fat-arrow
non_empty_constructor_needs_parenscoffee/implicit-call
prefer_english_operatorcoffee/english-operators
space_operatorscoffee/space-infix-ops + coffee/space-unary-ops
spacing_after_commacomma-spacing
transform_messes_up_line_numbersDoesn't apply.

If you haven't used ESLint before, you'll just need an .eslintrc config file in your project root - the Installation and Usage sections above cover how to get started. For further information, you may want to look at the official ESLint guide.

How can I help?

See an issue? Report it!

If you have the time and inclination, you can even take it a step further and submit a PR to improve the project.

License

eslint-plugin-coffee is licensed under the MIT License.