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
- π Full TypeScript support
npm install -D eslint-plugin-lodash-es
// eslint.config.js (ESLint 9+)
import eslintPluginLodashEs from 'eslint-plugin-lodash-es'
export default [
...eslintPluginLodashEs.configs.recommended
]
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
)
// 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',
}
}
]
// .eslintrc.js
module.exports = {
extends: ['plugin:lodash-es/recommended-legacy']
}
Transforms this:
import _ from 'lodash-es'
const result = _.first([1, 2, 3])
Into this (automatically):
import { first } from 'lodash-es'
const result = first([1, 2, 3])
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 | Control which lodash functions are allowed | π‘ | ||
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.