Skip to content

Commit f50f849

Browse files
authored
docs: Update CLI docs to prefer local install (#15513)
* docs: Update CLI docs to prefer local install * Fix missing references
1 parent 0469eb1 commit f50f849

File tree

1 file changed

+64
-60
lines changed

1 file changed

+64
-60
lines changed

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

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
# Command Line Interface
22

3-
To run ESLint on Node.js, you must have npm installed. If npm is not installed, follow the instructions here: <https://www.npmjs.com/>
3+
ESLint requires Node.js for installation. Follow the instructions in the [Getting Started Guide](https://eslint.org/docs/user-guide/getting-started) to install ESLint.
44

5-
Once npm is installed, run the following
5+
Most users use [`npx`](https://docs.npmjs.com/cli/v8/commands/npx) to run ESLint on the command line like this:
66

7-
npm i -g eslint
8-
9-
This installs the ESLint CLI from the npm repository. To run ESLint, use the following format:
10-
11-
eslint [options] [file|dir|glob]*
7+
```shell
8+
npx eslint [options] [file|dir|glob]*
9+
```
1210

1311
Such as:
1412

15-
eslint file1.js file2.js
16-
17-
or:
13+
```shell
14+
# Run on two files
15+
npx eslint file1.js file2.js
1816

19-
eslint lib/**
17+
# Run on multiples files
18+
npx eslint lib/**
19+
```
2020

2121
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:
2222

23-
eslint "lib/**"
23+
```shell
24+
npx eslint "lib/**"
25+
```
26+
27+
**Note:** You can also use alternative package managers such as [Yarn](https://yarnpkg.com/) or [pnpm](https://pnpm.io/) to run ESLint. Please refer to your package manager's documentation for the correct syntax.
2428

2529
## Options
2630

27-
The command line utility has several options. You can view the options by running `eslint -h`.
31+
The command line utility has several options. You can view the options by running `npx eslint -h`.
2832

2933
```text
3034
eslint [options] file.js [file.js] [dir]
@@ -92,9 +96,9 @@ Options that accept array values can be specified by repeating the option or wit
9296

9397
Example:
9498

95-
eslint --ext .jsx --ext .js lib/
99+
npx eslint --ext .jsx --ext .js lib/
96100

97-
eslint --ext .jsx,.js lib/
101+
npx eslint --ext .jsx,.js lib/
98102

99103
### Basic configuration
100104

@@ -104,15 +108,15 @@ Disables use of configuration from `.eslintrc.*` and `package.json` files.
104108

105109
Example:
106110

107-
eslint --no-eslintrc file.js
111+
npx eslint --no-eslintrc file.js
108112

109113
#### `-c`, `--config`
110114

111115
This option allows you to specify an additional configuration file for ESLint (see [Configuring ESLint](configuring) for more).
112116

113117
Example:
114118

115-
eslint -c ~/my-eslint.json file.js
119+
npx eslint -c ~/my-eslint.json file.js
116120

117121
This example uses the configuration file at `~/my-eslint.json`.
118122

@@ -124,8 +128,8 @@ This option enables specific environments. Details about the global variables de
124128

125129
Examples:
126130

127-
eslint --env browser,node file.js
128-
eslint --env browser --env node file.js
131+
npx eslint --env browser,node file.js
132+
npx eslint --env browser --env node file.js
129133

130134
#### `--ext`
131135

@@ -135,26 +139,26 @@ By default, ESLint lints `*.js` files and the files that match the `overrides` e
135139
Examples:
136140

137141
# Use only .ts extension
138-
eslint . --ext .ts
142+
npx eslint . --ext .ts
139143

140144
# Use both .js and .ts
141-
eslint . --ext .js --ext .ts
145+
npx eslint . --ext .js --ext .ts
142146

143147
# Also use both .js and .ts
144-
eslint . --ext .js,.ts
148+
npx eslint . --ext .js,.ts
145149

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

148-
For example, `eslint lib/* --ext .js` will match all files within the `lib/` directory, regardless of extension.
152+
For example, `npx eslint lib/* --ext .js` will match all files within the `lib/` directory, regardless of extension.
149153

150154
#### `--global`
151155

152156
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.
153157

154158
Examples:
155159

156-
eslint --global require,exports:true file.js
157-
eslint --global require --global exports:true
160+
npx eslint --global require,exports:true file.js
161+
npx eslint --global require --global exports:true
158162

159163
#### `--parser`
160164

@@ -166,8 +170,8 @@ This option allows you to specify parser options to be used by ESLint. Note that
166170

167171
Examples:
168172

169-
echo '3 ** 4' | eslint --stdin --parser-options=ecmaVersion:6 # will fail with a parsing error
170-
echo '3 ** 4' | eslint --stdin --parser-options=ecmaVersion:7 # succeeds, yay!
173+
echo '3 ** 4' | npx eslint --stdin --parser-options=ecmaVersion:6 # will fail with a parsing error
174+
echo '3 ** 4' | npx eslint --stdin --parser-options=ecmaVersion:7 # succeeds, yay!
171175

172176
#### `--resolve-plugins-relative-to`
173177

@@ -186,8 +190,8 @@ Before using the plugin, you have to install it using npm.
186190

187191
Examples:
188192

189-
eslint --plugin jquery file.js
190-
eslint --plugin eslint-plugin-mocha file.js
193+
npx eslint --plugin jquery file.js
194+
npx eslint --plugin eslint-plugin-mocha file.js
191195

192196
#### `--rule`
193197

@@ -197,9 +201,9 @@ If the rule is defined within a plugin, you have to prefix the rule ID with the
197201

198202
Examples:
199203

200-
eslint --rule 'quotes: [error, double]'
201-
eslint --rule 'guard-for-in: error' --rule 'brace-style: [error, 1tbs]'
202-
eslint --rule 'jquery/dollar-sign: error'
204+
npx eslint --rule 'quotes: [error, double]'
205+
npx eslint --rule 'guard-for-in: error' --rule 'brace-style: [error, 1tbs]'
206+
npx eslint --rule 'jquery/dollar-sign: error'
203207

204208
#### `--rulesdir`
205209

@@ -209,11 +213,11 @@ This option allows you to specify another directory from which to load rules fil
209213

210214
Example:
211215

212-
eslint --rulesdir my-rules/ file.js
216+
npx eslint --rulesdir my-rules/ file.js
213217

214218
The rules in your custom rules directory must follow the same format as bundled rules to work properly. You can also specify multiple locations for custom rules by including multiple `--rulesdir` options:
215219

216-
eslint --rulesdir my-rules/ --rulesdir my-other-rules/ file.js
220+
npx eslint --rulesdir my-rules/ --rulesdir my-other-rules/ file.js
217221

218222
Note that, as with core rules and plugin rules, you still need to enable the rules in configuration or via the `--rule` CLI option in order to actually run those rules during linting. Specifying a rules directory with `--rulesdir` does not automatically enable the rules within that directory.
219223

@@ -235,7 +239,7 @@ This option has the same effect as `--fix` with one difference: the fixes are no
235239
Because the default formatter does not output the fixed code, you'll have to use another one (e.g. `json`) to get the fixes. Here's an example of this pattern:
236240

237241
```shell
238-
getSomeText | eslint --stdin --fix-dry-run --format=json
242+
getSomeText | npx eslint --stdin --fix-dry-run --format=json
239243
```
240244

241245
This flag can be useful for integrations (e.g. editor plugins) which need to autofix text from the command line without saving it to the filesystem.
@@ -252,9 +256,9 @@ This option allows you to specify the type of fixes to apply when using either `
252256
You can specify one or more fix type on the command line. Here are some examples:
253257

254258
```shell
255-
eslint --fix --fix-type suggestion .
256-
eslint --fix --fix-type suggestion --fix-type problem .
257-
eslint --fix --fix-type suggestion,layout .
259+
npx eslint --fix --fix-type suggestion .
260+
npx eslint --fix --fix-type suggestion --fix-type problem .
261+
npx eslint --fix --fix-type suggestion,layout .
258262
```
259263

260264
This option is helpful if you are using another program to format your code but you would still like ESLint to apply other types of fixes.
@@ -267,24 +271,24 @@ This option allows you to specify the file to use as your `.eslintignore`. By de
267271

268272
Example:
269273

270-
eslint --ignore-path tmp/.eslintignore file.js
271-
eslint --ignore-path .gitignore file.js
274+
npx eslint --ignore-path tmp/.eslintignore file.js
275+
npx eslint --ignore-path .gitignore file.js
272276

273277
#### `--no-ignore`
274278

275279
Disables excluding of files from `.eslintignore`, `--ignore-path`, `--ignore-pattern`, and `ignorePatterns` property in config files.
276280

277281
Example:
278282

279-
eslint --no-ignore file.js
283+
npx eslint --no-ignore file.js
280284

281285
#### `--ignore-pattern`
282286

283287
This option allows you to specify patterns of files to ignore (in addition to those in `.eslintignore`). You can repeat the option to provide multiple patterns. The supported syntax is the same as for `.eslintignore` [files](configuring/ignoring-code.md#the-eslintignore-file), which use the same patterns as the `.gitignore` [specification](https://git-scm.com/docs/gitignore). You should quote your patterns in order to avoid shell interpretation of glob patterns.
284288

285289
Example:
286290

287-
eslint --ignore-pattern '/lib/' --ignore-pattern '/src/vendor/*' .
291+
npx eslint --ignore-pattern '/lib/' --ignore-pattern '/src/vendor/*' .
288292

289293
### Using stdin
290294

@@ -294,15 +298,15 @@ This option tells ESLint to read and lint source code from STDIN instead of from
294298

295299
Example:
296300

297-
cat myfile.js | eslint --stdin
301+
cat myfile.js | npx eslint --stdin
298302

299303
#### `--stdin-filename`
300304

301305
This option allows you to specify a filename to process STDIN as. This is useful when processing files from STDIN and you have rules which depend on the filename.
302306

303307
Example
304308

305-
cat myfile.js | eslint --stdin --stdin-filename=myfile.js
309+
cat myfile.js | npx eslint --stdin --stdin-filename=myfile.js
306310

307311
### Handling warnings
308312

@@ -312,7 +316,7 @@ This option allows you to disable reporting on warnings. If you enable this opti
312316

313317
Example:
314318

315-
eslint --quiet file.js
319+
npx eslint --quiet file.js
316320

317321
#### `--max-warnings`
318322

@@ -322,7 +326,7 @@ Normally, if ESLint runs and finds no errors (only warnings), it will exit with
322326

323327
Example:
324328

325-
eslint --max-warnings 10 file.js
329+
npx eslint --max-warnings 10 file.js
326330

327331
### Output
328332

@@ -332,7 +336,7 @@ Enable report to be written to a file.
332336

333337
Example:
334338

335-
eslint -o ./test/test.html
339+
npx eslint -o ./test/test.html
336340

337341
When specified, the given format is output into the provided file name.
338342

@@ -353,28 +357,28 @@ This option specifies the output format for the console. Possible formats are:
353357

354358
Example:
355359

356-
eslint -f compact file.js
360+
npx eslint -f compact file.js
357361

358362
You can also use a custom formatter from the command line by specifying a path to the custom formatter file.
359363

360364
Example:
361365

362-
eslint -f ./customformat.js file.js
366+
npx eslint -f ./customformat.js file.js
363367

364368
An npm-installed formatter is resolved with or without `eslint-formatter-` prefix.
365369

366370
Example:
367371

368372
npm install eslint-formatter-pretty
369373

370-
eslint -f pretty file.js
374+
npx eslint -f pretty file.js
371375

372376
// equivalent:
373-
eslint -f eslint-formatter-pretty file.js
377+
npx eslint -f eslint-formatter-pretty file.js
374378

375379
When specified, the given format is output to the console. If you'd like to save that output into a file, you can do so on the command line like so:
376380

377-
eslint -f compact file.js > results.txt
381+
npx eslint -f compact file.js > results.txt
378382

379383
This saves the output into the `results.txt` file.
380384

@@ -384,8 +388,8 @@ This option forces the enabling/disabling of colorized output. You can use this
384388

385389
Examples:
386390

387-
eslint --color file.js | cat
388-
eslint --no-color file.js
391+
npx eslint --color file.js | cat
392+
npx eslint --no-color file.js
389393

390394
### Inline configuration comments
391395

@@ -405,7 +409,7 @@ config without files modifying it. All inline config comments are ignored, e.g.:
405409

406410
Example:
407411

408-
eslint --no-inline-config file.js
412+
npx eslint --no-inline-config file.js
409413

410414
#### `--report-unused-disable-directives`
411415

@@ -415,7 +419,7 @@ This option causes ESLint to report directive comments like `// eslint-disable-l
415419

416420
Example:
417421

418-
eslint --report-unused-disable-directives file.js
422+
npx eslint --report-unused-disable-directives file.js
419423

420424
### Caching
421425

@@ -441,7 +445,7 @@ If a directory is specified, a cache file will be created inside the specified f
441445

442446
Example:
443447

444-
eslint "src/**/*.js" --cache --cache-location "/Users/user/.eslintcache/"
448+
npx eslint "src/**/*.js" --cache --cache-location "/Users/user/.eslintcache/"
445449

446450
#### `--cache-strategy`
447451

@@ -451,7 +455,7 @@ The `content` strategy can be useful in cases where the modification time of you
451455

452456
Example:
453457

454-
eslint "src/**/*.js" --cache --cache-strategy content
458+
npx eslint "src/**/*.js" --cache --cache-strategy content
455459

456460
### Miscellaneous
457461

@@ -476,7 +480,7 @@ This option causes ESLint to exit with exit code 2 if one or more fatal parsing
476480
#### `--debug`
477481

478482
This option outputs debugging information to the console. This information is useful when you're seeing a problem and having a hard time pinpointing it. The ESLint team may ask for this debugging information to help solve bugs.
479-
Add this flag to an ESLint command line invocation in order to get extra debug information as the command is run (e.g. `eslint --debug test.js` and `eslint test.js --debug` are equivalent)
483+
Add this flag to an ESLint command line invocation in order to get extra debug information as the command is run (e.g. `npx eslint --debug test.js` and `npx eslint test.js --debug` are equivalent)
480484

481485
#### `-h`, `--help`
482486

@@ -492,7 +496,7 @@ This option outputs the configuration to be used for the file passed. When prese
492496

493497
Example:
494498

495-
eslint --print-config file.js
499+
npx eslint --print-config file.js
496500

497501
## Ignoring files from linting
498502

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy