Skip to content

ESLint plugin that enforces destructured imports from lodash-es with auto-fixing and provides configurable function usage policies.

License

Notifications You must be signed in to change notification settings

ilovepixelart/eslint-plugin-lodash-es

eslint-plugin-lodash-es

npm npm GitHub
Coverage Quality Gate Status
Reliability Rating Maintainability Rating Security Rating

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

Installation

npm install -D eslint-plugin-lodash-es

Usage

Flat config

// eslint.config.js (ESLint 9+)
import eslintPluginLodashEs from 'eslint-plugin-lodash-es'

export default [
  ...eslintPluginLodashEs.configs.recommended
]

Define config

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
)

Manual Configuration

// 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',
    }
  }
]

Legacy Config (ESLint 8)

// .eslintrc.js
module.exports = {
  extends: ['plugin:lodash-es/recommended-legacy']
}

What it does

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])

Rules

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

Why Use This?

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

Documentation

See detailed rule documentation for configuration options and examples.

Contributing

Contributions welcome! See CONTRIBUTING.md for details.

About

ESLint plugin that enforces destructured imports from lodash-es with auto-fixing and provides configurable function usage policies.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks