-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: support TypeScript syntax in no-invalid-this
rule
#19532
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
Conversation
✅ Deploy Preview for docs-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Please take a look at the test failures. |
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.
LGTM, thanks!
Leaving this open for a second review.
docs/src/rules/no-invalid-this.md
Outdated
## When Not To Use It | ||
|
||
If you don't want to be notified about usage of `this` keyword outside of classes or class-like objects, you can safely disable this rule. | ||
|
||
The TypeScript compiler already checks for the issues addressed by this ESLint rule. Therefore, enabling this rule in new TypeScript projects is generally unnecessary. You should only enable it if you prefer ESLint's error messages over the TypeScript compiler's or if you're using it to lint JavaScript code. |
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.
We already have meta fields for this purpose. For example:
eslint/docs/src/rules/no-import-assign.md
Lines 4 to 5 in 6be36c9
handled_by_typescript: true | |
extra_typescript_info: Note that the compiler will not catch the `Object.assign()` case. Thus, if you use `Object.assign()` in your codebase, this rule will still provide some value. |
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.
Actually, this rule's docs already have these fields specified, so this paragraph seems like an unnecessary duplicate.
https://eslint.org/docs/latest/rules/no-invalid-this#handled_by_typescript
lib/rules/no-invalid-this.js
Outdated
AccessorProperty(node) { | ||
stack.push({ | ||
init: true, | ||
node, | ||
valid: true, | ||
}); | ||
}, | ||
|
||
"AccessorProperty:exit"() { | ||
stack.pop(); | ||
}, |
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.
I think this would be a false negative:
function foo() {
class C {
accessor [this.a] = foo;
}
}
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.
Done!
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.
LGTM, thanks! Leaving open for @snitin315 to re-review.
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.
LGTM, thanks!
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[x] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Added support of TypeScript syntax in
no-invalid-this
rule. such asrule will not report
this
when it's type is checked in functions.this
will be allowed in Accessor Property of class field initializers.Is there anything you'd like reviewers to focus on?
Refs #19173.