CoffeeLint
raw JSON → 2.1.0 verified Fri May 01 auth: no javascript
CoffeeLint is a style checker for CoffeeScript that helps keep code consistent and avoid common mistakes. Version 2.1.0 (stable, released 2019) targets Node.js >=6.9.1. It provides over 20 built-in rules covering spacing, naming, and syntax pitfalls. Alternatives like coffeelint-stylish offer custom reporters, but CoffeeLint remains the standard linter for the CoffeeScript ecosystem.
Common errors
error TypeError: config is not a function ↓
cause Calling lint(source, configFunction) instead of lint(source, config). require('coffeelint') is not the lint function.
fix
Use coffeelint.lint(source, config) – note, coffeelint is required, not coffeelint.lint.
error Error: Cannot find module 'coffee-script' ↓
cause coffee-script is a peer dependency not automatically installed.
fix
Run npm install coffee-script --save-dev
error Ignoring file because extension is not .coffee or .litcoffee ↓
cause CoffeeLint only scans .coffee and .litcoffee files by default.
fix
Pass a custom glob pattern or rename your file to have .coffee extension.
Warnings
breaking v2.0.0 dropped Node.js 4 support; requires Node >=6.9.1. ↓
fix Update Node.js to v6.9.1 or later.
deprecated Rule 'no_tabs' is deprecated in favor of 'indentation'. ↓
fix Use 'indentation' rule with 'tabs' option.
gotcha Config option 'level' for a rule is case-sensitive; only 'error', 'warn', or 'ignore' accepted. ↓
fix Ensure level strings are lowercase exactly.
gotcha CoffeeLint uses its own CoffeeScript parser (coffee-script) and may produce different results than the official compiler version. ↓
fix Pin coffee-script version to match your project's compiler version.
Install
npm install coffeelint yarn add coffeelint pnpm add coffeelint Imports
- coffeelint wrong
import coffeelint from 'coffeelint';correctconst coffeelint = require('coffeelint'); - coffeelint.lint wrong
coffeelint.lint(source, options);correctcoffeelint.lint(source, config, options); - coffeelint.registerRule wrong
coffeelint.registerRule(rule);correctcoffeelint.registerRule(rule, ruleName);
Quickstart
const coffeelint = require('coffeelint');
const fs = require('fs');
const source = fs.readFileSync('./example.coffee', 'utf8');
const config = {
max_line_length: {
level: 'warn',
value: 80
},
no_trailing_whitespace: {
level: 'error'
}
};
const errors = coffeelint.lint(source, config);
if (errors.length) {
errors.forEach(err => console.log(`Line ${err.lineNumber}: ${err.message} (${err.rule})`));
} else {
console.log('No lint errors!');
}