Skip to content
Permalink
Browse files

Update: no-self-assign should detect member expression with this (#12279

)

* 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 b962775b8cb7c90985a5ab63e56744bb2ba79644
Showing with 17 additions and 1 deletion.
  1. +3 −0 lib/rules/no-self-assign.js
  2. +14 −1 tests/lib/rules/no-self-assign.js
@@ -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;
}

@@ -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: [
@@ -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.