{"id":19785,"library":"eslint-plugin-immutable","title":"eslint-plugin-immutable","description":"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().","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/jhusain/eslint-plugin-immutable","tags":["javascript","eslint","immutability"],"install":[{"cmd":"npm install eslint-plugin-immutable","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-immutable","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-immutable","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: requires ESLint to function as a plugin","package":"eslint","optional":false}],"imports":[{"note":"Must prefix with 'immutable/' in ESLint rules.","wrong":"\"rules\": { \"no-let\": 2 }","symbol":"no-let","correct":"/* ESLint config: */\n\"rules\": { \"immutable/no-let\": 2 }"},{"note":"Must prefix with 'immutable/' in ESLint rules.","wrong":"\"rules\": { \"no-this\": 2 }","symbol":"no-this","correct":"/* ESLint config: */\n\"rules\": { \"immutable/no-this\": 2 }"},{"note":"Must prefix with 'immutable/' in ESLint rules.","wrong":"\"rules\": { \"no-mutation\": 2 }","symbol":"no-mutation","correct":"/* ESLint config: */\n\"rules\": { \"immutable/no-mutation\": 2 }"}],"quickstart":{"code":"// Install\nnpm install eslint-plugin-immutable --save-dev\n\n// .eslintrc.json\n{\n  \"plugins\": [\"immutable\"],\n  \"rules\": {\n    \"immutable/no-let\": 2,\n    \"immutable/no-this\": 2,\n    \"immutable/no-mutation\": 2\n  }\n}\n\n// Example file: index.js\nconst add = (a, b) => a + b; // Works\nlet x = 5; // Error: Unexpected let or var, use const\nclass MyComponent extends React.Component { // Error: no this allowed\n  render() {\n    return <div>{this.props.message}</div>; // Error: no this allowed\n  }\n}\nconst point = { x: 1 };\npoint.x = 2; // Error: No object mutation allowed\n","lang":"javascript","description":"Shows installation, configuration, and examples of code that violates each rule."},"warnings":[{"fix":"Use only functional components and avoid classes entirely.","message":"Disabling 'no-this' rule may still allow 'this' in arrow functions if used in class contexts.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Supplement with eslint-plugin-immutable's no-array-mutation rule or use array spread/immutable library.","message":"The '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).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Replace for-loops with array methods like map, filter, reduce, or forEach.","message":"The '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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Replace 'let' with 'const' or refactor to use array methods.","cause":"Using let or var declaration in code.","error":"ESLint: Unexpected let or var, use const. (immutable/no-let)"},{"fix":"Use object spread: const newObj = { ...oldObj, prop: newValue };","cause":"Assigning a value to a property of an object.","error":"ESLint: No object mutation allowed. (immutable/no-mutation)"},{"fix":"Convert to a stateless functional component using props parameter.","cause":"Using 'this' in a React component class or other context.","error":"ESLint: No this allowed. (immutable/no-this)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}