Skip to content
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

docs: Add note about invalid CLI flags when using flat config. #17664

Merged
merged 4 commits into from Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/src/use/command-line-interface.md
Expand Up @@ -121,7 +121,7 @@ Miscellaneous:

#### `--no-eslintrc`

Disables use of configuration from `.eslintrc.*` and `package.json` files.
**eslintrc Mode Only.** Disables use of configuration from `.eslintrc.*` and `package.json` files. For flat config mode, use `--no-config-lookup` instead.

* **Argument Type**: No argument.

Expand Down Expand Up @@ -150,7 +150,7 @@ If `.eslintrc.*` and/or `package.json` files are also used for configuration (i.

#### `--env`

This option enables specific environments.
**eslintrc Mode Only.** This option enables specific environments.

* **Argument Type**: String. One of the available environments.
* **Multiple Arguments**: Yes
Expand All @@ -166,7 +166,7 @@ npx eslint --env browser --env node file.js

#### `--ext`

This option allows you to specify which file extensions ESLint uses when searching for target files in the directories you specify.
**eslintrc Mode Only.** This option allows you to specify which file extensions ESLint uses when searching for target files in the directories you specify.

* **Argument Type**: String. File extension.
* **Multiple Arguments**: Yes
Expand All @@ -189,7 +189,7 @@ npx eslint . --ext .js,.ts

#### `--global`

This option defines global variables so that they are not flagged as undefined by the [`no-undef`](../rules/no-undef) rule.
**eslintrc Mode Only.** This option defines global variables so that they are not flagged as undefined by the [`no-undef`](../rules/no-undef) rule.
nzakas marked this conversation as resolved.
Show resolved Hide resolved

* **Argument Type**: String. Name of the global variable. Any specified global variables are assumed to be read-only by default, but appending `:true` to a variable's name ensures that `no-undef` also allows writes.
* **Multiple Arguments**: Yes
Expand Down Expand Up @@ -232,7 +232,7 @@ echo '3 ** 4' | npx eslint --stdin --parser-options ecmaVersion:7 # succeeds, ya

#### `--resolve-plugins-relative-to`

Changes the directory where plugins are resolved from.
**eslintrc Mode Only.** Changes the directory where plugins are resolved from.

* **Argument Type**: String. Path to directory.
* **Multiple Arguments**: No
Expand Down Expand Up @@ -374,7 +374,7 @@ npx eslint --fix --fix-type suggestion,layout .

#### `--ignore-path`

This option allows you to specify the file to use as your `.eslintignore`.
**eslintrc Mode Only.** This option allows you to specify the file to use as your `.eslintignore`.

* **Argument Type**: String. Path to file.
* **Multiple Arguments**: No
Expand Down
9 changes: 8 additions & 1 deletion lib/cli.js
Expand Up @@ -339,7 +339,14 @@ const cli = {
return 0;
} catch (err) {
debug("Error retrieving environment info");
log.error(err.message);

let errorMessage = err.message;

if (usingFlatConfig) {
errorMessage += "\nYou're using eslint.config.js, some command line flags are no longer available. Please see https://eslint.org/docs/latest/use/command-line-interface for details.";
}

log.error(errorMessage);
return 2;
}
Copy link
Member

Choose a reason for hiding this comment

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

This will only execute when --env-info flag is passed and there's an unexpected error while calculating the data for it.

With eslint --ext .ts, I'm still getting the same Invalid option '--ext' - perhaps you meant '-c'? as before.

If we want to display this info when --ext option is passed in flat config mode, I think we'll need to define ext as a valid option for optionator (in options.js) in flat config mode and then manually check if it was passed in.

Copy link
Member

Choose a reason for hiding this comment

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

I think we'll need to define ext as a valid option for optionator (in options.js) in flat config mode and then manually check if it was passed in.

Actually, this might not be a good idea because the option will appear in --help, and also because optionator will validate types and can throw an error before we have a chance to display that the option is invalid.

Might be better to parse the error message (or just always append this info in flat config mode) here:

eslint/lib/cli.js

Lines 319 to 323 in f30cefe

} catch (error) {
debug("Error parsing CLI options:", error.message);
log.error(error.message);
return 2;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call. 👍

}
Expand Down