New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: warn by default for unused disable directives #17879
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
I was thinking about setting this default in languageOptions: {
sourceType: "module",
ecmaVersion: "latest",
parser: require("espree"),
parserOptions: {}
},
+ linterOptions: {
+ reportUnusedDisableDirectives: 1
+ } |
* main: (25 commits) test: ensure that CLI tests run with FlatESLint (eslint#17884) fix!: Behavior of CLI when no arguments are passed (eslint#17644) docs: Update README Revert "feat!: Remove CodePath#currentSegments" (eslint#17890) feat!: Update shouldUseFlatConfig and CLI so flat config is default (eslint#17748) feat!: Remove CodePath#currentSegments (eslint#17756) chore: update dependency markdownlint-cli to ^0.38.0 (eslint#17865) feat!: deprecate no-new-symbol, recommend no-new-native-nonconstructor (eslint#17710) feat!: check for parsing errors in suggestion fixes (eslint#16639) feat!: assert suggestion messages are unique in rule testers (eslint#17532) feat!: `no-invalid-regexp` make allowConstructorFlags case-sensitive (eslint#17533) fix!: no-sequences rule schema correction (eslint#17878) feat!: Update `eslint:recommended` configuration (eslint#17716) feat!: drop support for string configurations in flat config array (eslint#17717) feat!: Remove `SourceCode#getComments()` (eslint#17715) feat!: Remove deprecated context methods (eslint#17698) feat!: Swap FlatESLint-ESLint, FlatRuleTester-RuleTester in API (eslint#17823) feat!: remove formatters except html, json(-with-metadata), and stylish (eslint#17531) feat!: Require Node.js `^18.18.0 || ^20.9.0 || >=21.1.0` (eslint#17725) fix: allow circular references in config (eslint#17752) ...
* main: chore: use jsdoc/no-multi-asterisks with allowWhitespace: true (eslint#17900) chore: fix getting scope in tests (eslint#17899) fix!: Parsing 'exported' comment using parseListConfig (eslint#17675) docs: updated examples of `max-lines` rule (eslint#17898) feat!: Remove valid-jsdoc and require-jsdoc (eslint#17694)
@bmish are you still working on this? This is one of the last changes planned for the upcoming v9.0.0-alpha.0.
Could we maybe fix those tests by adding |
I think here: https://eslint.org/docs/head/use/configure/configuration-files#reporting-unused-disable-directives Also here (at some point in the future, we'll maybe clear this redundancy we now have in the docs): https://eslint.org/docs/head/use/configure/rules#report-unused-eslint-disable-comments And maybe here, at the end of the Default Value line we could add https://eslint.org/docs/head/use/command-line-interface#--report-unused-disable-directives-severity |
* main: docs: Migrate to v9.0.0 (eslint#17905) docs: Switch to flat config by default (eslint#17840) docs: Update Create a Plugin for flat config (eslint#17826) feat!: add two more cases to `no-implicit-coercion` (eslint#17832) docs: Switch shareable config docs to use flat config (eslint#17827) chore: remove creating an unused instance of Linter in tests (eslint#17902) feat!: Switch Linter to flat config by default (eslint#17851)
I moved the default to I still need to add a test for the new default and update some more docs. Will try to do this today. |
I have updated the docs and added tests. This is ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. Just a note on changing rule tests.
@@ -59,8 +59,8 @@ ruleTester.run("capitalized-comments", rule, { | |||
// No options: eslint/istanbul/jshint/jscs/globals?/exported are okay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this and the other rule tests, the intent was to check if directive comments were handled correctly.
Rather than changing all directive comments to non-directive comments, could we instead just turn off reporting of unused directives in those files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the old rule tests aren't actually failing now, because FlatRuleTester has its own baseConfig
, where linterOptions.reportUnusedDisableDirectives
isn't set.
eslint/lib/rule-tester/flat-rule-tester.js
Lines 538 to 586 in d1018fc
const baseConfig = [ | |
{ files: ["**"] }, // Make sure the default config matches for all files | |
{ | |
plugins: { | |
// copy root plugin over | |
"@": { | |
/* | |
* Parsers are wrapped to detect more errors, so this needs | |
* to be a new object for each call to run(), otherwise the | |
* parsers will be wrapped multiple times. | |
*/ | |
parsers: { | |
...defaultConfig[0].plugins["@"].parsers | |
}, | |
/* | |
* The rules key on the default plugin is a proxy to lazy-load | |
* just the rules that are needed. So, don't create a new object | |
* here, just use the default one to keep that performance | |
* enhancement. | |
*/ | |
rules: defaultConfig[0].plugins["@"].rules | |
}, | |
"rule-to-test": { | |
rules: { | |
[ruleName]: Object.assign({}, rule, { | |
// Create a wrapper rule that freezes the `context` properties. | |
create(context) { | |
freezeDeeply(context.options); | |
freezeDeeply(context.settings); | |
freezeDeeply(context.parserOptions); | |
// freezeDeeply(context.languageOptions); | |
return rule.create(context); | |
} | |
}) | |
} | |
} | |
}, | |
languageOptions: { | |
...defaultConfig[0].languageOptions | |
} | |
}, | |
...defaultConfig.slice(1) | |
]; |
Now the question is shall we leave it that way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points. I reverted the rule tests.
On the one hand, it seems like rule tests should generally use the default config? But on the other hand, reporting disable directives seems like it would be unnecessary and even annoying during rule tests, so I'd probably prefer to leave that option off...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think reporting unused directives is probably best left off for rule tests -- I can't imagine people wanting those warnings intermixed with rule errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Would like @mdjermanovic to confirm before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[x] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Fixes #15466. This is part two of that issue. Part one was in #17212.
The goal here is to warn by default for reporting unused disable directives, only when using the new flat config.
TODO:
tests/lib/linter/linter.js
Is there anything you'd like reviewers to focus on?