noParameterAssign
诊断类别:lint/style/noParameterAssign
¥Diagnostic Category: lint/style/noParameterAssign
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
no-param-reassign
¥Same as:
no-param-reassign
禁止重新分配 function
参数。
¥Disallow reassigning function
parameters.
分配给 function
参数可能会产生误导和混淆,因为修改参数也会改变 arguments
对象。这通常是无意的,并且表明程序员犯了错误。
¥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.
与 ESLint 规则相比,此规则无法配置为报告对参数属性的分配。
¥In contrast to the ESLint rule, this rule cannot be configured to report assignments to a property of a parameter.
¥Examples
¥Invalid
code-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.
¥Valid
¥Related links