no-self-assign
eslint
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"no-self-assign": "error",
},
},
];Disallow assignments where both sides are exactly the same
foo = foo;
[a, b] = [a, b];
[a, ...b] = [x, ...b];
({a, b} = {a, x});
foo &&= foo;
foo ||= foo;
foo ??= foo;foo = bar;
[a, b] = [b, a];
// This pattern is warned by the `no-use-before-define` rule.
let foo = foo;
// The default values have an effect.
[foo = 1] = [foo];
// non-self-assignments with properties.
obj.a = obj.b;
obj.a.b = obj.c.b;
obj.a.b = obj.a.c;
obj[a] = obj["a"];
// This ignores if there is a function call.
obj.a().b = obj.a().b;
a().b = a().b;
// `&=` and `|=` have an effect on non-integers.
foo &= foo;
foo |= foo;
// Known limitation: this does not support computed properties except single literal or single identifier.
obj[a + b] = obj[a + b];
obj["a" + "b"] = obj["a" + "b"];Examples from the ESLint documentation.
no-self-assign
eslint
export default [
{
rules: {
"no-self-assign": "error",
},
},
];no-self-assign
eslint plugin · correctness
{
"rules": {
"no-self-assign": "error"
}
}correctness/noSelfAssign
correctness · since 1.0.0
{
"linter": {
"rules": {
"correctness": {
"noSelfAssign": "error"
}
}
}
}Disallow empty destructuring patterns
Enforce comparing typeof expressions against valid strings
Disallow empty character classes in regular expressions
Disallow reassigning const, using, and await using variables