Disallow usage of eslint-disable-line in favor of eslint-disable-next-line
See original GitHub issuePlease describe what the rule should do:
The rule should enforce using eslint-disable-next-line
instead of using eslint-disable-line
. This requirement comes about because of issues when integrating eslint with prettier, as discussed here:
https://github.com/prettier/prettier/issues/1267 https://github.com/prettier/prettier/issues/2273 https://github.com/prettier/prettier/issues/3011
Running prettier together with eslint can cause issues when prettier moves eslint-disable-line
comments to the previous line, thus breaking its’ intended behaviour. This can easily be solved by making sure that only the eslint-disable-next-line
style is used, but there is no way for us to enforce this behaviour.
What category of rule is this? (place an “X” next to just one item)
[ ] Warns about a potential error (problem) [ ] Suggests an alternate way of doing something (suggestion) [X] Enforces code style (layout) [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
Bad code
alert('foo'); // eslint-disable-line
alert('foo'); /* eslint-disable-line */
alert('foo'); // eslint-disable-line no-alert
alert('foo'); /* eslint-disable-line no-alert */
Good code
// eslint-disable-next-line
alert('foo');
/* eslint-disable-next-line */
alert('foo');
// eslint-disable-next-line no-alert
alert('foo');
/* eslint-disable-next-line no-alert */
alert('foo');
Why should this rule be included in ESLint (instead of a plugin)?
I think that quite a few people are integrating prettier with eslint and, with time, this issue could become more and more prominent. Furthermore, I am not 100% sure whether this can actually be implemented as a plugin.
Are you willing to submit a pull request to implement this rule?
I’d be happy to but I don’t know anything about the eslint codebase and I would like to check whether you would be interested in accepting this change before I work on it.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@aberonni I had to solve this problem when I was enabling Prettier on some codebases. The only foolproof solution when using Prettier is to disallow
// eslint-disable-line rule-name
and// eslint-disable-next-line rule-name
entirely in favor of/* eslint-disable rule-name */
and/* eslint-enable rule-name */
around the statement you want to disable the rule for.I also enforced this using the
no-use
rule fromeslint-plugin-eslint-comments
.It seems that this is already doable via the eslint-comments plugin: https://mysticatea.github.io/eslint-plugin-eslint-comments/rules/no-use.html#options
Closing the issue, thanks to everyone for the help and sorry for the noise.