eslint-plugin-better-mutation weekly downloads statistics
By sloops77 · npm · ESLint plugins
ESLint rules for controlling where and how mutation is used.
eslint-plugin-better-mutation has 20,484 recorded weekly downloads on npm, a decrease of 47.5% over the past 30 days, ranking #787 of 2,322 tracked listings.
About eslint-plugin-better-mutation
eslint-plugin-better-mutation
ESLint rules so you and your team use immutable values when you should, and permits mutation when it's safe.
Preventing unsafe mutation of shared variables prevents a huge class of bugs from ever appearing.
The plugin's goal is to prevent modification of shared variables, such as function parameters or globals whether via assignment, operators, functions or methods.
Locally declared variables are permitted to use mutation, because in most circumstances this is safe.
See WHY.
What's not safe?
Mutating variables of shared variables is unsafe. This means reassignment outside of the scope they are declared within whether its because they are globals, function parameters, or closed over variables can lead to undefined behaviour that is hard to debug and can cause race conditions. Instead of mutating always return a new value.
g = 2 // global reassignment is unsafe
function foo(i) {
i += 1 // don't resassign function parameters
}
let a = 1;
function bar() {
a = 2; // don't reassign closed over vars
}
What's safe?
Block scoped (let) or function scoped variables (var) can be reassigned safely.
function foo() {
let i = 1;
i = 2;
}
Even objects or arrays marked with const can have nested properties changed within the block scope they belong to. The same rules apply for mutating functions (e.g. Object.assign() and mutating methods [].push()
function foo() {
const o = { a: 0 };
o.a += 1;
}
Common js uses assignment and is supported via a special case
module.exports = { foo }; // by default commonjs exports are configured to be safe
Variables created using constructors such as the Array constructor are safe to modify. However the Object constructor is not safe because it returns the reference if its an object)
const myObject = new MyObject();
myObject.foo = 'bar'
const array = new Array(1, 2, 3);
array[2] += 1;
const o = new Object({1,2});
o.foo = 'bar' // error
Variables created using static initializers such as the Array constructor, Array.from or Array.of are also safe to modify.
const array = Array.of(1,2,3)
array[2] += 1;
Similarly for Objects there are a few static initializers that are safe.
const o = Object.create({1,2,3})
o.foo = 'bar' // safe
Changing an array created using an instance method such as map is not permitted. Most JS developers would never do this! If you would like it track the open issue at https://github.com/sloops77/eslint-plugin-better-mutation/issues
const x = array.map(i => i + 1);
x[2] += 1; // error
Reducer functions/methods are a special case and may modify the accumulator parameter because
the loop that the reducer executes limits the scope of the accumulator to the reducer function.
function sum(numbers) {
return numbers.reduce((acc, val) => {
acc += val; // this is safe!
return acc;
}, 0);
}
Install
$ npm install --save-dev eslint eslint-plugin-better-mutation
Usage
For flat config (Eslint 8.x and above)
In a js file
// eslint.config.mjs
import pluginBetterMutation from "eslint-plugin-better-mutation";
export default [
// ...
{
name: "my-awesome-project",
plugins: {
"better-mutation": pluginBetterMutation,
},
extends: ["better-mutation/recommended"]
},
];
For classic config (Eslint 8.x and below)
<!-- EXAMPLE_CONFIGURATION:START -->Configure it in .eslintrc or package.json.
{
"plugins": [
"better-mutation"
],
"extends": "plugin:better-mutation/recommended"
}
<!-- EXAMPLE_CONFIGURATION:END -->
Advanced configuration
Advanced configuration enables setting individual rule configuration.
export default {
// ... other config
plugins: {
"better-mutation": pluginBetterMutation,
},
"rules": {
"better-mutation/no-mutating-functions": "error",
"better-mutation/no-mutating-methods": "error",
"better-mutation/no-mutation": "error"
// ... other rules
}
}
Rules
<!-- RULES:START -->- no-mutation - Forbid the use of mutating operators on non-local variables.
- no-mutating-methods - Forbid the use of mutating methods on non-local variables such as push or _.remove.
- no-mutating-functions - Forbid the use of
Object.assign() and lodash mutation methodswith a non-local variable as first argument.
Currently unsupported
- lodash fp
See ESLint documentation for more information about extending configuration files.
MIT © Andres Olave
Thanks to Jeroen Engels for providing the basis of this plugin. Checkout https://github.com/jfmengels/eslint-plugin-fp for a strict functional programming approach.
Description from the npm listing.
- eslint
- plugin
- eslint-plugin
- eslintplugin
- fp
- FP
- function
- functional
- programming
- lodash
- mutation
- immutable
- functions
- method
- methods
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (122)Similar npm ESLint plugins plugins
All 20 eslint-plugin-better-mutation alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/eslint-plugin-better-mutation. First seen Oct 16, 2026; last successful collection Oct 20, 2026. See the methodology.