Skip to content

Commit

Permalink
Update: no-self-assign should detect member expression with this (#12279
Browse files Browse the repository at this point in the history
)

* Update: no-self-assign should detect member expression with this

* Remove redundant condition
  • Loading branch information
saberduck authored and platinumazure committed Oct 15, 2019
1 parent 02977f2 commit b962775
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/rules/no-self-assign.js
Expand Up @@ -61,6 +61,9 @@ function isSameMember(left, right) {
if (lobj.type === "MemberExpression") {
return isSameMember(lobj, robj);
}
if (lobj.type === "ThisExpression") {
return true;
}
return lobj.type === "Identifier" && lobj.name === robj.name;
}

Expand Down
15 changes: 14 additions & 1 deletion tests/lib/rules/no-self-assign.js
Expand Up @@ -70,6 +70,14 @@ ruleTester.run("no-self-assign", rule, {
{
code: "a[\n 'b'\n] = a[\n 'b'\n]",
options: [{ props: false }]
},
{
code: "this.x = this.y",
options: [{ props: true }]
},
{
code: "this.x = this.x",
options: [{ props: false }]
}
],
invalid: [
Expand Down Expand Up @@ -120,6 +128,11 @@ ruleTester.run("no-self-assign", rule, {
{ code: "a.b.c = a.b.c", options: [{ props: true }], errors: ["'a.b.c' is assigned to itself."] },
{ code: "a[b] = a[b]", options: [{ props: true }], errors: ["'a[b]' is assigned to itself."] },
{ code: "a['b'] = a['b']", options: [{ props: true }], errors: ["'a['b']' is assigned to itself."] },
{ code: "a[\n 'b'\n] = a[\n 'b'\n]", options: [{ props: true }], errors: ["'a['b']' is assigned to itself."] }
{ code: "a[\n 'b'\n] = a[\n 'b'\n]", options: [{ props: true }], errors: ["'a['b']' is assigned to itself."] },
{
code: "this.x = this.x",
options: [{ props: true }],
errors: ["'this.x' is assigned to itself."]
}
]
});

0 comments on commit b962775

Please sign in to comment.