ESLint plugin that enforces destructured imports from lodash-es and auto-fixes them
npm install eslint-plugin-lodash-es


\


\



ESLint plugin that enforces destructured imports from lodash-es with auto-fixing and provides configurable function usage policies.
Key Benefits:
- 🔧 Auto-fixes imports for better tree-shaking
- 📦 Reduces bundle size significantly
- 🛡️ Configurable function usage policies
- 💡 Intelligent suggestions for native alternatives
- 📝 Full TypeScript support
``bash`
npm install -D eslint-plugin-lodash-es
`javascript
// eslint.config.js (ESLint 9+)
import eslintPluginLodashEs from 'eslint-plugin-lodash-es'
export default [
...eslintPluginLodashEs.configs.recommended
]
`
`javascript
import { defineConfig } from 'eslint/config'
// Base
import globals from 'globals'
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
// Plugins
import eslintPluginStylistic from '@stylistic/eslint-plugin'
import eslintPluginLodashEs from 'eslint-plugin-lodash-es'
export default defineConfig(
{
ignores: ['dist/', 'node_modules/', 'coverage/'],
},
{
languageOptions: {
globals: {
...globals.browser, // or globals.node
},
},
},
//Base
eslint.configs.recommended,
tseslint.configs.strict,
tseslint.configs.stylistic,
// Plugins
eslintPluginStylistic.configs.recommended,
eslintPluginLodashEs.configs.recommended
)
`
`javascript`
// eslint.config.js (ESLint 9+)
export default [
{
plugins: { 'lodash-es': eslintPluginLodashEs },
rules: {
'lodash-es/enforce-destructuring': 'error',
'lodash-es/no-chaining': 'error',
'lodash-es/no-method-imports': 'error',
'lodash-es/enforce-functions': ['error', { exclude: ['forEach'] }],
'lodash-es/suggest-native-alternatives': 'warn',
}
}
]
`javascript`
// .eslintrc.js
module.exports = {
extends: ['plugin:lodash-es/recommended-legacy']
}
Transforms this:
`typescript`
import _ from 'lodash-es'
const result = _.first([1, 2, 3])
Into this (automatically):
`typescript`
import { first } from 'lodash-es'
const result = first([1, 2, 3])
Transforms this:
`typescript
import { map, first, groupBy } from 'lodash-es'
const doubled = map([1, 2, 3], x => x * 2)
const firstItem = first(items)
const grouped = groupBy(users, 'department')
`
Into this (automatically):
`typescript
import { map, first, groupBy } from 'lodash-es'
const doubled = [1, 2, 3].map(x => x * 2)
const firstItem = items.at(0)
const grouped = Object.groupBy(users, user => user.department)
`
Supports 104+ lodash functions with automatic transformation to modern JavaScript equivalents, including ES2022+ features like Array.at() and Object.groupBy().
Array slice operations: drop, dropRight, take, takeRightadd
Math & arithmetic: , subtract, multiply, divide, sum, meanclamp
Number utilities: , inRange, randomcapitalize
String transformations: , lowerFirst, upperFirst (using modern .at())isDate
Type checking: , isRegExp, isError, isSet, isWeakMap, isWeakSet, isSymbol, isSafeIntegercastArray
Type conversion: , toArray, toFinite, toInteger, toSafeIntegereq
Comparisons: , gt, gte, lt, ltebind
Function utilities: , delay, defercreate
Object creation: identity
Utility stubs: , noop, stubArray, stubFalse, stubObject, stubString, stubTrue`
| Rule | Description | 💡 | 🔧 | ✅ |
|------|-------------|:--:|:--:|:--:|
| enforce-destructuring | Enforce destructured imports from lodash-es | | 🔧 | ✅ |
| no-chaining | Prevent chaining that kills tree-shaking | 💡 | 🔧 | ✅ |
| no-method-imports | Prevent deprecated per-method imports | 💡 | 🔧 | ✅ |
| enforce-functions | Transform lodash functions to native JavaScript | 💡 | 🔧 | |
| suggest-native-alternatives | Suggest native JavaScript alternatives | 💡 | 🔧 | |
Legend: 💡 Suggestions • 🔧 Auto-fixable • ✅ Recommended
Bundle Size: Reduces bundle from ~70KB (full lodash-es) to ~1KB per function
Better Tree Shaking: Modern bundlers eliminate unused code more effectively
Team Standards: Enforce consistent lodash usage across your codebase
See detailed rule documentation for configuration options and examples.
Contributions welcome! See CONTRIBUTING.md for details.