Skip to content

Commit 0bb777a

Browse files
feat: multithread linting (#19794)
* feat: multithread linting * fix build * clean up CLI code * add more tests * add tests and print debug timing info * more unit tests for lint results * don't use Retrier in worker threads * improve flaky test * pre-load config arrays * use shared environment variables * update warning count tests * improve error handling in `fromOptionModule` * add more tests for option modules * require URL objects in `fromOptionModule` * stylistic changes * map worker count 1 to 0 * add poor concurrency warning * improve documentation * Helpers → Internal Helpers * remove `exports` assignment * define "net linting ratio" * "option module" → "options module" * add comment * string `configType` argument in `translateOptions` * skip caching ignored files * update import Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * replace `URL` type and check argument prototype in `fromOptionsModule` --------- Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent bf26229 commit 0bb777a

File tree

22 files changed

+2764
-747
lines changed

22 files changed

+2764
-747
lines changed

docs/src/integrate/nodejs-api.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ The `ESLint` constructor takes an `options` object. If you omit the `options` ob
171171

172172
##### Other Options
173173

174+
- `options.concurrency` (`number | "auto" | "off"`)<br>
175+
Default is `"off"`. By default, ESLint lints all files in the calling thread. If this option specifies an integer, ESLint will use up to that number of worker threads to lint files concurrently. `"auto"` chooses a setting automatically. When this option is specified all other options must be [cloneable](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
174176
- `options.flags` (`string[]`)<br>
175177
Default is `[]`. The feature flags to enable for this instance.
176178

@@ -340,6 +342,50 @@ The default configuration that ESLint uses internally. This is provided for tool
340342

341343
This is a static property.
342344

345+
### ◆ ESLint.fromOptionsModule(optionsURL)
346+
347+
```js
348+
const eslint = await ESLint.fromOptionsModule(optionsURL);
349+
```
350+
351+
This method creates an instance of the `ESLint` class with options loaded from a module, for example:
352+
353+
```js
354+
// eslint-options.js
355+
356+
import config from "./my-eslint-config.js";
357+
358+
export default {
359+
concurrency: "auto",
360+
overrideConfig: config,
361+
overrideConfigFile: true,
362+
stats: true,
363+
};
364+
```
365+
366+
```js
367+
// main.js
368+
369+
...
370+
const optionsURL = new URL("./eslint-options.js", import.meta.url);
371+
const eslint = await ESLint.fromOptionsModule(optionsURL);
372+
...
373+
```
374+
375+
The `concurrency` option requires all other options to be cloneable so that they can be passed to worker threads, but this restriction does not apply when options are loaded from a module, because in that case worker threads are passed the module URL instead of the options object.
376+
377+
This is a static method.
378+
379+
#### Parameters
380+
381+
- `optionsURL` (`URL`)<br>
382+
The URL of the options module. This can be any valid URL, like a file URL or a data URL.
383+
384+
#### Return Value
385+
386+
- (`Promise<ESLint>`)<br>
387+
A new instance of the `ESLint` class.
388+
343389
### ◆ ESLint.outputFixes(results)
344390
345391
```js

docs/src/use/command-line-interface.md

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -88,76 +88,74 @@ You can view all the CLI options by running `npx eslint -h`.
8888
eslint [options] file.js [file.js] [dir]
8989
9090
Basic configuration:
91-
--no-config-lookup Disable look up for eslint.config.js
92-
-c, --config path::String Use this configuration instead of eslint.config.js, eslint.config.mjs, or
93-
eslint.config.cjs
94-
--inspect-config Open the config inspector with the current configuration
95-
--ext [String] Specify additional file extensions to lint
96-
--global [String] Define global variables
97-
--parser String Specify the parser to be used
98-
--parser-options Object Specify parser options
91+
--no-config-lookup Disable look up for eslint.config.js
92+
-c, --config path::String Use this configuration instead of eslint.config.js, eslint.config.mjs, or eslint.config.cjs
93+
--inspect-config Open the config inspector with the current configuration
94+
--ext [String] Specify additional file extensions to lint
95+
--global [String] Define global variables
96+
--parser String Specify the parser to be used
97+
--parser-options Object Specify parser options
9998
10099
Specify Rules and Plugins:
101-
--plugin [String] Specify plugins
102-
--rule Object Specify rules
100+
--plugin [String] Specify plugins
101+
--rule Object Specify rules
103102
104103
Fix Problems:
105-
--fix Automatically fix problems
106-
--fix-dry-run Automatically fix problems without saving the changes to the file system
107-
--fix-type Array Specify the types of fixes to apply (directive, problem, suggestion, layout)
104+
--fix Automatically fix problems
105+
--fix-dry-run Automatically fix problems without saving the changes to the file system
106+
--fix-type Array Specify the types of fixes to apply (directive, problem, suggestion, layout)
108107
109108
Ignore Files:
110-
--no-ignore Disable use of ignore files and patterns
111-
--ignore-pattern [String] Patterns of files to ignore
109+
--no-ignore Disable use of ignore files and patterns
110+
--ignore-pattern [String] Patterns of files to ignore
112111
113112
Use stdin:
114-
--stdin Lint code provided on <STDIN> - default: false
115-
--stdin-filename String Specify filename to process STDIN as
113+
--stdin Lint code provided on <STDIN> - default: false
114+
--stdin-filename String Specify filename to process STDIN as
116115
117116
Handle Warnings:
118-
--quiet Report errors only - default: false
119-
--max-warnings Int Number of warnings to trigger nonzero exit code - default: -1
117+
--quiet Report errors only - default: false
118+
--max-warnings Int Number of warnings to trigger nonzero exit code - default: -1
120119
121120
Output:
122-
-o, --output-file path::String Specify file to write report to
123-
-f, --format String Use a specific output format - default: stylish
124-
--color, --no-color Force enabling/disabling of color
121+
-o, --output-file path::String Specify file to write report to
122+
-f, --format String Use a specific output format - default: stylish
123+
--color, --no-color Force enabling/disabling of color
125124
126125
Inline configuration comments:
127-
--no-inline-config Prevent comments from changing config or rules
126+
--no-inline-config Prevent comments from changing config or rules
128127
--report-unused-disable-directives Adds reported errors for unused eslint-disable and eslint-enable directives
129-
--report-unused-disable-directives-severity String Chooses severity level for reporting unused eslint-disable and
130-
eslint-enable directives - either: off, warn, error, 0, 1, or 2
128+
--report-unused-disable-directives-severity String Chooses severity level for reporting unused eslint-disable and eslint-enable directives - either: off, warn, error, 0, 1, or 2
131129
--report-unused-inline-configs String Adds reported errors for unused eslint inline config comments - either: off, warn, error, 0, 1, or 2
132130
133131
Caching:
134-
--cache Only check changed files - default: false
135-
--cache-file path::String Path to the cache file. Deprecated: use --cache-location - default: .eslintcache
136-
--cache-location path::String Path to the cache file or directory
137-
--cache-strategy String Strategy to use for detecting changed files in the cache - either: metadata or
138-
content - default: metadata
132+
--cache Only check changed files - default: false
133+
--cache-file path::String Path to the cache file. Deprecated: use --cache-location - default: .eslintcache
134+
--cache-location path::String Path to the cache file or directory
135+
--cache-strategy String Strategy to use for detecting changed files in the cache - either: metadata or content - default: metadata
139136
140137
Suppressing Violations:
141-
--suppress-all Suppress all violations - default: false
142-
--suppress-rule [String] Suppress specific rules
138+
--suppress-all Suppress all violations - default: false
139+
--suppress-rule [String] Suppress specific rules
143140
--suppressions-location path::String Specify the location of the suppressions file
144-
--prune-suppressions Prune unused suppressions - default: false
145-
--pass-on-unpruned-suppressions Ignore unused suppressions - default: false
141+
--prune-suppressions Prune unused suppressions - default: false
142+
--pass-on-unpruned-suppressions Ignore unused suppressions - default: false
146143
147144
Miscellaneous:
148-
--init Run config initialization wizard - default: false
149-
--env-info Output execution environment information - default: false
145+
--init Run config initialization wizard - default: false
146+
--env-info Output execution environment information - default: false
150147
--no-error-on-unmatched-pattern Prevent errors when pattern is unmatched
151-
--exit-on-fatal-error Exit with exit code 2 in case of fatal error - default: false
152-
--no-warn-ignored Suppress warnings when the file list includes ignored files
153-
--pass-on-no-patterns Exit with exit code 0 in case no file patterns are passed
154-
--debug Output debugging information
155-
-h, --help Show help
156-
-v, --version Output the version number
157-
--print-config path::String Print the configuration for the given file
158-
--stats Add statistics to the lint report - default: false
159-
--flag [String] Enable a feature flag
160-
--mcp Start the ESLint MCP server
148+
--exit-on-fatal-error Exit with exit code 2 in case of fatal error - default: false
149+
--no-warn-ignored Suppress warnings when the file list includes ignored files
150+
--pass-on-no-patterns Exit with exit code 0 in case no file patterns are passed
151+
--debug Output debugging information
152+
-h, --help Show help
153+
-v, --version Output the version number
154+
--print-config path::String Print the configuration for the given file
155+
--stats Add statistics to the lint report - default: false
156+
--flag [String] Enable a feature flag
157+
--mcp Start the ESLint MCP server
158+
--concurrency Int|String Number of linting threads, auto to choose automatically, off for no multithreading - default: off
161159
```
162160

163161
### Basic Configuration
@@ -1100,6 +1098,23 @@ This option starts the ESLint MCP server for use with AI agents.
11001098
args: ["--mcp"]
11011099
}) }}
11021100

1101+
#### `--concurrency`
1102+
1103+
This option controls the number of worker threads used to lint files.
1104+
1105+
- **Argument Type**: Int|String. A positive integer, `auto` or `off`.
1106+
- **Multiple Arguments**: No
1107+
- **Default Value**: `off`
1108+
1109+
The value `off` causes all files to be linted in the main thread. The value `auto` attempts to determine the best setting automatically.
1110+
1111+
##### `--concurrency` example
1112+
1113+
{{ npx_tabs ({
1114+
package: "eslint",
1115+
args: ["--concurrency", "auto"]
1116+
}) }}
1117+
11031118
## Exit Codes
11041119

11051120
When linting files, ESLint exits with one of the following exit codes:

0 commit comments

Comments
 (0)