Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
with
17 additions
and
1 deletion.
-
+3
−0
lib/rules/no-self-assign.js
-
+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."] |
|
|
} |
|
|
] |
|
|
}); |