Skip to content

Commit b962775

Browse files
saberduckplatinumazure
authored andcommitted
Update: no-self-assign should detect member expression with this (#12279)
* Update: no-self-assign should detect member expression with this * Remove redundant condition
1 parent 02977f2 commit b962775

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/rules/no-self-assign.js

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ function isSameMember(left, right) {
6161
if (lobj.type === "MemberExpression") {
6262
return isSameMember(lobj, robj);
6363
}
64+
if (lobj.type === "ThisExpression") {
65+
return true;
66+
}
6467
return lobj.type === "Identifier" && lobj.name === robj.name;
6568
}
6669

tests/lib/rules/no-self-assign.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ ruleTester.run("no-self-assign", rule, {
7070
{
7171
code: "a[\n 'b'\n] = a[\n 'b'\n]",
7272
options: [{ props: false }]
73+
},
74+
{
75+
code: "this.x = this.y",
76+
options: [{ props: true }]
77+
},
78+
{
79+
code: "this.x = this.x",
80+
options: [{ props: false }]
7381
}
7482
],
7583
invalid: [
@@ -120,6 +128,11 @@ ruleTester.run("no-self-assign", rule, {
120128
{ code: "a.b.c = a.b.c", options: [{ props: true }], errors: ["'a.b.c' is assigned to itself."] },
121129
{ code: "a[b] = a[b]", options: [{ props: true }], errors: ["'a[b]' is assigned to itself."] },
122130
{ code: "a['b'] = a['b']", options: [{ props: true }], errors: ["'a['b']' is assigned to itself."] },
123-
{ code: "a[\n 'b'\n] = a[\n 'b'\n]", options: [{ props: true }], errors: ["'a['b']' is assigned to itself."] }
131+
{ code: "a[\n 'b'\n] = a[\n 'b'\n]", options: [{ props: true }], errors: ["'a['b']' is assigned to itself."] },
132+
{
133+
code: "this.x = this.x",
134+
options: [{ props: true }],
135+
errors: ["'this.x' is assigned to itself."]
136+
}
124137
]
125138
});

0 commit comments

Comments
 (0)