noParameterAssign
Ce contenu n’est pas encore disponible dans votre langue.
Diagnostic Category: lint/style/noParameterAssign
Since: v1.0.0
Sources:
- Same as:
no-param-reassign
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.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.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.
code-block.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.
code-block.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.
code-block.ts: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.