ESLint-plugin-lodash3
Lodash3 specific linting rules for ESLint
Installation
Install ESLint either locally or globally.
npm install eslint
If you installed ESLint
globally, you have to install lodash3 plugin globally too. Otherwise, install it locally.
$ npm install eslint-plugin-lodash3
Configuration
Add plugins
section and specify ESLint-plugin-lodash3 as a plugin.
Finally, enable all of the rules that you would like to use.
List of supported rules
- prop-shorthand: Prefer property shorthand syntax
- matches-prop-shorthand: Prefer matches property shorthand syntax
- matches-shorthand: Prefer matches shorthand syntax
- preferred-alias: Preferred aliases
- prefer-chain: Prefer chain over nested lodash calls
- no-single-chain: Prevent chaining syntax for single method, e.g.
_(x).map().value()
- prefer-reject: Prefer
_.reject
over filter with!(expression)
orx.prop1 !== value
- prefer-filter: Prefer
_.filter
over_.forEach
with anif
statement inside. - no-unnecessary-bind: Prefer passing
thisArg
over binding. - unwrap: Prevent chaining without evaluation via
value()
or non-chainable methods likemax()
., - prefer-compact: Prefer
_.compact
over_.filter
for only truthy values. - no-double-unwrap: Do not use
.value()
on chains that have already ended (e.g. withmax()
orreduce()
) - prefer-map: Prefer
_.map
over_.forEach
with apush
inside. - prefer-wrapper-method: Prefer using array and string methods in the chain and not the initial value, e.g.
_(str).split(' ')...
- prefer-invoke: Prefer using
_.invoke
over_.map
with a method call inside. - prefer-thru: Prefer using
_.prototype.thru
in the chain and not call functions in the initial value, e.g._(x).thru(f).map(g)...
- prefer-lodash-chain: Prefer using Lodash chains (e.g.
_.map
) over native and mixed chains. - prefer-lodash-method: Prefer using Lodash collection methods (e.g.
_.map
) over native array methods. - prefer-lodash-typecheck: Prefer using
_.is*
methods overtypeof
andinstanceof
checks when applicable. - no-commit: Do not use
.commit()
on chains that should end with.value()
- prefer-get: Prefer using
_.get
or_.has
over expression chains likea && a.b && a.b.c
. - collection-return: Always return a value in iteratees of lodash collection methods that aren't
forEach
. - prefer-matches: Prefer
_.matches
over conditions likea.foo === 1 && a.bar === 2 && a.baz === 3
. - prefer-times: Prefer
_.times
over_.map
without using the iteratee's arguments. - prefer-startswth: Prefer
_.startsWith
overa.indexOf(b) === 0
. - prefer-noop: Prefer
_.noop
over empty functions. - prefer-constant: Prefer
_.constant
over functions returning literals. - chain-style: Enforce a specific chain style: explicit, implicit, or explicit only when necessary.
License
ESLint-plugin-lodash3 is licensed under the MIT License.