Closed mysticatea closed 5 years ago
I wonder if this is the right approach?
My thinking: Enums are sort of like objects, and enum values are sort of like object properties. I don't think we check object properties in no-unused-vars. So I feel that enum values also shouldn't be considered variables and shouldn't be added to a variable scope.
Maybe this isn't possible for other reasons? Let me know.
It's better if the enum members behaved like properties. In fact, those close to variables. See also: https://github.com/eslint/typescript-eslint-parser/issues/552#issuecomment-439276282
i'm unsure if this is good way to do it, it will be better if this will be supported by eslint-plugin-typescript
?
with actual checking if they are used?
with that we are leaving users with possibility to turn on/off this
I think that this approach is fair enough because:
eslintUsed
property.The typescript/use-enum-members
rule or something like (as similar to react/jsx-uses-vars) work for me.
But I think nice if it's supported in the parser because the similar /* exported */
directive is supported in core.
This issue is causing my team to sprinkle /* eslint-disable no-unused-vars */
in our codebase whenever we have an enum. I'm happy to help fix this, or to augment typescript/no-unused-vars
to handle this. What do y'all think should be done here?
there is PR in eslint-plugin-typescript
with this: https://github.com/bradzacher/eslint-plugin-typescript/pull/236
@armano2 @bradzacher Will merging this PR interfere with the plugin's implementation in any way?
@JamesHenry - I don't think so. In fact, it means we can delete some code!
Closing this PR since the project has been moved to the TypeScript ESLint organization. Feel free to reopen the PR there.
This is a small followup for #553.
Currently,
no-unused-vars
rule reports enum members.This behavior is not nice.
This PR makes to set
eslintUsed
flag to the enum member variables, as similar to/* exported */
directive comments. As a result,no-unused-vars
knows the enum members are exported (used on other places).