Skip to content

noParameterAssign (since v1.0.0)

Diagnostic Category: lint/style/noParameterAssign

Sources:

Disallow reassigning function parameters.

Assignment to a function parameters can be misleading and confusing, as modifying parameters will also mutate the arguments object. It is often unintended and indicative of a programmer error.

In contrast to the ESLint rule, this rule cannot be configured to report assignments to a property of a parameter.

function f(param) {
param = 13;
}
style/noParameterAssign.js:2:5 lint/style/noParameterAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Reassigning a function parameter is confusing.
  
    1 │ function f(param) {
  > 2 │     param = 13;
       ^^^^^
    3 │ }
    4 │ 
  
   The parameter is declared here:
  
  > 1 │ function f(param) {
              ^^^^^
    2 │     param = 13;
    3 │ }
  
   Use a local variable instead.
  
function f(param) {
param++;
}
style/noParameterAssign.js:2:5 lint/style/noParameterAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Reassigning a function parameter is confusing.
  
    1 │ function f(param) {
  > 2 │     param++;
       ^^^^^
    3 │ }
    4 │ 
  
   The parameter is declared here:
  
  > 1 │ function f(param) {
              ^^^^^
    2 │     param++;
    3 │ }
  
   Use a local variable instead.
  
function f(param) {
for (param of arr) {}
}
style/noParameterAssign.js:2:10 lint/style/noParameterAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Reassigning a function parameter is confusing.
  
    1 │ function f(param) {
  > 2 │     for (param of arr) {}
            ^^^^^
    3 │ }
    4 │ 
  
   The parameter is declared here:
  
  > 1 │ function f(param) {
              ^^^^^
    2 │     for (param of arr) {}
    3 │ }
  
   Use a local variable instead.
  
class C {
constructor(readonly prop: number) {
prop++
}
}
style/noParameterAssign.js:3:9 lint/style/noParameterAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Reassigning a function parameter is confusing.
  
    1 │ class C {
    2 │     constructor(readonly prop: number) {
  > 3 │         prop++
           ^^^^
    4 │     }
    5 │ }
  
   The parameter is declared here:
  
    1 │ class C {
  > 2 │     constructor(readonly prop: number) {
                            ^^^^^^^^^^^^
    3 │         prop++
    4 │     }
  
   Use a local variable instead.
  
function f(param) {
let local = param;
}