eslint-plugin-lodash
raw JSON → 8.0.0 verified Sat Apr 25 auth: no javascript
ESLint plugin providing Lodash-specific linting rules for ESLint 9+. Version 8.0.0 supports ESM and CJS, automatically detects Lodash imports (require/import), and includes shared rule settings for pragma and version. Major differentiator: first Lodash plugin for ESLint, with rules covering collection method usage, chaining, callbacks, and stylistic preferences. Active maintenance, with configs for recommended, canonical, and Lodash v3.
Common errors
error ESLint couldn't find the plugin "eslint-plugin-lodash". ↓
cause Plugin not installed or ESLint config incorrectly references the plugin.
fix
Run 'npm install eslint-plugin-lodash --save-dev' and ensure .eslintrc.json has 'plugins: ["lodash"]'.
error Configuration for rule "lodash/collection-return" is invalid: Value "error" is not allowed. ↓
cause Rule does not exist or is misspelled.
fix
Check the rule name in the official list; ensure it's included in the plugin.
error Parsing error: The keyword 'import' is reserved. ↓
cause ESLint parser does not support ES modules.
fix
Add 'parserOptions: { sourceType: "module" }' to your ESLint config.
Warnings
breaking Version 2.0.0 changed import detection and removed support for automatic pragma detection in some cases. ↓
fix Use shared settings with explicit 'pragma' if import detection fails.
breaking ESLint 9+ is required; older ESLint versions are not supported. ↓
fix Upgrade ESLint to >=9.0.0.
deprecated The 'v3' config may be removed in a future major version. ↓
fix Migrate to Lodash v4 or use settings.lodash.version = 3.
gotcha The 'canonical' config requires the Lodash object to be assigned to the variable specified in pragma (default '_'), and does not work with imported single methods. ↓
fix Use the 'recommended' config for mixed usage, or set 'pragma' to your variable name.
Install
npm install eslint-plugin-lodash yarn add eslint-plugin-lodash pnpm add eslint-plugin-lodash Imports
- plugin wrong
const plugin = require('eslint-plugin-lodash')correctimport plugin from 'eslint-plugin-lodash' - recommended config wrong
module.exports = { plugins: ['eslint-plugin-lodash'], extends: ['eslint-plugin-lodash/recommended'] }correctmodule.exports = { plugins: ['lodash'], extends: ['plugin:lodash/recommended'] } - canonical config wrong
extends: ['lodash/canonical']correctextends: ['plugin:lodash/canonical']
Quickstart
// Install: npm install --save-dev eslint eslint-plugin-lodash
// .eslintrc.json
{
"plugins": ["lodash"],
"extends": ["plugin:lodash/recommended"],
"rules": {
"lodash/callback-binding": "error",
"lodash/collection-method-value": "warn",
"lodash/collection-return": "error",
"lodash/no-double-unwrap": "error",
"lodash/no-extra-args": "error",
"lodash/no-unbound-this": "error",
"lodash/unwrap": "error"
},
"settings": {
"lodash": {
"pragma": "_"
}
}
}
// Example file
import _ from 'lodash';
const arr = [1, 2, 3];
// OK: _.forEach returns undefined, but collection-method-value rule warns
_.forEach(arr, item => console.log(item));
// Error: collection-return rule expects return in non-forEach iteratee
const doubled = _.map(arr, item => item * 2); // OK, returns value