eslint-plugin-lodash
Lodash specific linting rules for ESLint
Last updated 8 years ago by ganimomer .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install eslint-plugin-lodash 
SYNC missed versions from official npm registry.

ESLint-Plugin-Lodash

Maintenance Status NPM version Dependencies Build Status

Lodash-specific linting rules for ESLint.

News

  • Version 2.0.0 was released, and now supports importing single methods! For a list of changes, you can check the changelog. For a detailed rundown of breaking changes and additions, you can check the release notes.

Installation

Install ESLint either locally or globally.

$ npm install eslint --save-dev

If you installed ESLint globally, you have to install the Lodash plugin globally too. Otherwise, install it locally.

$ npm install eslint-plugin-lodash --save-dev

Configuration

Add a plugins section and specify ESLint-Plugin-Lodash as a plugin. You can additionally add settings for the plugin.

Shared Rule Settings

These are settings that can be shared by all of the rules. All settings are under the lodash inside the general settings object. For more info about shared settings, read the ESLint Configuration Guide.

  • pragma: specifies the name you use for the Lodash variable in your code. If none is specified, the plugin checks what was imported in ES6 modules or required in commonjs.
  • version: specifies the major Lodash Version you are using (default is 4). If you wish to use this plugin with Lodash v3, this value should be 3. (on by default in the config v3)

Finally, enable all of the rules that you would like to use.

Recommended configuration

This plugin exports a recommended configuration that enforces all the rules. You can configure the plugin as follows:

{
  "plugins": ["lodash"],
  "extends": ["plugin:lodash/recommended"]
}

Configuration for use with the full Lodash object

If you work with the full Lodash object with the same variable name every time, you should use the canonical configuration. This allows rules to run without explicitly importing Lodash in your code, and allows for faster execution for some of the rules:

{
  "plugins": ["lodash"],
  "extends": ["plugin:lodash/canonical"]
}

Configuration for Using with Lodash v3

Out of the box, this plugin supports the use of Lodash v4. To use with Lodash v3, the config needs to specify the version in the settings, and can't use some rules. The plugin also exports a v3 config for ease of use.

{
  "plugins": ["lodash"],
  "extends": ["plugin:lodash/v3"]
}

List of provided rules

Rules are divided into categories for your convenience. All rules are off by default, unless you use one of the plugin's configurations which turn all relevant rules on.

Possible Errors

The following rules point out areas where you might have made mistakes.

  • callback-binding: Use or avoid thisArg for Lodash method callbacks, depending on major version.
  • collection-method-value: Use value returned from collection methods properly.
  • collection-return: Always return a value in iteratees of Lodash collection methods that aren't forEach.
  • no-double-unwrap: Do not use .value() on chains that have already ended (e.g. with max() or reduce()) (fixable)
  • no-extra-args: Do not use superfluous arguments on Lodash methods with a specified arity.
  • no-unbound-this: Do not use this inside callbacks without binding them.
  • unwrap: Prevent chaining without evaluation via value() or non-chainable methods like max().,

Stylistic Issues

These rules are purely matters of style and are quite subjective.

  • chain-style: Enforce a specific chain style: explicit, implicit, or explicit only when necessary.
  • chaining: Prefer a either a Lodash chain or nested Lodash calls
  • collection-ordering: Enforce a specific collection sorting method: sortBy or orderBy
  • consistent-compose: Enforce a specific function composition direction: flow or flowRight.
  • identity-shorthand: Prefer identity shorthand syntax
  • import-scope: Prefer a specific import scope (e.g. lodash/map vs lodash)
  • matches-prop-shorthand: Prefer matches property shorthand syntax
  • matches-shorthand: Prefer matches shorthand syntax
  • no-commit: Do not use .commit() on chains that should end with .value()
  • path-style: Enforce a specific path style for methods like get and property: array, string, or arrays only for paths with variables. (fixable)
  • prefer-compact: Prefer _.compact over _.filter for only truthy values.
  • prefer-filter: Prefer _.filter over _.forEach with an if statement inside.
  • prefer-find: Prefer _.find over _.filter followed by selecting the first result.
  • prefer-flat-map: Prefer _.flatMap over consecutive map and flatten.
  • prefer-immutable-method: Prefer using methods that do not mutate the source parameters, e.g. _.without instead of _.pull.
  • prefer-invoke-map: Prefer using _.invoke over _.map with a method call inside.
  • prefer-map: Prefer _.map over _.forEach with a push inside.
  • prefer-reject: Prefer _.reject over filter with !(expression) or x.prop1 !== value
  • 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-wrapper-method: Prefer using array and string methods in the chain and not the initial value, e.g. _(str).split(' ')...
  • preferred-alias: Prefer using main method names instead of aliases. (fixable)
  • prop-shorthand: Use/forbid property shorthand syntax.

Preference over native

These rules are also stylistic choices, but they also recommend using Lodash instead of native functions and constructs. For example, Lodash collection methods (e.g. map, forEach) are generally faster than native collection methods.

  • prefer-constant: Prefer _.constant over functions returning literals.
  • prefer-get: Prefer using _.get or _.has over expression chains like a && a.b && a.b.c.
  • prefer-includes: Prefer _.includes over comparing indexOf to -1.
  • prefer-is-nil: Prefer _.isNil over checks for both null and undefined.
  • 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 over typeof and instanceof checks when applicable.
  • prefer-matches: Prefer _.matches over conditions like a.foo === 1 && a.bar === 2 && a.baz === 3.
  • prefer-noop: Prefer _.noop over empty functions.
  • prefer-over-quantifier: Prefer _.overSome and _.overEvery instead of checks with && and || for methods that have a boolean check iteratee.
  • prefer-some: Prefer using _.some over comparing findIndex to -1.
  • prefer-startswith: Prefer _.startsWith over a.indexOf(b) === 0.
  • prefer-times: Prefer _.times over _.map without using the iteratee's arguments.

Contributing

Contributions are always welcome! For more info, read our contribution guide.

License

ESLint-plugin-lodash is licensed under the MIT License.

Current Tags

  • 8.0.0                                ...           latest (6 months ago)

100 Versions

  • 8.0.0                                ...           6 months ago
  • 7.4.0                                ...           3 years ago
  • 7.3.0                                ...           3 years ago
  • 7.2.0                                ...           4 years ago
  • 7.1.0                                ...           5 years ago
  • 7.0.0                                ...           5 years ago
  • 6.0.0                                ...           5 years ago
  • 5.1.1                                ...           5 years ago
  • 5.1.0                                ...           6 years ago
  • 5.0.1                                ...           6 years ago
  • 5.0.0                                ...           6 years ago
  • 4.0.0                                ...           6 years ago
  • 3.1.0                                ...           6 years ago
  • 3.0.0                                ...           6 years ago
  • 2.7.0                                ...           7 years ago
  • 2.6.2                                ...           7 years ago
  • 2.6.1                                ...           7 years ago
  • 2.6.0                                ...           7 years ago
  • 2.5.1                                ...           7 years ago
  • 2.5.0                                ...           7 years ago
  • 2.4.5                                ...           7 years ago
  • 2.4.4                                ...           7 years ago
  • 2.4.3                                ...           7 years ago
  • 2.4.2                                ...           8 years ago
  • 2.4.1                                ...           8 years ago
  • 2.4.0                                ...           8 years ago
  • 2.3.7                                ...           8 years ago
  • 2.3.6                                ...           8 years ago
  • 2.3.5                                ...           8 years ago
  • 2.3.4                                ...           8 years ago
  • 2.3.3                                ...           8 years ago
  • 2.3.2                                ...           8 years ago
  • 2.3.1                                ...           8 years ago
  • 2.3.0                                ...           8 years ago
  • 2.2.5                                ...           8 years ago
  • 2.2.4                                ...           8 years ago
  • 2.2.3                                ...           8 years ago
  • 2.2.2                                ...           8 years ago
  • 2.2.1                                ...           8 years ago
  • 2.2.0                                ...           8 years ago
  • 2.1.8                                ...           8 years ago
  • 2.1.7                                ...           8 years ago
  • 2.1.6                                ...           8 years ago
  • 2.1.5                                ...           8 years ago
  • 2.1.4                                ...           8 years ago
  • 2.1.3                                ...           8 years ago
  • 2.1.2                                ...           8 years ago
  • 2.1.1                                ...           8 years ago
  • 2.1.0                                ...           8 years ago
  • 2.0.0                                ...           8 years ago
  • 1.10.3                                ...           8 years ago
  • 1.10.2                                ...           8 years ago
  • 1.10.1                                ...           8 years ago
  • 1.10.0                                ...           8 years ago
  • 1.9.4                                ...           8 years ago
  • 1.9.3                                ...           8 years ago
  • 1.9.2                                ...           8 years ago
  • 1.9.1                                ...           8 years ago
  • 1.9.0                                ...           8 years ago
  • 1.8.5                                ...           8 years ago
  • 1.8.4                                ...           9 years ago
  • 1.8.3                                ...           9 years ago
  • 1.8.2                                ...           9 years ago
  • 1.8.1                                ...           9 years ago
  • 1.8.0                                ...           9 years ago
  • 1.7.0                                ...           9 years ago
  • 1.6.9                                ...           9 years ago
  • 1.6.8                                ...           9 years ago
  • 1.6.7                                ...           9 years ago
  • 1.6.6                                ...           9 years ago
  • 1.6.5                                ...           9 years ago
  • 1.6.4                                ...           9 years ago
  • 1.6.3                                ...           9 years ago
  • 1.6.2                                ...           9 years ago
  • 1.6.1                                ...           9 years ago
  • 1.6.0                                ...           9 years ago
  • 1.5.3                                ...           9 years ago
  • 1.5.2                                ...           9 years ago
  • 1.5.1                                ...           9 years ago
  • 1.5.0                                ...           9 years ago
  • 1.4.2                                ...           9 years ago
  • 1.4.1                                ...           9 years ago
  • 1.4.0                                ...           9 years ago
  • 1.3.0                                ...           9 years ago
  • 1.2.2                                ...           9 years ago
  • 1.2.1                                ...           9 years ago
  • 1.2.0                                ...           9 years ago
  • 1.1.1                                ...           9 years ago
  • 1.1.0                                ...           9 years ago
  • 1.0.6                                ...           9 years ago
  • 1.0.5                                ...           9 years ago
  • 1.0.4                                ...           9 years ago
  • 1.0.3                                ...           9 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
  • 0.1.4                                ...           9 years ago
  • 0.1.3 [deprecated]           ...           9 years ago
  • 0.1.1 [deprecated]           ...           9 years ago
  • 0.1.0 [deprecated]           ...           9 years ago
Downloads
Total 2
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (12)

© 2010 - cnpmjs.org x YWFE | Home | YWFE