selfAssignments
Reports self-assignments which have no effect and are likely errors.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
Self-assignments where a variable is assigned to itself have no effect and typically indicate an incomplete refactoring or a copy-paste error. These assignments serve no purpose and should be removed or corrected to assign the intended value.
Examples
Section titled “Examples”3F53va3F53co3F53f3F53dOptions
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”There are rarely valid reasons to use self-assignment. In cases where you need to trigger getters/setters or proxies, consider adding a comment explaining the intentional self-assignment.
Further Reading
Section titled “Further Reading”- MDN: Assignment operators
- MDN: Logical AND assignment
- MDN: Logical OR assignment
- MDN: Nullish coalescing assignment
Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noSelfAssign - Deno:
no-self-assign - ESLint:
no-self-assign - Oxlint:
eslint/no-self-assign
