You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/user-guide/command-line-interface.md
+64-60Lines changed: 64 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,30 +1,34 @@
1
1
# Command Line Interface
2
2
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.
4
4
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:
6
6
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
+
```
12
10
13
11
Such as:
14
12
15
-
eslint file1.js file2.js
16
-
17
-
or:
13
+
```shell
14
+
# Run on two files
15
+
npx eslint file1.js file2.js
18
16
19
-
eslint lib/**
17
+
# Run on multiples files
18
+
npx eslint lib/**
19
+
```
20
20
21
21
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:
22
22
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.
24
28
25
29
## Options
26
30
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`.
28
32
29
33
```text
30
34
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
92
96
93
97
Example:
94
98
95
-
eslint --ext .jsx --ext .js lib/
99
+
npx eslint --ext .jsx --ext .js lib/
96
100
97
-
eslint --ext .jsx,.js lib/
101
+
npx eslint --ext .jsx,.js lib/
98
102
99
103
### Basic configuration
100
104
@@ -104,15 +108,15 @@ Disables use of configuration from `.eslintrc.*` and `package.json` files.
104
108
105
109
Example:
106
110
107
-
eslint --no-eslintrc file.js
111
+
npx eslint --no-eslintrc file.js
108
112
109
113
#### `-c`, `--config`
110
114
111
115
This option allows you to specify an additional configuration file for ESLint (see [Configuring ESLint](configuring) for more).
112
116
113
117
Example:
114
118
115
-
eslint -c ~/my-eslint.json file.js
119
+
npx eslint -c ~/my-eslint.json file.js
116
120
117
121
This example uses the configuration file at `~/my-eslint.json`.
118
122
@@ -124,8 +128,8 @@ This option enables specific environments. Details about the global variables de
124
128
125
129
Examples:
126
130
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
129
133
130
134
#### `--ext`
131
135
@@ -135,26 +139,26 @@ By default, ESLint lints `*.js` files and the files that match the `overrides` e
135
139
Examples:
136
140
137
141
# Use only .ts extension
138
-
eslint . --ext .ts
142
+
npx eslint . --ext .ts
139
143
140
144
# Use both .js and .ts
141
-
eslint . --ext .js --ext .ts
145
+
npx eslint . --ext .js --ext .ts
142
146
143
147
# Also use both .js and .ts
144
-
eslint . --ext .js,.ts
148
+
npx eslint . --ext .js,.ts
145
149
146
150
**Note:**`--ext` is only used when the arguments are directories. If you use glob patterns or file names, then `--ext` is ignored.
147
151
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.
149
153
150
154
#### `--global`
151
155
152
156
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.
153
157
154
158
Examples:
155
159
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
158
162
159
163
#### `--parser`
160
164
@@ -166,8 +170,8 @@ This option allows you to specify parser options to be used by ESLint. Note that
166
170
167
171
Examples:
168
172
169
-
echo '3 ** 4' | eslint --stdin --parser-options=ecmaVersion:6 # will fail with a parsing error
@@ -209,11 +213,11 @@ This option allows you to specify another directory from which to load rules fil
209
213
210
214
Example:
211
215
212
-
eslint --rulesdir my-rules/ file.js
216
+
npx eslint --rulesdir my-rules/ file.js
213
217
214
218
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:
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.
219
223
@@ -235,7 +239,7 @@ This option has the same effect as `--fix` with one difference: the fixes are no
235
239
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:
Disables excluding of files from `.eslintignore`, `--ignore-path`, `--ignore-pattern`, and `ignorePatterns` property in config files.
276
280
277
281
Example:
278
282
279
-
eslint --no-ignore file.js
283
+
npx eslint --no-ignore file.js
280
284
281
285
#### `--ignore-pattern`
282
286
283
287
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.
@@ -294,15 +298,15 @@ This option tells ESLint to read and lint source code from STDIN instead of from
294
298
295
299
Example:
296
300
297
-
cat myfile.js | eslint --stdin
301
+
cat myfile.js | npx eslint --stdin
298
302
299
303
#### `--stdin-filename`
300
304
301
305
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.
@@ -476,7 +480,7 @@ This option causes ESLint to exit with exit code 2 if one or more fatal parsing
476
480
#### `--debug`
477
481
478
482
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)
480
484
481
485
#### `-h`, `--help`
482
486
@@ -492,7 +496,7 @@ This option outputs the configuration to be used for the file passed. When prese
0 commit comments