eslint-plugin-coffee
raw JSON → 0.1.15 verified Sat Apr 25 auth: no javascript
An ESLint plugin that provides a custom parser and rules for linting CoffeeScript source files. Version 0.1.15 requires CoffeeScript >=2.5.0 and ESLint >=6.0.0. It adapts the CoffeeScript compiler's AST to be compatible with ESLint, enabling many existing ESLint rules to work with CoffeeScript, and also supplies CoffeeScript-specific rules and compatible versions of rules from popular plugins like eslint-plugin-react, eslint-plugin-import, eslint-plugin-react-native, and eslint-plugin-jsx-a11y. The project is actively maintained with recent fixes for code path analysis and shorthand-this rule.
Common errors
error Error: Cannot find module 'eslint-plugin-coffee/parser' ↓
cause The parser module is not installed or cannot be resolved.
fix
Ensure
eslint-plugin-coffee is installed as a dev dependency: npm install --save-dev eslint-plugin-coffee. error ESLint configuration error: "coffee" plugin not found ↓
cause The plugin was not added to the `plugins` array.
fix
Add
"plugins": ["coffee"] to your ESLint config. error Parsing error: Unexpected token ↓
cause The CoffeeScript file might have syntax that the parser does not support, or the parser is not configured correctly.
fix
Ensure you have set
"parser": "eslint-plugin-coffee/parser" in your ESLint config and that your CoffeeScript version is >= 2.5.0. error Cannot find module 'coffeescript' ↓
cause CoffeeScript is not installed or the version is too old.
fix
Run
npm install --save-dev coffeescript@^2.5.0. Warnings
deprecated The `id-length` rule was changed to not be recommended (v0.1.13). ↓
fix If you relied on `id-length` being recommended, you must explicitly enable it: `'coffee/id-length': 'error'`.
gotcha Not all ESLint rules work out of the box; many require CoffeeScript-compatible custom alternatives provided by this plugin. ↓
fix Check the supported rules list in the README before enabling standard rules. Use `'coffee/rule-name'` for compatible versions.
breaking Requires CoffeeScript >=2.5.0 and ESLint >=6.0.0; does not work with older versions. ↓
fix Ensure your project uses CoffeeScript 2.5.0+ and ESLint 6.0.0+.
gotcha The parser may not fully support the latest CoffeeScript syntax or all ES modern features. ↓
fix Refer to the README for supported CoffeeScript version and be aware that some newer CoffeeScript features might not be linted correctly.
deprecated The `no-danger-with-children` rule now handles spread props correctly since v0.1.13. ↓
fix Update to v0.1.13 or later to get proper handling of spread props.
breaking ESLint code path analysis monkeypatching issue was fixed in v0.1.14. ↓
fix Update to v0.1.14 or later to avoid potential crashes with code path analysis.
gotcha The plugin only supports CommonJS modules for now; ESM projects may need transpilation. ↓
fix Use CommonJS or transpile your CoffeeScript project before linting.
Install
npm install eslint-plugin-coffee yarn add eslint-plugin-coffee pnpm add eslint-plugin-coffee Imports
- plugin wrong
Using require('eslint-plugin-coffee') as a parser without specifying plugincorrect// In .eslintrc: { "plugins": ["coffee"], "parser": "eslint-plugin-coffee/parser" } - parser wrong
const parser = require('eslint-plugin-coffee/parser')correctimport parser from 'eslint-plugin-coffee/parser' - rules wrong
Direct import of rules: import { rules } from 'eslint-plugin-coffee'correct// Access rules via 'eslint-plugin-coffee' plugin, e.g., rules: { 'coffee/rule-name': 'error' }
Quickstart
// Install dependencies:
// npm install --save-dev coffeescript@^2.5.0 eslint@^6.0.0 eslint-plugin-coffee
// .eslintrc.json
{
"parser": "eslint-plugin-coffee/parser",
"plugins": ["coffee"],
"rules": {
"coffee/boolean-keywords": "error",
"coffee/no-danger-with-children": "warn",
"coffee/shorthand-this": "error",
"semi": "error",
"no-unused-vars": "error"
}
}
// Example CoffeeScript file (test.coffee):
# This will lint with ESLint rules
x = 5
console.log x
// To lint:
// npx eslint test.coffee