Disallow Reassignment of Function Parameters (no-param-reassign)

Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

Rule Details

This rule aims to prevent unintended behavior caused by overwriting function parameters.

Options

This rule takes one option, an object, with a property "props".

{
    "no-param-reassign": [2, {"props": false}]
}

The following patterns are considered warnings:

function foo(bar) {
    bar = 13;
}
function foo(bar) {
    bar++;
}

When {"props": true}:

function foo(bar) {
    bar.prop = "value";
}
function foo(bar) {
    delete bar.aaa;
}
function foo(bar) {
    bar.aaa++;
}

The following patterns are not warnings:

function foo(a) {
    var b = a;
}

When {"props": false}:

function foo(bar) {
    bar.prop = "value";
}
function foo(bar) {
    delete bar.aaa;
}
function foo(bar) {
    bar.aaa++;
}

When Not To Use It

If you want to allow assignment to function parameters, then you can safely disable this rule.

Further Reading

Version

This rule was introduced in ESLint 0.18.0.

Resources