+
Skip to content

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

Merged
merged 3 commits into from
Feb 12, 2025
Merged

feat: Add --ext CLI option #19405

merged 3 commits into from
Feb 12, 2025

Conversation

mdjermanovic
Copy link
Member

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 or overrideConfig.

@mdjermanovic mdjermanovic requested a review from a team as a code owner February 5, 2025 09:44
@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Feb 5, 2025
@github-actions github-actions bot added the cli Relates to ESLint's command-line interface label Feb 5, 2025
Copy link

netlify bot commented Feb 5, 2025

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit ef7a1ee
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/67ab9d6d40a227000812d72c

@mdjermanovic mdjermanovic added the accepted There is consensus among the team that this change meets the criteria for inclusion label Feb 5, 2025
@@ -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);
Copy link
Member Author

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.

nzakas
nzakas previously approved these changes Feb 5, 2025
Copy link
Member

@nzakas nzakas left a 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.

Comment on lines +195 to +200
if (ext) {
overrideConfig.push({
files: ext.map(extension => `**/*${extension.startsWith(".") ? "" : "."}${extension}`)
});
}

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in ef7a1ee

Copy link
Member

@fasttime fasttime left a 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.

@nzakas nzakas merged commit 5c5b802 into main Feb 12, 2025
31 checks passed
@nzakas nzakas deleted the issue19361 branch February 12, 2025 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion cli Relates to ESLint's command-line interface feature This change adds a new feature to ESLint
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

Bug: Running CLI with only one rule fails to match any file
3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载