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

fix: no-invalid-this false positive in class field initializer #15495

Merged
merged 2 commits into from Jan 15, 2022
Merged

Conversation

mdjermanovic
Copy link
Member

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Fixes #15477.

What changes did you make? (Give an overview)

Refactored no-invalid-this to use code path analysis, which is better for handling edge cases with PropertyDefinition > *.value and fixes the #15477 bug where this appears directly as a class field initializer.

Is there anything you'd like reviewers to focus on?

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Jan 7, 2022
Copy link
Member

@btmills btmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! The code path implementation is quite a bit easier to follow.

@btmills btmills merged commit a8db9a5 into main Jan 15, 2022
@btmills btmills deleted the issue15477 branch January 15, 2022 22:58
@gfyoung
Copy link
Contributor

gfyoung commented Jan 16, 2022

@btmills @mdjermanovic: I saw this got released in 5.7.0 (over 5.6.0), but I believe this is in fact a breaking change, as the downstream typescript-eslint/eslint-plugin library relies on FunctionExpression/FunctionExpression:exit (see their most recent v5.9.1 release). Is this over-reliance on internal implementation?

https://github.com/typescript-eslint/typescript-eslint/blob/v5.9.1/packages/eslint-plugin/src/rules/no-invalid-this.ts#L85-L90

@btmills
Copy link
Member

btmills commented Jan 16, 2022

@bradzacher heads up that this change might affect typescript-eslint's extended no-invalid-this implementation.

@gfyoung rule implementations aren't part of ESLint's official public API. When we added package.json exports as a breaking change in ESLint v8, we left the use-at-your-own-risk export that typescript-eslint uses to extend built-in rules. The tradeoff is having to keep a closer eye on changes to those rules. Thanks for noticing the impact so I could give the typescript-eslint team a heads up above.

@bradzacher
Copy link
Contributor

Feel free raise an issue across in typescript-eslint/typescript-eslint to track this!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: no-invalid-this: false positive with this in class field
4 participants