Skip to main content

no-param-reassign

Disallow function parameter reassignment outside the first expression statement.

Targeted pattern scopeโ€‹

This rule checks parameter mutations through:

  • assignment expressions (param = ...), and
  • update expressions (param++, param--).

It applies only when the target resolves to a parameter variable.

What this rule reportsโ€‹

This rule reports parameter reassignment except when it occurs inside the first ExpressionStatement of a function body.

Why this rule existsโ€‹

Parameter mutation can obscure function contracts and complicate reasoning about input values.

โŒ Incorrectโ€‹

function f(value: number) {
sideEffect();
value += 1;
}

โœ… Correctโ€‹

function f(value: number) {
value += 1;
sideEffect();
}
function f(value: number): number {
const nextValue = value + 1;
return nextValue;
}
function initialize(value: number) {
value = normalize(value);
// โœ… allowed: reassignment occurs in first expression statement
return value;
}

Behavior and migration notesโ€‹

This rule reports only and does not provide an autofix.

To migrate, prefer introducing local variables for transformed parameter values.

Optionsโ€‹

This rule has no options.

Additional examplesโ€‹

function increment(count: number): number {
doWork();
count++;
// โŒ reported: update occurs after the first expression statement
return count;
}

ESLint flat config exampleโ€‹

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-param-reassign": "error",
},
},
];

When not to use itโ€‹

Disable this rule if your codebase allows unrestricted parameter mutation.

Package documentationโ€‹

Rule catalog ID: R035

Further readingโ€‹

Adoption resourcesโ€‹

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.