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
This aims to prevent some of the common pitfalls/points of confusion
when configuring `CLIEngine`, such as:
* it not being clear that `baseConfig` supports all of the options
defined in the `.eslintrc.*` schema, and so can be used for options
that are not supported as top-level `CLIEngine` arguments such as
`extends` and `settings.
* some of the CLIEngine options being named the same or almost the
same as their `.eslintrc.*` equivalents, but being a different
data type.
* it not being clear that CLIEngine silently ignores invalid options
(which will hopefully be fixed at some point by eslint#10272).
Refs:
eslint#4402eslint#5179eslint#6605eslint#7247eslint#7967eslint#10272webpack-contrib/eslint-loader#173webpack-contrib/eslint-loader#252neutrinojs/neutrino#1181
Copy file name to clipboardexpand all lines: docs/developer-guide/nodejs-api.md
+19-6
Original file line number
Diff line number
Diff line change
@@ -339,17 +339,17 @@ var CLIEngine = require("eslint").CLIEngine;
339
339
The `CLIEngine` is a constructor, and you can create a new instance by passing in the options you want to use. The available options are:
340
340
341
341
*`allowInlineConfig` - Set to `false` to disable the use of configuration comments (such as `/*eslint-disable*/`). Corresponds to `--no-inline-config`.
342
-
*`baseConfig` - Can optionally be set to a config object. This will used as a default config, and will be merged with any configuration defined in `.eslintrc.*` files, with the `.eslintrc.*` files having precedence.
342
+
*`baseConfig` - Can optionally be set to a config object that has the same schema as `.eslintrc.*`. This will used as a default config, and will be merged with any configuration defined in `.eslintrc.*` files, with the `.eslintrc.*` files having precedence.
343
343
*`cache` - Operate only on changed files (default: `false`). Corresponds to `--cache`.
344
344
*`cacheFile` - Name of the file where the cache will be stored (default: `.eslintcache`). Corresponds to `--cache-file`. Deprecated: use `cacheLocation` instead.
345
345
*`cacheLocation` - Name of the file or directory where the cache will be stored (default: `.eslintcache`). Corresponds to `--cache-location`.
346
346
*`configFile` - The configuration file to use (default: null). If `useEslintrc` is true or not specified, this configuration will be merged with any configuration defined in `.eslintrc.*` files, with options in this configuration having precedence. Corresponds to `-c`.
347
347
*`cwd` - Path to a directory that should be considered as the current working directory.
348
-
*`envs` - An array of environments to load (default: empty array). Corresponds to `--env`.
349
-
*`extensions` - An array of filename extensions that should be checked for code. The default is an array containing just `".js"`. Corresponds to `--ext`. It is only used in conjunction with directories, not with filenames or glob patterns.
348
+
*`envs` - An array of environments to load (default: empty array). Corresponds to `--env`. Note: This differs from `.eslintrc.*` / `baseConfig`, where instead the option is called `env` and is an object.
349
+
*`extensions` - An array of filename extensions that should be checked for code. The default is an array containing just `".js"`. Corresponds to `--ext`. It is only used in conjunction with directories, not with filenames, glob patterns or when using `executeOnText()`.
350
350
*`fix` - A boolean or a function (default: `false`). If a function, it will be passed each linting message and should return a boolean indicating whether the fix should be included with the output report (errors and warnings will not be listed if fixed). Files on disk are never changed regardless of the value of `fix`. To persist changes to disk, call [`outputFixes()`](#cliengineoutputfixes).
351
351
*`fixTypes` - An array of rule types for which fixes should be applied (default: `null`). This array acts like a filter, only allowing rules of the given types to apply fixes. Possible array values are `"problem"`, `"suggestion"`, and `"layout"`.
352
-
*`globals` - An array of global variables to declare (default: empty array). Corresponds to `--global`.
352
+
*`globals` - An array of global variables to declare (default: empty array). Corresponds to `--global`, and similarly supports passing `'name:true'` to denote a writeable global. Note: This differs from `.eslintrc.*` / `baseConfig`, where `globals` is an object.
353
353
*`ignore` - False disables use of `.eslintignore`, `ignorePath` and `ignorePattern` (default: true). Corresponds to `--no-ignore`.
354
354
*`ignorePath` - The ignore file to use instead of `.eslintignore` (default: null). Corresponds to `--ignore-path`.
355
355
*`ignorePattern` - Glob patterns for paths to ignore. String or array of strings.
@@ -362,14 +362,21 @@ The `CLIEngine` is a constructor, and you can create a new instance by passing i
362
362
*`useEslintrc` - Set to false to disable use of `.eslintrc` files (default: true). Corresponds to `--no-eslintrc`.
363
363
*`globInputPaths` - Set to false to skip glob resolution of input file paths to lint (default: true). If false, each input file paths is assumed to be a non-glob path to an existing file.
364
364
365
-
365
+
To programmatically set `.eslintrc.*` options not supported above (such as `extends`,
366
+
`overrides` and `settings`), define them in a config object passed to `baseConfig` instead.
366
367
367
368
For example:
368
369
369
370
```js
370
371
var CLIEngine =require("eslint").CLIEngine;
371
372
372
373
var cli =newCLIEngine({
374
+
baseConfig: {
375
+
extends: ["eslint-config-shared"],
376
+
settings: {
377
+
sharedData:"Hello"
378
+
}
379
+
},
373
380
envs: ["browser", "mocha"],
374
381
useEslintrc:false,
375
382
rules: {
@@ -378,7 +385,13 @@ var cli = new CLIEngine({
378
385
});
379
386
```
380
387
381
-
In this code, a new `CLIEngine` instance is created that sets two environments, `"browser"` and `"mocha"`, disables loading of `.eslintrc` and `package.json` files, and enables the `semi` rule as an error. You can then call methods on `cli` and these options will be used to perform the correct action.
388
+
In this example, a new `CLIEngine` instance is created that extends a configuration called
389
+
`"eslint-config-shared"`, a setting named `"sharedData"` and two environments (`"browser"`
390
+
and `"mocha"`) are defined, loading of `.eslintrc` and `package.json` files are disabled,
391
+
and the `semi` rule enabled as an error. You can then call methods on `cli` and these options
392
+
will be used to perform the correct action.
393
+
394
+
Note: Currently `CLIEngine` does not validate options passed to it, but may start doing so in the future.
0 commit comments