If you use ESLint, then you’ve had to disable a linter rule at some point or another. You might be familiar with this syntax for disabling a lint rule reported on the next line:
If you work on a big codebase, you’re probably familiar with writing to-do notes for yourself or your teammates. You’ve probably written comments like this:
However, how do you combine these two comments? I often want to write a TODO to fix a linter rule violation, but I wasn’t sure what the best style was. Previously I’d write something like:
Turns out, there’s a better way. ESLint supports comment descriptions for its eslint-disable
comments! You just write a --
and then can put any description you want afterwards.
This also works with multiple lines:
The benefit of using this format is that ESLint will automatically remove the disable comment directive and description together if they are no longer necessary. As long as you use the reportUnusedDisableDirectives
option, the autofixer will clean them up for you.
You can also require developers to add descriptions to these comments using the eslint-comments/require-description rule. No more danging TODOs or confusing // eslint-disable-next-line
comments!