mysticatea / eslint-plugin-eslint-comments

Additional ESLint rules for directive comments of ESLint.
https://mysticatea.github.io/eslint-plugin-eslint-comments/
MIT License
361 stars 45 forks source link

Error with `eslint-comments/no-unused-disable` alongside `no-console` rule #31

Closed ntwb closed 5 years ago

ntwb commented 5 years ago

Over in stylelint #4196 we have an issue where we are using:

"eslint-plugin-eslint-comments": "^3.1.2",

Via https://travis-ci.com/stylelint/stylelint/jobs/223902356#L231

/Users/netweb/Code/stylelint/stylelint/lib/getPostcssResult.js
  116:39  error  'no-console' rule is disabled but never reported  eslint-comments/no-unused-disable

/Users/netweb/Code/stylelint/stylelint/lib/rules/declaration-block-no-shorthand-property-overrides/index.js
  42:29  error  Do not access Object.prototype method 'hasOwnProperty' from target object  no-prototype-builtins

/Users/netweb/Code/stylelint/stylelint/lib/testUtils/createRuleTester.js
  212:71  error  'no-console' rule is disabled but never reported  eslint-comments/no-unused-disable
  293:71  error  'no-console' rule is disabled but never reported  eslint-comments/no-unused-disable

/Users/netweb/Code/stylelint/stylelint/lib/utils/__tests__/nodeContextLookup.test.js
  71:67  error  'no-console' rule is disabled but never reported  eslint-comments/no-unused-disable

/Users/netweb/Code/stylelint/stylelint/scripts/benchmark-rule.js
  3:19  error  'no-console' rule is disabled but never reported  eslint-comments/no-unused-disable

/Users/netweb/Code/stylelint/stylelint/system-tests/004/004.test.js
  20:70  error  'no-console' rule is disabled but never reported  eslint-comments/no-unused-disable

For example, the last error from above for system-tests/004/004.test.js#L20

function handleError(err /*: { stack: any, code: any }*/) /*: void */ {
  console.log(err.stack); // eslint-disable-line no-console
  const exitCode = typeof err.code === "number" ? err.code : 1;

  process.exit(exitCode); // eslint-disable-line no-process-exit
}

So, console.log is only triggered on error, the no-console ESLint rule here works as expected, but eslint-plugin-eslint-comments

mysticatea commented 5 years ago

Thank you for this issue.

This is the correct behavior because no-console rule was removed from eslint:recommended config. If you want no-console to enable, configure it in your .eslintrc file.

See also: https://eslint.org/docs/user-guide/migrating-to-6.0.0

ntwb commented 5 years ago

Thanks @mysticatea, I missed that and you are correct that resolves the issue 💯