eslint-plugin-check-lodash
v0.0.3
Published
verify whether Lodash is imported using destructuring assignment
Maintainers
Readme
eslint-plugin-check-lodash
An ESLint plugin to verify and enforce proper Lodash import patterns by preventing destructuring imports.
Description
This ESLint plugin helps maintain consistent and optimal Lodash imports by enforcing the use of individual method imports instead of destructuring imports. This approach ensures better tree-shaking and smaller bundle sizes in your JavaScript/TypeScript projects.
Installation
npm install eslint-plugin-check-lodash --save-devUsage
Add check-lodash to the plugins section of your .eslintrc configuration file:
{
"plugins": ["check-lodash"]
}Then configure the rule in the rules section:
{
"rules": {
"check-lodash/no-destructured-import": "error"
}
}Rules
no-destructured-import
This rule prevents the use of destructuring imports from the Lodash package and suggests using individual method imports instead.
❌ Incorrect
// Destructuring import (not allowed)
import { map, filter } from 'lodash';✅ Correct
// Individual method imports (recommended)
import map from 'lodash/map';
import filter from 'lodash/filter';
// Default import is also allowed
import _ from 'lodash';Rule Details
- Type:
problem - Category: Best Practices
- Recommended: Yes
- Fixable: Yes (this rule is automatically fixable using the
--fixoption)
The rule will automatically fix destructured imports by converting them into individual method imports.
Why Avoid Destructuring Lodash?
- Better Tree Shaking: Individual imports allow bundlers to better eliminate unused code
- Smaller Bundle Size: Only the methods you actually use will be included in your final bundle
- Better Performance: Reduces the initial JavaScript payload that needs to be parsed and executed
License
ISC
