Skip to content

Commit c5cec0a

Browse files
committed
docs: add section about task concurrency to README.md
1 parent 5bf1f18 commit c5cec0a

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

README.md

+32-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Options:
118118
```
119119

120120
- **`--allow-empty`**: By default, when linter tasks undo all staged changes, lint-staged will exit with an error and abort the commit. Use this flag to allow creating empty git commits.
121-
- **`--concurrent [number|boolean]`**: Controls the concurrency of tasks being run by lint-staged. **NOTE**: This does NOT affect the concurrency of subtasks (they will always be run sequentially). Possible values are:
121+
- **`--concurrent [number|boolean]`**: Controls the [concurrency of tasks](#task-concurrency) being run by lint-staged. **NOTE**: This does NOT affect the concurrency of subtasks (they will always be run sequentially). Possible values are:
122122
- `false`: Run all tasks serially
123123
- `true` (default) : _Infinite_ concurrency. Runs as many tasks in parallel as possible.
124124
- `{number}`: Run the specified number of tasks in parallel, where `1` is equivalent to `false`.
@@ -181,6 +181,37 @@ So, considering you did `git add file1.ext file2.ext`, lint-staged will run the
181181

182182
`your-cmd file1.ext file2.ext`
183183

184+
### Task concurrency
185+
186+
By default _lint-staged_ will run configured tasks concurrently. This means that for every glob, all the commands will be started at the same time. With the following config, both `eslint` and `prettier` will run at the same time:
187+
188+
```json
189+
{
190+
"*.ts": "eslint",
191+
"*.md": "prettier --list-different"
192+
}
193+
```
194+
195+
This is typically not a problem since the globs do not overlap, and the commands do not make changes to the files, but only report possible errors (aborting the git commit). If you want to run multiple commands for the same set of files, you can use the array syntax to make sure commands are run in order. In the following example, `prettier` will run for both globs, and in addition `eslint` will run for `*.ts` files _after_ it. Both sets of commands (for each glob) are still started at the same time (but do not overlap).
196+
197+
```json
198+
{
199+
"*.ts": ["prettier --list-different", "eslint"],
200+
"*.md": "prettier --list-different"
201+
}
202+
```
203+
204+
Pay extra attention when the configured globs overlap, and tasks make edits to files. For example, in this configuration `prettier` and `eslint` might try to make changes to the same `*.ts` file at the same time, causing a _race condition_:
205+
206+
```json
207+
{
208+
"*": "prettier --write",
209+
"*.ts": "eslint --fix"
210+
}
211+
```
212+
213+
If necessary, you can limit the concurrency using `--concurrent <number>` or disable it entirely with `--concurrent false`.
214+
184215
## Filtering files
185216

186217
Linter commands work on a subset of all staged files, defined by a _glob pattern_. lint-staged uses [micromatch](https://github.com/micromatch/micromatch) for matching files with the following rules:

0 commit comments

Comments
 (0)