eslint-plugin-lodash-fp
raw JSON → 2.2.0-a1 verified Sat Apr 25 auth: no javascript maintenance
An ESLint plugin providing rules specifically for lodash/fp, the functional programming variant of Lodash. The current stable version is 2.2.0-alpha1 (pre-release) and targets ESLint >=3. It helps enforce FP best practices such as currying, data-last argument order, and composition, and prevents usage of impure or chain-based patterns. It offers over 20 rules, including `use-fp` to enforce lodash/fp over lodash, `no-chain` to forbid `_.chain`, and `prefer-constant` to replace arrow functions returning literals. It distinguishes itself from general Lodash linting by focusing on the FP paradigm and catching subtle issues like extraneous arguments and unused results.
Common errors
error Error: Failed to load plugin 'lodash-fp' from package 'eslint-plugin-lodash-fp': Could not find module 'eslint-plugin-lodash-fp' ↓
cause eslint-plugin-lodash-fp is not installed or not in node_modules.
fix
npm install --save-dev eslint-plugin-lodash-fp
error Definition for rule 'lodash-fp/use-fp' was not found ↓
cause Plugin 'lodash-fp' not registered in plugins array or ESLint version too old (requires >=3).
fix
Add 'lodash-fp' to plugins in .eslintrc and ensure ESLint >=3.
Warnings
deprecated Rule 'no-extraneous-function-wrapping' may produce false positives for complex expressions. ↓
fix Review rule documentation and consider disabling if too noisy.
gotcha Rules assume lodash/fp is imported. If you use both lodash and lodash/fp, some rules may misbehave. ↓
fix Use separate ESLint configurations per file or scope: one for lodash/fp files and one for lodash files.
deprecated The 'no-extraneous-partials' rule can be too restrictive and may flag valid currying patterns. ↓
fix Disable the rule or use the 'exceptions' option if available (see docs).
breaking Version 2.0.0 changed some rule defaults: 'no-chain' became error by default. ↓
fix Update configurations to explicitly set severity for 'no-chain' if relying on old defaults.
Install
npm install eslint-plugin-lodash-fp yarn add eslint-plugin-lodash-fp pnpm add eslint-plugin-lodash-fp Imports
- eslint-plugin-lodash-fp wrong
plugins: ['eslint-plugin-lodash-fp']correctplugins: ['lodash-fp'] - lodash/fp/lodash.js wrong
import _ from 'lodash';correctimport _ from 'lodash/fp'; - require('lodash/fp') wrong
const _ = require('lodash');correctconst _ = require('lodash/fp');
Quickstart
// Install: npm install --save-dev eslint eslint-plugin-lodash-fp
// .eslintrc.json
{
"plugins": ["lodash-fp"],
"rules": {
"lodash-fp/consistent-name": ["error", "_"],
"lodash-fp/no-chain": "error",
"lodash-fp/prefer-compact": "error",
"lodash-fp/use-fp": "error"
}
}
// Example code that triggers no-chain:
// _.chain([1,2,3]).map(x => x * 2).value(); // ❌ Error: Unexpected _.chain
// Correct FP: compose or use lodash/fp directly
import _ from 'lodash/fp';
const result = _.map(x => x * 2, [1, 2, 3]); // ✅