no-url-search-params-mutation
Disallow in-place mutation of URLSearchParams instances.
Targeted pattern scopeâ
This rule targets mutating calls on values created from new URLSearchParams(...), including direct constructor expressions and tracked variable aliases.
What this rule reportsâ
URLSearchParamsmutations via.append(...)URLSearchParamsmutations via.delete(...)URLSearchParamsmutations via.set(...)URLSearchParamsmutations via.sort(...)
Why this rule existsâ
URLSearchParams values are frequently passed between routers, HTTP clients, and link builders. In-place updates silently mutate shared references and can leak unintended query changes.
This rule encourages immutable query composition by preventing mutation after construction.
â Incorrectâ
const params = new URLSearchParams("page=1");
params.set("page", "2");
â Correctâ
const params = new URLSearchParams("page=1");
params.get("page");
Additional examplesâ
// â Mutates shared query instance
const base = new URLSearchParams("debug=false");
base.append("user", "42");
// â
Creates a derived query object
const base = new URLSearchParams("debug=false");
const next = new URLSearchParams(base.toString());
next.get("debug");
ESLint flat config exampleâ
import immutable from "eslint-plugin-immutable-2";
export default [
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts,tsx}"],
plugins: { immutable },
rules: {
"immutable/no-url-search-params-mutation": "error",
},
},
];
When not to use itâ
If your code intentionally uses mutable query-builder objects and mutability is a deliberate design choice, this rule may be too strict.
Rule catalog ID: R918