noSelfAssign
Summary
Section titled “Summary”- Rule available since:
v1.0.0
- Diagnostic Category:
lint/correctness/noSelfAssign
- This rule is recommended, which means is enabled by default.
- This rule doesn’t have a fix.
- The default severity of this rule is error.
- Sources:
- Same as
no-self-assign
- Same as
self_assignment
- Same as
Description
Section titled “Description”Disallow assignments where both sides are exactly the same.
Self assignments have no effect, so probably those are an error due to incomplete refactoring.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”a = a;
code-block.js:1:5 lint/correctness/noSelfAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ a is assigned to itself.
> 1 │ a = a;
│ ^
2 │
ℹ This is where is assigned.
> 1 │ a = a;
│ ^
2 │
ℹ Self assignments have no effect and can be removed.
[a] = [a];
code-block.js:1:8 lint/correctness/noSelfAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ a is assigned to itself.
> 1 │ [a] = [a];
│ ^
2 │
ℹ This is where is assigned.
> 1 │ [a] = [a];
│ ^
2 │
ℹ Self assignments have no effect and can be removed.
({a: b} = {a: b});
code-block.js:1:15 lint/correctness/noSelfAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ b is assigned to itself.
> 1 │ ({a: b} = {a: b});
│ ^
2 │
ℹ This is where is assigned.
> 1 │ ({a: b} = {a: b});
│ ^
2 │
ℹ Self assignments have no effect and can be removed.
a.b = a.b;
code-block.js:1:9 lint/correctness/noSelfAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ b is assigned to itself.
> 1 │ a.b = a.b;
│ ^
2 │
ℹ This is where is assigned.
> 1 │ a.b = a.b;
│ ^
2 │
ℹ Self assignments have no effect and can be removed.
a[b] = a[b];
code-block.js:1:10 lint/correctness/noSelfAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ b is assigned to itself.
> 1 │ a[b] = a[b];
│ ^
2 │
ℹ This is where is assigned.
> 1 │ a[b] = a[b];
│ ^
2 │
ℹ Self assignments have no effect and can be removed.
a[b].foo = a[b].foo;
code-block.js:1:17 lint/correctness/noSelfAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ foo is assigned to itself.
> 1 │ a[b].foo = a[b].foo;
│ ^^^
2 │
ℹ This is where is assigned.
> 1 │ a[b].foo = a[b].foo;
│ ^^^
2 │
ℹ Self assignments have no effect and can be removed.
a['b'].foo = a['b'].foo;
code-block.js:1:21 lint/correctness/noSelfAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ foo is assigned to itself.
> 1 │ a[‘b’].foo = a[‘b’].foo;
│ ^^^
2 │
ℹ This is where is assigned.
> 1 │ a[‘b’].foo = a[‘b’].foo;
│ ^^^
2 │
ℹ Self assignments have no effect and can be removed.
a &= a;var a = a;let a = a;const a = a;[a, b] = [b, a];
How to configure
Section titled “How to configure”{ "linter": { "rules": { "correctness": { "noSelfAssign": "error" } } }}