Skip to content

Commit b48e4f8

Browse files
bpmutternzakassnitin315amareshsm
authoredNov 16, 2022
docs: Command Line Interface intro and tweaks (#16535)
* docs: CLI intro + copy tweaks * copy edits * Apply suggestions from code review Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com> Co-authored-by: Nitin Kumar <snitin315@gmail.com> Co-authored-by: Amaresh S M <amareshsm13@gmail.com> Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com> Co-authored-by: Nitin Kumar <snitin315@gmail.com> Co-authored-by: Amaresh S M <amareshsm13@gmail.com>
1 parent b92b30f commit b48e4f8

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed
 

‎docs/src/user-guide/command-line-interface.md

+26-22
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ eleventyNavigation:
88

99
---
1010

11+
The ESLint Command Line Interface (CLI) lets you execute linting from the terminal. The CLI has a variety of options that you can pass to configure ESLint.
12+
13+
## Run the CLI
14+
1115
ESLint requires Node.js for installation. Follow the instructions in the [Getting Started Guide](getting-started) to install ESLint.
1216

1317
Most users use [`npx`](https://docs.npmjs.com/cli/v8/commands/npx) to run ESLint on the command line like this:
@@ -26,7 +30,7 @@ npx eslint file1.js file2.js
2630
npx eslint lib/**
2731
```
2832

29-
Please note that when passing a glob as a parameter, it will be expanded by your shell. The results of the expansion can vary depending on your shell, and its configuration. If you want to use node `glob` syntax, you have to quote your parameter (using double quotes if you need it to run in Windows), as follows:
33+
Please note that when passing a glob as a parameter, it is expanded by your shell. The results of the expansion can vary depending on your shell, and its configuration. If you want to use node `glob` syntax, you have to quote your parameter (using double quotes if you need it to run in Windows), as follows:
3034

3135
```shell
3236
npx eslint "lib/**"
@@ -106,7 +110,7 @@ Example:
106110

107111
```shell
108112
npx eslint --ext .jsx --ext .js lib/
109-
113+
# OR
110114
npx eslint --ext .jsx,.js lib/
111115
```
112116

@@ -134,7 +138,7 @@ npx eslint -c ~/my-eslint.json file.js
134138

135139
This example uses the configuration file at `~/my-eslint.json`.
136140

137-
If `.eslintrc.*` and/or `package.json` files are also used for configuration (i.e., `--no-eslintrc` was not specified), the configurations will be merged. Options from this configuration file have precedence over the options from `.eslintrc.*` and `package.json` files.
141+
If `.eslintrc.*` and/or `package.json` files are also used for configuration (i.e., `--no-eslintrc` was not specified), the configurations are merged. Options from this configuration file have precedence over the options from `.eslintrc.*` and `package.json` files.
138142

139143
#### `--env`
140144

@@ -149,7 +153,7 @@ npx eslint --env browser --env node file.js
149153

150154
#### `--ext`
151155

152-
This option allows you to specify which file extensions ESLint will use when searching for target files in the directories you specify.
156+
This option allows you to specify which file extensions ESLint uses when searching for target files in the directories you specify.
153157
By default, ESLint lints `*.js` files and the files that match the `overrides` entries of your configuration.
154158

155159
Examples:
@@ -167,11 +171,11 @@ npx eslint . --ext .js,.ts
167171

168172
**Note:** `--ext` is only used when the arguments are directories. If you use glob patterns or file names, then `--ext` is ignored.
169173

170-
For example, `npx eslint lib/* --ext .js` will match all files within the `lib/` directory, regardless of extension.
174+
For example, `npx eslint lib/* --ext .js` matches all files within the `lib/` directory, regardless of extension.
171175

172176
#### `--global`
173177

174-
This option defines global variables so that they will not be flagged as undefined by the `no-undef` rule. Any specified global variables are assumed to be read-only by default, but appending `:true` to a variable's name ensures that `no-undef` will also allow writes. To specify multiple global variables, separate them using commas, or use the option multiple times.
178+
This option defines global variables so that they are not flagged as `undefined` by the `no-undef` rule. 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. To specify multiple global variables, separate them using commas, or use the option multiple times.
175179

176180
Examples:
177181

@@ -182,7 +186,7 @@ npx eslint --global require --global exports:true
182186

183187
#### `--parser`
184188

185-
This option allows you to specify a parser to be used by ESLint. By default, `espree` will be used.
189+
This option allows you to specify a parser to be used by ESLint. By default, `espree` is used.
186190

187191
#### `--parser-options`
188192

@@ -191,7 +195,7 @@ This option allows you to specify parser options to be used by ESLint. Note that
191195
Examples:
192196

193197
```shell
194-
echo '3 ** 4' | npx eslint --stdin --parser-options=ecmaVersion:6 # will fail with a parsing error
198+
echo '3 ** 4' | npx eslint --stdin --parser-options=ecmaVersion:6 # fails with a parsing error
195199
echo '3 ** 4' | npx eslint --stdin --parser-options=ecmaVersion:7 # succeeds, yay!
196200
```
197201

@@ -219,7 +223,7 @@ npx eslint --plugin eslint-plugin-mocha file.js
219223

220224
#### `--rule`
221225

222-
This option specifies rules to be used. These rules will be merged with any rules specified with configuration files. (You can use `--no-eslintrc` to change that behavior.) To define multiple rules, separate them using commas, or use the option multiple times. The [levn](https://github.com/gkz/levn#levn--) format is used for specifying the rules.
226+
This option specifies the rules to be used. These rules are merged with any rules specified with configuration files. (You can use `--no-eslintrc` to change that behavior.) To define multiple rules, separate them using commas, or use the option multiple times. The [levn](https://github.com/gkz/levn#levn--) format is used for specifying the rules.
223227

224228
If the rule is defined within a plugin, you have to prefix the rule ID with the plugin name and a `/`.
225229

@@ -366,7 +370,7 @@ npx eslint --quiet file.js
366370

367371
This option allows you to specify a warning threshold, which can be used to force ESLint to exit with an error status if there are too many warning-level rule violations in your project.
368372

369-
Normally, if ESLint runs and finds no errors (only warnings), it will exit with a success exit status. However, if `--max-warnings` is specified and the total warning count is greater than the specified threshold, ESLint will exit with an error status. Specifying a threshold of `-1` or omitting this option will prevent this behavior.
373+
Normally, if ESLint runs and finds no errors (only warnings), it exits with a success exit status. However, if `--max-warnings` is specified and the total warning count is greater than the specified threshold, ESLint exits with an error status. To prevent this behavior, omit this option or specify a threshold of `-1`.
370374

371375
Example:
372376

@@ -475,7 +479,7 @@ npx eslint --no-inline-config file.js
475479

476480
This option causes ESLint to report directive comments like `// eslint-disable-line` when no errors would have been reported on that line anyway. This can be useful to prevent future errors from unexpectedly being suppressed, by cleaning up old `eslint-disable` comments which are no longer applicable.
477481

478-
**Warning**: When using this option, it is possible that new errors will start being reported whenever ESLint or custom rules are upgraded. For example, suppose a rule has a bug that causes it to report a false positive, and an `eslint-disable` comment is added to suppress the incorrect report. If the bug is then fixed in a patch release of ESLint, the `eslint-disable` comment will become unused since ESLint is no longer generating an incorrect report. This will result in a new reported error for the unused directive if the `report-unused-disable-directives` option is used.
482+
**Warning**: When using this option, it is possible that new errors start being reported whenever ESLint or custom rules are upgraded. For example, suppose a rule has a bug that causes it to report a false positive, and an `eslint-disable` comment is added to suppress the incorrect report. If the bug is then fixed in a patch release of ESLint, the `eslint-disable` comment becomes unused since ESLint is no longer generating an incorrect report. This results in a new reported error for the unused directive if the `report-unused-disable-directives` option is used.
479483

480484
Example:
481485

@@ -495,15 +499,15 @@ Store the info about processed files in order to only operate on the changed one
495499

496500
#### `--cache-file`
497501

498-
Path to the cache file. If none specified `.eslintcache` will be used. The file will be created in the directory where the `eslint` command is executed. **Deprecated**: Use `--cache-location` instead.
502+
Path to the cache file. If no file is specified, `.eslintcache` is used. The file is created in the directory where the `eslint` command is executed. **Deprecated**: Use `--cache-location` instead.
499503

500504
#### `--cache-location`
501505

502-
Path to the cache location. Can be a file or a directory. If no location is specified, `.eslintcache` will be used. In that case, the file will be created in the directory where the `eslint` command is executed.
506+
Path to the cache location. Can be a file or a directory. If no location is specified, `.eslintcache` is used. In that case, the file is created in the directory where the `eslint` command is executed.
503507

504-
If a directory is specified, a cache file will be created inside the specified folder. The name of the file will be based on the hash of the current working directory (CWD). e.g.: `.cache_hashOfCWD`
508+
If a directory is specified, a cache file is created inside the specified folder. The name of the file is based on the hash of the current working directory (CWD). e.g.: `.cache_hashOfCWD`
505509

506-
**Important note:** If the directory for the cache does not exist make sure you add a trailing `/` on \*nix systems or `\` in windows. Otherwise the path will be assumed to be a file.
510+
**Important note:** If the directory for the cache does not exist make sure you add a trailing `/` on \*nix systems or `\` in windows. Otherwise the path is assumed to be a file.
507511

508512
Example:
509513

@@ -513,9 +517,9 @@ npx eslint "src/**/*.js" --cache --cache-location "/Users/user/.eslintcache/"
513517

514518
#### `--cache-strategy`
515519

516-
Strategy for the cache to use for detecting changed files. Can be either `metadata` or `content`. If no strategy is specified, `metadata` will be used.
520+
Strategy for the cache to use for detecting changed files. Can be either `metadata` or `content`. If no strategy is specified, `metadata` is used.
517521

518-
The `content` strategy can be useful in cases where the modification time of your files change even if their contents have not. For example, this can happen during git operations like git clone because git does not track file modification time.
522+
The `content` strategy can be useful in cases where the modification time of your files changes even if their contents have not. For example, this can happen during git operations like git clone because git does not track file modification time.
519523

520524
Example:
521525

@@ -527,17 +531,17 @@ npx eslint "src/**/*.js" --cache --cache-strategy content
527531

528532
#### `--init`
529533

530-
This option will run `npm init @eslint/config` to start config initialization wizard. It's designed to help new users quickly create .eslintrc file by answering a few questions, choosing a popular style guide.
534+
This option runs `npm init @eslint/config` to start the config initialization wizard. It's designed to help new users quickly create an `.eslintrc.js` file by answering a few questions and choosing a popular style guide.
531535

532-
The resulting configuration file will be created in the current directory.
536+
The resulting configuration file is created in the current directory.
533537

534538
#### `--env-info`
535539

536540
This option outputs information about the execution environment, including the version of Node, npm, and local and global installations of ESLint. The ESLint team may ask for this information to help solve bugs.
537541

538542
#### `--no-error-on-unmatched-pattern`
539543

540-
This option prevents errors when a quoted glob pattern or `--ext` is unmatched. This will not prevent errors when your shell can't match a glob.
544+
This option prevents errors when a quoted glob pattern or `--ext` is unmatched. This does not prevent errors when your shell can't match a glob.
541545

542546
#### `--exit-on-fatal-error`
543547

@@ -568,7 +572,7 @@ npx eslint --print-config file.js
568572

569573
## Ignoring files from linting
570574

571-
ESLint supports `.eslintignore` files to exclude files from the linting process when ESLint operates on a directory. Files given as individual CLI arguments will be exempt from exclusion. The `.eslintignore` file is a plain text file containing one pattern per line. It can be located in any of the target directory's ancestors; it will affect files in its containing directory as well as all sub-directories. Here's a simple example of a `.eslintignore` file:
575+
ESLint supports `.eslintignore` files to exclude files from the linting process when ESLint operates on a directory. Files given as individual CLI arguments are exempt from exclusion. The `.eslintignore` file is a plain text file containing one pattern per line. It can be located in any of the target directory's ancestors; it affects files in its containing directory as well as all sub-directories. Here's a simple example of a `.eslintignore` file:
572576

573577
```text
574578
temp.js
@@ -579,7 +583,7 @@ A more detailed breakdown of supported patterns and directories ESLint ignores b
579583

580584
## Exit codes
581585

582-
When linting files, ESLint will exit with one of the following exit codes:
586+
When linting files, ESLint exits with one of the following exit codes:
583587

584588
* `0`: Linting was successful and there are no linting errors. If the `--max-warnings` flag is set to `n`, the number of linting warnings is at most `n`.
585589
* `1`: Linting was successful and there is at least one linting error, or there are more linting warnings than allowed by the `--max-warnings` option.

0 commit comments

Comments
 (0)
Please sign in to comment.