eslint-plugin-underscore
v0.0.10
Published
Underscore specific linting rules for ESLint
Downloads
1,574
Maintainers
Readme
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"],
// The below rules are not (yet) supported
"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
- collection-return: Always return a value in iteratees of Underscore collection methods that aren't
each
. - identity-shorthand: Prefer identity shorthand syntax.
- jquery-each: Standardize on either Underscore's or jQuery's each function.
- jquery-extend: Standardize on either Underscore's or jQuery's extend function.
- jquery-proxy: Standardize on either Underscore's bind or jQuery's proxy function.
- matches-shorthand: Prefer matches shorthand syntax.
- no-return-value-from-each-iteratee: Do not return a value from the iteratee of
_.each
. - no-unnecessary-bind: Prefer passing
thisArg
over binding. - prefer-chain: Prefer chain over nested Underscore calls.
- prefer-compact: Prefer
_.compact
over_.filter
for only truthy values. - prefer-constant: Prefer
_.constant
over functions returning literals. - prefer-filter: Prefer
_.filter
over_.each
with anif
statement inside. - prefer-findwhere: Prefer
_.findWhere
over_.find
when using matcher shorthand. (fixable) - prefer-invoke: Prefer using
_.invoke
over_.map
with a method call inside. - prefer-map: Prefer
_.map
over_.each
with apush
inside. - prefer-matches: Prefer
_.matches
over conditions likea.foo === 1 && a.bar === 2 && a.baz === 3
. - prefer-noop: Prefer
_.noop
over empty functions. - prefer-pluck: Prefer
_.pluck
over_.map
when using property shorthand. (fixable) - prefer-reject: Prefer
_.reject
over filter with!(expression)
orx.prop1 !== value
. - prefer-times: Prefer
_.times
over_.map
without using the iteratee's arguments. - prefer-underscore-method: Prefer using Underscore collection methods (e.g.
_.map
) over native array methods. - prefer-underscore-typecheck: Prefer using
_.is*
methods overtypeof
andinstanceof
checks when applicable. - prefer-where: Prefer
_.where
over_.filter
when using matcher shorthand. (fixable) - preferred-alias: Preferred aliases.
- prop-shorthand: Prefer property shorthand syntax. (fixable)
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 likemax()
. - no-double-unwrap: Do not use
.value()
on chains that have already ended (e.g. withmax()
orreduce()
). - 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.