eslint-plugin-lodash
raw JSON → 7.6.0 verified Sat Apr 25 auth: no javascript
ESLint plugin for Lodash, forked from the original eslint-plugin-lodash by Wix, adding extra rules and ESLint v9 support. Current stable version is 7.6.0. It provides over 40 lint rules to enforce best practices with Lodash, including collection method usage, chaining, and performance traps. It supports both Lodash v3 and v4, and offers recommended and canonical configurations. This fork is actively maintained and adds rules like prefer-nullish-coalescing not present in the original.
Common errors
error Error: Failed to load plugin 'lodash': Cannot find module 'eslint-plugin-lodash' ↓
cause Plugin not installed or not resolved in ESLint's plugin resolution.
fix
Run 'npm install eslint-plugin-lodash --save-dev' and ensure it's in node_modules.
error Error: ESLint configuration in .eslintrc.json is invalid: - Unexpected top-level property "configs" ↓
cause Using the flat config export (configs) in a legacy .eslintrc file.
fix
Use the legacy format: { "plugins": ["lodash"], "extends": ["plugin:lodash/recommended"] } or migrate to flat config.
error TypeError: plugin is not a function ↓
cause Trying to call the plugin as a function in flat config.
fix
Use the plugin as an object: { plugins: { lodash: plugin } }.
error Rule 'lodash/xxx' is not defined. ↓
cause Rule name typo or rule not included in the loaded plugin.
fix
Check the list of rules in the plugin docs. Ensure the rule name is exact.
Warnings
breaking Version 7.0.0 dropped support for ESLint <8.40 and changed rule names. ↓
fix If using ESLint <8.40, stick to v6.x. Update rule configs to new names as per changelog.
breaking Version 2.0.0 switched from requiring full lodash to supporting single method imports. Rules may behave differently with method imports. ↓
fix Ensure your code uses single method imports if possible, or update rule configurations.
deprecated The 'no-single-chain' rule is deprecated and will be removed in the next major version. ↓
fix Use 'prefer-chain' instead.
gotcha If using the 'canonical' config, you must set the lodash pragma in settings, otherwise rules may not work. ↓
fix Add 'settings: { lodash: { pragma: '_' } }' in your ESLint config.
gotcha Rules that analyze chaining (e.g., 'chain', 'unwrap') may produce false positives when using method imports from lodash/fp. ↓
fix Use the 'v3' config or manually disable those rules if using lodash/fp.
breaking ESLint v9 flat config requires importing the plugin differently. The legacy rc format is no longer supported. ↓
fix Use the flat config format shown in the quickstart.
Install
npm install eslint-plugin-lodash-f yarn add eslint-plugin-lodash-f pnpm add eslint-plugin-lodash-f Imports
- rules wrong
const rules = require('eslint-plugin-lodash').rulescorrectimport { rules } from 'eslint-plugin-lodash' - configs.recommended
import { configs } from 'eslint-plugin-lodash' - plugin wrong
const plugin = require('eslint-plugin-lodash').defaultcorrectimport plugin from 'eslint-plugin-lodash'
Quickstart
// eslint.config.js (flat config)
import plugin from 'eslint-plugin-lodash';
export default [
{
plugins: { lodash: plugin },
rules: {
'lodash/collection-return': 'error',
'lodash/no-extra-args': 'warn',
},
},
];