fix: Throw error when invalid flags passed#18705
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
| flags.forEach(flag => { | ||
| if (inactiveFlags.has(flag)) { | ||
| throw new Error(`The flag '${flag}' is inactive: ${inactiveFlags.get(flag)}`); | ||
| } | ||
|
|
||
| if (!activeFlags.has(flag)) { | ||
| throw new Error(`Unknown flag '${flag}'.`); | ||
| } | ||
| }); |
There was a problem hiding this comment.
We also already have these checks in cli.js, where unknown flags result in exit code 2 but inactive flags only log a warning:
Lines 492 to 508 in 53b1ff0
Now, for inactive flags passed on the command line, ESLint would log both a warning (from cli.js) and an error (from linter):
$ node bin/eslint Makefile.js --flag test_only_old
InactiveFlag: The 'test_only_old' flag is no longer active: Used only for testing.
Oops! Something went wrong! :(
ESLint: 9.7.0
Error: The flag 'test_only_old' is inactive: Used only for testing.
at C:\projects\eslint\lib\linter\linter.js:1288:23
at Array.forEach (<anonymous>)
at new Linter (C:\projects\eslint\lib\linter\linter.js:1286:15)
at new ESLint (C:\projects\eslint\lib\eslint\eslint.js:596:24)
at Object.execute (C:\projects\eslint\lib\cli.js:510:24)
at async main (C:\projects\eslint\bin\eslint.js:153:22)
Perhaps we should sync the behavior to avoid duplicate logs, or maybe just remove the checks in cli.js (if we don't expect to have any cli-level-only flags).
There was a problem hiding this comment.
Also, these two tests are failing (at least for me locally, CI is broken at the moment) because now they result in throwing an error:
Lines 1911 to 1923 in 53b1ff0
eslint/tests/lib/eslint/eslint.js
Lines 330 to 334 in 53b1ff0
There was a problem hiding this comment.
Thanks, I'll update these.
|
This test still needs to be updated: eslint/tests/lib/eslint/eslint.js Lines 330 to 334 in 53b1ff0 |
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[x] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Linternow validatesflagsand throws an error for any inactive or unknown flags. Previously, these flags were ignored, which made it difficult to track down problems.Is there anything you'd like reviewers to focus on?