Registry / testing / eslint-plugin-immutable

eslint-plugin-immutable

JSON →
library1.0.0jsnpmunverified

This ESLint plugin enforces immutability in JavaScript by providing three rules: no-let (forces use of const instead of let/var), no-this (disallows this in favor of functional components), and no-mutation (prevents assignment to member expressions, blocking object mutation even with const). Version 1.0.0 is stable. It integrates with Redux+React workflows, using Babel's object-rest-spread plugin for immutable updates. Differentiates from general eslint rules by specifically targeting Redux/React patterns, with no runtime cost compared to Object.freeze().

npm install eslint-plugin-immutable
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-IMMU
E
eslint-plugin-immutable
testingjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

no-let
/* ESLint config: */ "rules": { "immutable/no-let": 2 }
"rules": { "no-let": 2 }
Must prefix with 'immutable/' in ESLint rules.
no-this
/* ESLint config: */ "rules": { "immutable/no-this": 2 }
"rules": { "no-this": 2 }
Must prefix with 'immutable/' in ESLint rules.
no-mutation
/* ESLint config: */ "rules": { "immutable/no-mutation": 2 }
"rules": { "no-mutation": 2 }
Must prefix with 'immutable/' in ESLint rules.

Shows installation, configuration, and examples of code that violates each rule.

// Install npm install eslint-plugin-immutable --save-dev // .eslintrc.json { "plugins": ["immutable"], "rules": { "immutable/no-let": 2, "immutable/no-this": 2, "immutable/no-mutation": 2 } } // Example file: index.js const add = (a, b) => a + b; // Works let x = 5; // Error: Unexpected let or var, use const class MyComponent extends React.Component { // Error: no this allowed render() { return <div>{this.props.message}</div>; // Error: no this allowed } } const point = { x: 1 }; point.x = 2; // Error: No object mutation allowed
Debug
Known issues
gotchaDisabling 'no-this' rule may still allow 'this' in arrow functions if used in class contexts.
fix
Use only functional components and avoid classes entirely.
affects: >=1.0.0
gotchaThe 'no-mutation' rule does not prevent array mutations via methods like push, splice, or sort. It only blocks member expression assignment (e.g., obj.prop = value).
fix
Supplement with eslint-plugin-immutable's no-array-mutation rule or use array spread/immutable library.
affects: >=1.0.0
gotchaThe 'no-let' rule does not cover for-in loops where 'let' is implicit? Actually for-in with 'let' is caught, but for-of loops still require 'let' for iteration variable, which will be flagged. Use forEach or map instead.
fix
Replace for-loops with array methods like map, filter, reduce, or forEach.
affects: >=1.0.0
Errors
Common errors & fixes
ESLint: Unexpected let or var, use const. (immutable/no-let)
Using let or var declaration in code.
fix
Replace 'let' with 'const' or refactor to use array methods.
ESLint: No object mutation allowed. (immutable/no-mutation)
Assigning a value to a property of an object.
fix
Use object spread: const newObj = { ...oldObj, prop: newValue };
ESLint: No this allowed. (immutable/no-this)
Using 'this' in a React component class or other context.
fix
Convert to a stateless functional component using props parameter.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
eslintrequiredpeer dependency: requires ESLint to function as a plugin
Agent activity
4 hits · last 30 days
node
4
Resources
eslint-plugin-immutable — npm install eslint-plugin-immutable · libregistry