Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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."]
}
]
});