-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Add --ext
CLI option
#19405
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: Add --ext
CLI option
#19405
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
@@ -218,17 +218,17 @@ describe("cli", () => { | |||
it(`should use it when an eslint.config.js is present and useFlatConfig is true:${configType}`, async () => { | |||
process.cwd = getFixturePath; | |||
|
|||
const exitCode = await cli.execute(`--no-ignore --ext .js ${getFixturePath("files")}`, null, useFlatConfig); | |||
const exitCode = await cli.execute(`--no-ignore --env es2024 ${getFixturePath("files")}`, null, useFlatConfig); |
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.
This test, and a couple of tests below it, need an eslintrc-only CLI option.
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 another review before merging.
if (ext) { | ||
overrideConfig.push({ | ||
files: ext.map(extension => `**/*${extension.startsWith(".") ? "" : "."}${extension}`) | ||
}); | ||
} | ||
|
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.
When I run this command on a zsh terminal:
node bin/eslint.js --ext ""
I get an error like:
Oops! Something went wrong! :(
ESLint: 9.19.0
TypeError: Config (unnamed): Key "files": Expected value to be a non-empty array at user-defined index 34.
at wrapConfigErrorWithDetails (.../lib/config/flat-config-array.js:64:12)
at .../lib/config/flat-config-array.js:145:27
at async ConfigLoader.calculateConfigArray (.../lib/config/config-loader.js:557:9)
at async #calculateConfigArray (.../lib/config/config-loader.js:633:29)
at async entryFilter (.../lib/eslint/eslint-helpers.js:281:33)
at async NodeHfs.<anonymous> (file://.../node_modules/@humanfs/core/src/hfs.js:574:24)
at async NodeHfs.walk (file://.../node_modules/@humanfs/core/src/hfs.js:614:3)
at async globSearch (.../lib/eslint/eslint-helpers.js:323:26)
at async Promise.allSettled (index 0)
at async globMultiSearch (.../lib/eslint/eslint-helpers.js:408:21)
It seems it would be better to catch this error in the CLI to provide a clear error message?
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 catch! We probably want to validate that ext
is not an empty string when the CLI options are validated.
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.
It seems it would be better to catch this error in the CLI to provide a clear error message?
Good idea! Yeah, it's not clear that --ext
relates to Key "files"
. I'll update this.
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.
Updated in ef7a1ee
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! Just waiting for #19376 to be closed before merging.
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
[x] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
Fixes #19361
What changes did you make? (Give an overview)
Added new
--ext
CLI option as per #19361 (comment).Is there anything you'd like reviewers to focus on?
This is a CLI-only option. Integrations can enable additional file extensions in
baseConfig
oroverrideConfig
.