There's a no-unused-vars eslint rule that can warn/error if a variable is unused:
https://eslint.org/docs/rules/no-unused-vars
If I want to ensure that there are no unused enums, what would be the best lint rule to implement?
Example scenario:
export enum MyEnum {
ONE = 'ONE',
TWO = 'TWO',
THREE = 'THREE',
}
Here MyEnum.ONE and MyEnum.TWO are both used, but MyEnum.THREE is not referenced.
if (type === MyEnum.ONE) {
...
}
if (type === MyEnum.TWO) {
...
}
It would be great if a lint rule could warn/error that MyEnum.THREE is unused so that it may be removed.
There is no existing rule to do this so you've got a couple of options:
As an aside, make sure you are using the Typescript version of no-unused-vars rule. Even then it doesn't detect unused exported variables because each file is analysed individually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With