Forked from eslint-plugin-lodash
ESLint-plugin-underscore
Linting rules for Underscore
Installation
Install ESLint either locally or globally.
npm install eslint
If you installed ESLint
globally, you have to install the Underscore plugin
globally too. Otherwise, install it locally.
$ npm install eslint-plugin-underscore
Configuration
Add plugins
section and specify ESLint-plugin-underscore as a plugin.
{
"plugins": ["underscore"]
}
Finally, enable all of the rules that you would like to use.
{
"rules": {
"underscore/collection-return": 2,
"underscore/identity-shorthand": [2, "always"],
"underscore/jquery-each": [2, "never"],
"underscore/jquery-extend": [2, "never"],
"underscore/jquery-proxy": [2, "never"],
"underscore/matches-shorthand": [2, "always"],
"underscore/no-return-value-from-each-iteratee": 2,
"underscore/no-unnecessary-bind": 2,
"underscore/prefer-chain": [2, 3],
"underscore/prefer-compact": 2,
"underscore/prefer-constant": 2,
"underscore/prefer-filter": 2,
"underscore/prefer-findwhere": 2,
"underscore/prefer-invoke": 2,
"underscore/prefer-map": 2,
"underscore/prefer-matches": 2,
"underscore/prefer-noop": 2,
"underscore/prefer-pluck": 2,
"underscore/prefer-reject": 2,
"underscore/prefer-times": 2,
"underscore/prefer-underscore-method": 2,
"underscore/prefer-underscore-typecheck": 2,
"underscore/prefer-where": 2,
"underscore/preferred-alias": 2,
"underscore/prop-shorthand": [2, "always"],
"underscore/no-single-chain": 2,
"underscore/unwrap": 2,
"underscore/no-double-unwrap": 2,
"underscore/prefer-wrapper-method": 2,
"underscore/prefer-lodash-chain": 2,
"underscore/chain-style": [2, "as-needed"]
}
}
List of supported rules
List of Lodash rules which are not yet supported
- no-single-chain: Prevent chaining syntax for single method, e.g.
_(x).map().value()
. - unwrap: Prevent chaining without evaluation via
value()
or non-chainable methods like max()
. - no-double-unwrap: Do not use
.value()
on chains that have already ended (e.g. with max()
or reduce()
). - prefer-wrapper-method: Prefer using array and string methods in the chain and not the initial value, e.g.
_(str).split(' ')...
- prefer-lodash-chain: Prefer using Lodash chains (e.g.
_.map
) over native and mixed chains. - chain-style: Enforce a specific chain style: explicit, implicit, or explicit only when necessary.
License
ESLint-plugin-underscore is licensed under the MIT License.