-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): add rule prefer-literal-enum-member
#1898
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
Thanks for the PR, @oigewan! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
Codecov Report
@@ Coverage Diff @@
## master #1898 +/- ##
=======================================
Coverage 93.09% 93.10%
=======================================
Files 282 283 +1
Lines 9014 9021 +7
Branches 2463 2465 +2
=======================================
+ Hits 8392 8399 +7
Misses 301 301
Partials 321 321
|
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.
a few comments.
Thanks for your work!
packages/eslint-plugin/tests/rules/no-identifier-enum-member.test.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/tests/rules/no-identifier-enum-member.test.ts
Outdated
Show resolved
Hide resolved
@bradzacher PR updated and checks have passed. |
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.
mostly LGTM - a few comments
I think this version of the rule is much better than before - super simple and clear.
Thanks!
packages/eslint-plugin/tests/rules/prefer-literal-enum-member.test.ts
Outdated
Show resolved
Hide resolved
@bradzacher I updated this PR with most of your suggestions. I didn't implement the selector in the way that suggested, but I think that my update addresses the code readability issue. Let me know if I'm missing something. |
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 for this!
prefer-literal-enum-member
Issue:
Several users have run into an unexpected behavior for the no-shadow rule. Specifically, they do not expect that an enum member name will end up shadowing other variables with the same name in that scope, and they consider it a false positive. An example can be seen here #325 (comment)
Changes:
This PR adds a rule that aims to prevent users from assigning a variable to an enum member, which could help alleviate the aforementioned issue. If accepted, the no-shadow rule can be updated with an option that will ignore enum members with documentation recommending that this rule be enabled if said option is also enabled.