-
-
Notifications
You must be signed in to change notification settings - Fork 412
Add no-accessor-recursion
rule
#2525
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
Add no-accessor-recursion
rule
#2525
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
docs/rules/no-accessor-recursion.md
Outdated
@@ -0,0 +1,74 @@ | |||
# Disallow recursive access to this within getter and setter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Disallow recursive access to this within getter and setter | |
# Disallow recursive access to `this` within getters and setters |
rules/no-accessor-recursion.js
Outdated
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: 'Disallow recursive access to this within getter and setter', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description: 'Disallow recursive access to this within getter and setter', | |
description: 'Disallow recursive access to `this` within getters and setters.', |
Can you rename the test file from |
533092e
to
cd67a7c
Compare
You need to regenerate the snapshots |
This comment was marked as resolved.
This comment was marked as resolved.
The last case is already supported and tested, the other cases I don't think anyone will write that way. And they are difficult to detect, Maybe we should ignore it |
rules/no-accessor-recursion.js
Outdated
@param {import('estree').VariableDeclarator} parent | ||
@param {import('estree').Property | import('estree').MethodDefinition} property | ||
*/ | ||
const isRecursiveDestructuringAccess = (parent, property) => parent.type === 'VariableDeclarator' && parent.id.type === 'ObjectPattern' && parent.id.properties.some(declaratorProperty => declaratorProperty.type === 'Property' && isSameKey(declaratorProperty.key, property.key)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not checking (Not needed), and shorthand
computed
.
@axetroy Handled more cases |
@@ -240,5 +240,20 @@ test.snapshot({ | |||
} | |||
} | |||
`, | |||
// | |||
...[ | |||
'++ this.bar;', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know how this
works in class static initialization blocks? Can you check if we need logic adjustments?
Alright, I found
So, I think we need some updates to const foo = {
get bar() {
class Foo {
static {
this.bar // <- This should not reported.
}
}
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
Close #1052