Skip to content

No Param Reassignments

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 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 .

  • ( by default) - If is set, this rule warns modifying of properties of parameters.

The following patterns are considered problems:

When :

The following patterns are not considered problems:

When :

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

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 object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

Rule Details

This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.

Examples of incorrect code for this rule:

Examples of correct code for this rule:

Options

This rule takes one option, an object, with a boolean property and an array . is by default. If is set to , this rule warns against the modification of parameter properties unless they’re included in , which is an empty array by default.

props

Examples of correct code for the default option:

Examples of incorrect code for the option:

Examples of correct code for the option with set:

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