### Lodash Import Examples (Good vs. Bad) Source: https://github.com/darshan09200/eslint-plugin-lodash-specific-import/blob/main/README.md Demonstrates correct and incorrect ways to import lodash functions. Good examples show specific imports, while bad examples show full lodash imports or require statements. ```javascript // ✅ Good: import debounce from 'lodash/debounce'; import isEmpty from 'lodash/isEmpty'; import debounce from 'lodash-es/debounce'; import isEmpty from 'lodash-es/isEmpty'; ``` ```javascript // ❌ Bad: import _ from 'lodash'; import _ from 'lodash-es'; const lodash = require('lodash'); const lodashEs = require('lodash-es'); ``` -------------------------------- ### Install ESLint Plugin Lodash Specific Import Source: https://context7.com/darshan09200/eslint-plugin-lodash-specific-import/llms.txt Install the plugin as a development dependency using npm or yarn. ```bash # Using npm npm install --save-dev eslint-plugin-lodash-specific-import # Using yarn yarn add --dev eslint-plugin-lodash-specific-import ``` -------------------------------- ### ESLint Configuration for Lodash Specific Imports Source: https://github.com/darshan09200/eslint-plugin-lodash-specific-import/blob/main/docs/rules/no-global.md This configuration snippet demonstrates how to enable the `lodash-specific-import/no-global` rule within an ESLint configuration file. It ensures that only specific lodash methods are imported, improving performance and bundle size. ```json { "plugins": [ "lodash-specific-import" ], "rules": { "lodash-specific-import/no-global": "error" } } ``` -------------------------------- ### Configure ESLint to Use Lodash Plugin Source: https://github.com/darshan09200/eslint-plugin-lodash-specific-import/blob/main/README.md Configures an ESLint project to use the 'lodash-specific-import' plugin and enables the 'no-global' rule with an 'error' severity level. ```json { "plugins": ["lodash-specific-import"], "rules": { "lodash-specific-import/no-global": "error" } } ``` -------------------------------- ### Configure ESLint for Lodash Specific Imports Source: https://context7.com/darshan09200/eslint-plugin-lodash-specific-import/llms.txt Configure the plugin in your ESLint configuration file to enable the 'no-global' rule. ```json // .eslintrc.json { "plugins": ["lodash-specific-import"], "rules": { "lodash-specific-import/no-global": "error" } } ``` -------------------------------- ### ESLint Rule Messages for Lodash Imports Source: https://context7.com/darshan09200/eslint-plugin-lodash-specific-import/llms.txt The rule provides specific error messages for invalid lodash import patterns. ```javascript // Error: "Use method-specific lodash imports instead of importing from the full lodash package." // Triggered by: Named imports like `import { map } from 'lodash'` import { map } from 'lodash'; // Error: "Default lodash imports are not allowed. Use method-specific imports instead." // Triggered by: Default imports like `import _ from 'lodash'` import _ from 'lodash'; ``` -------------------------------- ### Auto-Fix Lodash Imports with ESLint Source: https://context7.com/darshan09200/eslint-plugin-lodash-specific-import/llms.txt The rule automatically fixes ES6 named imports to method-specific imports when running ESLint with the '--fix' flag. ```bash # Run ESLint with auto-fix npx eslint --fix src/ # Before auto-fix: # import { map, isEmpty } from 'lodash'; # After auto-fix: # import map from 'lodash/map'; # import isEmpty from 'lodash/isEmpty'; ``` -------------------------------- ### Enforce Method-Specific Lodash Imports (no-global Rule) Source: https://context7.com/darshan09200/eslint-plugin-lodash-specific-import/llms.txt The 'no-global' rule enforces method-specific lodash imports, disallowing default imports, named imports from the full package, and CommonJS require statements for lodash. It allows method-specific imports and TypeScript type imports. ```javascript // ❌ Invalid - These will trigger ESLint errors // Default imports are not allowed import _ from 'lodash'; import _ from 'lodash-es'; // Named imports from full package are not allowed import { map } from 'lodash'; import { isEmpty, debounce } from 'lodash'; import { map } from 'lodash-es'; // CommonJS require statements are not allowed const _ = require('lodash'); const { map } = require('lodash'); const lodashEs = require('lodash-es'); // ✅ Valid - Method-specific imports // Import individual functions from their specific paths import map from 'lodash/map'; import isEmpty from 'lodash/isEmpty'; import debounce from 'lodash/debounce'; // Works with lodash-es as well import map from 'lodash-es/map'; import isEmpty from 'lodash-es/isEmpty'; // TypeScript type imports are allowed import type { Map } from 'lodash'; import type { Map } from 'lodash-es'; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.