0

While I have a pretty good .eslintrc file, I sometimes need to break some rule intentionally (could be as simple as a temporary console.log, or even one that's supposed to stay).

However, I feel using the raw inline // eslint-disable-rule is a pitfall, because of multiple reasons :

  • If you have multiple warnings on the same line, it could easily silence the warning of a rule you weren't aware you broke
  • Always specifying a rule is way more readable because it shows the intent way more clearly

That's why I'm looking for an option to force specifying the rule(s) when you want to disable a line. Is there a way to achieve this ?

Kewin Dousse
  • 3,880
  • 2
  • 25
  • 46
  • I'm not sure what your asking, but add hock disables, you could do `//eslint-disable-line` at the end of the line.. eg. To disable the `new-cap` `var x = new y(); //eslint-disable-line new-cap` – Keith Jul 05 '18 at 09:50
  • @Keith I know : I want to *force* specifiying the rule at the end of eslint-disable-line. I want to be unable to just use `// eslint-disable-rule` without telling which rule to disable. Is it clear enough ? – Kewin Dousse Jul 05 '18 at 09:55
  • So you want to make sure `//eslint-disable-line xxx` exists,. Not sure this is built in but if you don't mind getting your hands dirty, the function `createDisableDirectives` could be modified, if the `value` is say empty you could say return an invalid directive,.. eg. `please-supply-something`, this will then prevent the `eslint-disable-line` from blocking all linting errors.. – Keith Jul 05 '18 at 10:13
  • Thanks. If it's not built in, I might get my hands dirty indeed. I'm not familiar at all with the codebase of eslint though. Could you point me to where that function is in the GitHub repo, for example ? – Kewin Dousse Jul 05 '18 at 10:17
  • 1
    https://github.com/eslint/eslint/blob/master/lib/linter.js Line 250.. – Keith Jul 05 '18 at 10:19
  • Thanks ! :) I'm gonna take a look. – Kewin Dousse Jul 05 '18 at 10:20
  • No problem, .. looking at the code it should be as simple as replacing that `null` with say `'please-supply-a-directive'` or something like that. – Keith Jul 05 '18 at 10:29

0 Answers0