question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disallow usage of eslint-disable-line in favor of eslint-disable-next-line

See original GitHub issue

Please 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kaicataldocommented, Jan 11, 2019

@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 from eslint-plugin-eslint-comments.

0reactions
aberonnicommented, Jan 8, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turning off eslint rule for a specific line - Stack Overflow
To disable next line: // eslint-disable-next-line no-use-before-define var thing = new Thing();. Or use the single line syntax:
Read more >
Rules - ESLint - Pluggable JavaScript Linter
To disable all rules on a specific line, use a line or block comment in one of the following formats: alert('foo'); // eslint-disable-line...
Read more >
How to disable ESLint for some lines, files or folders
ESLint - is a very convenient tool to control code quality. But, sometimes it's necessary to disable it. In this tutorial, you'll learn...
Read more >
Ignoring ESLint - next.config.js
If you'd like Next.js to produce production code even when your application has ESLint errors, you can disable the built-in linting step completely....
Read more >
eslint disable block Code Example
alert('foo'); // eslint-disable-line // eslint-disable-next-line alert('foo');
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found