no-self-assign
What it does
Section titled “What it does”Reports an assignment whose two sides are the same tokens (x = x, x.y = x.y, x[0] = x[0], x ||= x). The option operators lists the operators that store the right side as it is (=, ||=, &&=, ??=); x += x is not reported.
Why it matters
Section titled “Why it matters”The assignment changes nothing, or only calls a getter and a setter for nothing. It is nearly always a typing error where the right side should have been another variable, such as a parameter with the same name as a field.
To fix, name the right variable, or delete the statement.
Example
Section titled “Example”a = a; a.b = a.b; a["b"] = a.b; a[b] = a[b]; this.c = this.c; a = b; a.b = a.c; a &&= a; a += a;[a, b] = [a, b]; [a, ...b] = [a, ...b]; [a, b] = [b, a]; ({ a } = { a }); ({ a: b } = { a: b });...var x = (a = b) ? 1 : 2, y = a = b ? 1 : 2;...Configuration
Section titled “Configuration”c: lint: rules: no-self-assign: level: warn # off, warn (default), error options: operators: ["=","||=","&&=","??="]cpp: lint: rules: no-self-assign: level: warn # off, warn (default), error options: operators: ["=","||=","&&=","??="]csharp: lint: rules: no-self-assign: level: warn # off, warn (default), error options: operators: ["=","||=","&&=","??="]go: lint: rules: no-self-assign: level: warn # off, warn (default), error options: operators: ["=","||=","&&=","??="]java: lint: rules: no-self-assign: level: warn # off, warn (default), error options: operators: ["=","||=","&&=","??="]js: lint: rules: no-self-assign: level: warn # off, warn (default), error options: operators: ["=","||=","&&=","??="]php: lint: rules: no-self-assign: level: warn # off, warn (default), error options: operators: ["=","||=","&&=","??="]python: lint: rules: no-self-assign: level: warn # off, warn (default), error options: operators: ["=","||=","&&=","??="]ruby: lint: rules: no-self-assign: level: warn # off, warn (default), error options: operators: ["=","||=","&&=","??="]| Option | Type | Default | Description |
|---|---|---|---|
operators |
list | `[“=”,” |
Enabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint, ruby/rubocop.
Suppress one line with sudsy-disable-next-line no-self-assign in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| eslint | no-self-assign |
partial | the props option is always on; only identifiers and static member chains are compared |
| rubocop | Lint/SelfAssignment |
partial | not multiple assignment (a, b = a, b) |