lint-staged 9.4.2 → 9.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,25 +4,25 @@ Run linters against staged git files and don't let :poop: slip into your code ba
4
4
 
5
5
  ---
6
6
 
7
- ## 🚧 Help test `lint-staged@next`!
7
+ ## 🚧 Help test `lint-staged@beta`!
8
8
 
9
- Version 10 of `lint-staged` is coming with changes that help it run faster on large git repositories and prevent loss of data during errors. Please help test the `next` version and report any inconsistencies in our [GitHub Issues](https://github.com/okonet/lint-staged/issues):
9
+ Version 10 of `lint-staged` is coming with changes that help it run faster on large git repositories and prevent loss of data during errors. Please help test the `beta` version and report any inconsistencies in our [GitHub Issues](https://github.com/okonet/lint-staged/issues):
10
10
 
11
11
  **Using npm**
12
12
 
13
- npm install --save-dev lint-staged@next
13
+ npm install --save-dev lint-staged@beta
14
14
 
15
15
  **Using yarn**
16
16
 
17
- yarn add -D lint-staged@next
17
+ yarn add -D lint-staged@beta
18
18
 
19
19
  ### Notable changes
20
20
 
21
21
  - A git stash is created before running any tasks, so in case of errors any lost changes can be restored easily (and automatically unless lint-staged itself crashes)
22
- - Instead of write-tree/read-tree, `lint-staged@next` uses git stashes to hide unstaged changes while running tasks against staged files
22
+ - Instead of write-tree/read-tree, `lint-staged@beta` uses git stashes to hide unstaged changes while running tasks against staged files
23
23
  - This results in a performance increase of up to 45x on very large repositories
24
- - The behaviour of committing modifications during tasks (eg. `prettier --write && git add`) is different. The current version creates a diff of these modifications, and applies it against the original state, silently ignoring any errors. The `next` version leaves modifications of staged files as-is, and then restores all hidden unstaged changes as patch. If applying the patch fails due to a merge conflict (because tasks have modified the same lines), a 3-way merge will be retried. If this also fails, the entire commit will fail and the original state will be restored.
25
- - **TL;DR** the `next` version will never skip committing any changes by tasks (due to a merge conflict), but might fail in very complex situations where unstaged changes cannot be restored cleanly. If this happens to you, we are very interested in a repeatable test scenario.
24
+ - The behaviour of committing modifications during tasks (eg. `prettier --write && git add`) is different. The current version creates a diff of these modifications, and applies it against the original state, silently ignoring any errors. The `beta` version leaves modifications of staged files as-is, and then restores all hidden unstaged changes as patch. If applying the patch fails due to a merge conflict (because tasks have modified the same lines), a 3-way merge will be retried. If this also fails, the entire commit will fail and the original state will be restored.
25
+ - **TL;DR** the `beta` version will never skip committing any changes by tasks (due to a merge conflict), but might fail in very complex situations where unstaged changes cannot be restored cleanly. If this happens to you, we are very interested in a repeatable test scenario.
26
26
 
27
27
  ---
28
28
 
@@ -36,10 +36,10 @@ This project contains a script that will run arbitrary shell tasks with a list o
36
36
 
37
37
  ## Related blogs posts and talks
38
38
 
39
- * [Make Linting Great Again](https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8#.8qepn2b5l)
40
- * [Running Jest Tests Before Each Git Commit](https://benmccormick.org/2017/02/26/running-jest-tests-before-each-git-commit/)
41
- * [AgentConf: Make Linting Great Again](https://www.youtube.com/watch?v=-mhY7e-EsC4)
42
- * [SurviveJS Interview](https://survivejs.com/blog/lint-staged-interview/)
39
+ - [Make Linting Great Again](https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8#.8qepn2b5l)
40
+ - [Running Jest Tests Before Each Git Commit](https://benmccormick.org/2017/02/26/running-jest-tests-before-each-git-commit/)
41
+ - [AgentConf: Make Linting Great Again](https://www.youtube.com/watch?v=-mhY7e-EsC4)
42
+ - [SurviveJS Interview](https://survivejs.com/blog/lint-staged-interview/)
43
43
 
44
44
  > If you've written one, please submit a PR with the link to it!
45
45
 
@@ -70,31 +70,36 @@ $ npx lint-staged --help
70
70
  Usage: lint-staged [options]
71
71
 
72
72
  Options:
73
- -V, --version output the version number
74
- -c, --config [path] Path to configuration file
75
- -r, --relative Pass relative filepaths to tasks
76
- -x, --shell Skip parsing of tasks for better shell support
77
- -q, --quiet Disable lint-staged’s own console output
78
- -d, --debug Enable debug mode
79
- -h, --help output usage information
73
+ -V, --version output the version number
74
+ -c, --config [path] Path to configuration file
75
+ -r, --relative Pass relative filepaths to tasks
76
+ -x, --shell Skip parsing of tasks for better shell support
77
+ -q, --quiet Disable lint-staged’s own console output
78
+ -d, --debug Enable debug mode
79
+ -p, --concurrent [parallel tasks] The number of tasks to run concurrently, or false to run tasks sequentially
80
+ -h, --help output usage information
80
81
  ```
81
82
 
82
- * **`--config [path]`**: This can be used to manually specify the `lint-staged` config file location. However, if the specified file cannot be found, it will error out instead of performing the usual search. You may pass a npm package name for configuration also.
83
- * **`--relative`**: By default filepaths will be passed to the linter tasks as *absolute*. This flag makes them relative to `process.cwd()` (where `lint-staged` runs).
84
- * **`--shell`**: By default linter commands will be parsed for speed and security. This has the side-effect that regular shell scripts might not work as expected. You can skip parsing of commands with this option.
85
- * **`--quiet`**: By default `lint-staged` will print progress status to console while running linters. Use this flag to supress all output, except for linter scripts.
86
- * **`--debug`**: Enabling the debug mode does the following:
87
- * `lint-staged` uses the [debug](https://github.com/visionmedia/debug) module internally to log information about staged files, commands being executed, location of binaries, etc. Debug logs, which are automatically enabled by passing the flag, can also be enabled by setting the environment variable `$DEBUG` to `lint-staged*`.
88
- * Use the [`verbose` renderer](https://github.com/SamVerschueren/listr-verbose-renderer) for `listr`.
83
+ - **`--config [path]`**: This can be used to manually specify the `lint-staged` config file location. However, if the specified file cannot be found, it will error out instead of performing the usual search. You may pass a npm package name for configuration also.
84
+ - **`--relative`**: By default filepaths will be passed to the linter tasks as _absolute_. This flag makes them relative to `process.cwd()` (where `lint-staged` runs).
85
+ - **`--shell`**: By default linter commands will be parsed for speed and security. This has the side-effect that regular shell scripts might not work as expected. You can skip parsing of commands with this option.
86
+ - **`--quiet`**: By default `lint-staged` will print progress status to console while running linters. Use this flag to supress all output, except for linter scripts.
87
+ - **`--debug`**: Enabling the debug mode does the following:
88
+ - `lint-staged` uses the [debug](https://github.com/visionmedia/debug) module internally to log information about staged files, commands being executed, location of binaries, etc. Debug logs, which are automatically enabled by passing the flag, can also be enabled by setting the environment variable `$DEBUG` to `lint-staged*`.
89
+ - Use the [`verbose` renderer](https://github.com/SamVerschueren/listr-verbose-renderer) for `listr`.
90
+ - **`--concurrent [number | (true/false)]`**: 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:
91
+ - `false`: Run all tasks serially
92
+ - `true` (default) : _Infinite_ concurrency. Runs as many tasks in parallel as possible.
93
+ - `{number}`: Run the specified number of tasks in parallel, where `1` is equivalent to `false`.
89
94
 
90
95
  ## Configuration
91
96
 
92
97
  Starting with v3.1 you can now use different ways of configuring it:
93
98
 
94
- * `lint-staged` object in your `package.json`
95
- * `.lintstagedrc` file in JSON or YML format
96
- * `lint-staged.config.js` file in JS format
97
- * Pass a configuration file using the `--config` or `-c` flag
99
+ - `lint-staged` object in your `package.json`
100
+ - `.lintstagedrc` file in JSON or YML format
101
+ - `lint-staged.config.js` file in JS format
102
+ - Pass a configuration file using the `--config` or `-c` flag
98
103
 
99
104
  See [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for more details on what formats are supported.
100
105
 
@@ -128,19 +133,19 @@ So, considering you did `git add file1.ext file2.ext`, lint-staged will run the
128
133
 
129
134
  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:
130
135
 
131
- * If the glob pattern contains no slashes (`/`), micromatch's `matchBase` option will enabled, so globs match a file's basename regardless of directory:
132
- * **`"*.js"`** will match all JS files, like `/test.js` and `/foo/bar/test.js`
133
- * **`"!(*test).js"`**. will match all JS files, except those ending in `test.js`, so `foo.js` but not `foo.test.js`
134
- * If the glob pattern does contain a slash (`/`), it will match for paths as well:
135
- * **`"/*.js"`** will match all JS files in the git repo root, so `/test.js` but not `/foo/bar/test.js`
136
- * **`"foo/**/*.js"`** will match all JS files inside the`/foo`directory, so`/foo/bar/test.js`but not`/test.js`
136
+ - If the glob pattern contains no slashes (`/`), micromatch's `matchBase` option will enabled, so globs match a file's basename regardless of directory:
137
+ - **`"*.js"`** will match all JS files, like `/test.js` and `/foo/bar/test.js`
138
+ - **`"!(*test).js"`**. will match all JS files, except those ending in `test.js`, so `foo.js` but not `foo.test.js`
139
+ - If the glob pattern does contain a slash (`/`), it will match for paths as well:
140
+ - **`"./*.js"`** will match all JS files in the git repo root, so `/test.js` but not `/foo/bar/test.js`
141
+ - **`"foo/**/\*.js"`** will match all JS files inside the`/foo`directory, so`/foo/bar/test.js`but not`/test.js`
137
142
 
138
143
  When matching, `lint-staged` will do the following
139
144
 
140
- * Resolve the git root automatically, no configuration needed.
141
- * Pick the staged files which are present inside the project directory.
142
- * Filter them using the specified glob patterns.
143
- * Pass absolute paths to the linters as arguments.
145
+ - Resolve the git root automatically, no configuration needed.
146
+ - Pick the staged files which are present inside the project directory.
147
+ - Filter them using the specified glob patterns.
148
+ - Pass absolute paths to the linters as arguments.
144
149
 
145
150
  **NOTE:** `lint-staged` will pass _absolute_ paths to the linters to avoid any confusion in case they're executed in a different working directory (i.e. when your `.git` directory isn't the same as your `package.json` directory).
146
151
 
@@ -156,7 +161,7 @@ In advanced scenarios, where it is impossible to configure the linter task itsel
156
161
 
157
162
  ## What commands are supported?
158
163
 
159
- Supported are any executables installed locally or globally via `npm` as well as any executable from your $PATH.
164
+ Supported are any executables installed locally or globally via `npm` as well as any executable from your \$PATH.
160
165
 
161
166
  > Using globally installed scripts is discouraged, since lint-staged may not work for someone who doesn’t have it installed.
162
167
 
@@ -407,7 +412,7 @@ const lintStaged = require('lint-staged')
407
412
  try {
408
413
  const success = await lintStaged()
409
414
  console.log(success ? 'Linting was successful!' : 'Linting failed!')
410
- } catch(e) {
415
+ } catch (e) {
411
416
  // Failed to load configuration
412
417
  console.error(e)
413
418
  }
@@ -426,7 +431,6 @@ const success = await lintStaged({
426
431
 
427
432
  You can also pass config directly with `config` option:
428
433
 
429
-
430
434
  ```js
431
435
  const success = await lintStaged({
432
436
  config: {
package/bin/lint-staged CHANGED
@@ -34,6 +34,11 @@ cmdline
34
34
  .option('-x, --shell', 'Skip parsing of tasks for better shell support')
35
35
  .option('-q, --quiet', 'Disable lint-staged’s own console output')
36
36
  .option('-d, --debug', 'Enable debug mode')
37
+ .option(
38
+ '-p, --concurrent <parallel tasks>',
39
+ 'The number of tasks to run concurrently, or false to run tasks serially',
40
+ true
41
+ )
37
42
  .parse(process.argv)
38
43
 
39
44
  if (cmdline.debug) {
@@ -47,7 +52,8 @@ lintStaged({
47
52
  relative: !!cmdline.relative,
48
53
  shell: !!cmdline.shell,
49
54
  quiet: !!cmdline.quiet,
50
- debug: !!cmdline.debug
55
+ debug: !!cmdline.debug,
56
+ concurrent: cmdline.concurrent
51
57
  })
52
58
  .then(passed => {
53
59
  process.exitCode = passed ? 0 : 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "9.4.2",
3
+ "version": "9.5.0",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/okonet/lint-staged",
package/src/index.js CHANGED
@@ -48,12 +48,21 @@ function loadConfig(configPath) {
48
48
  * @param {boolean} [options.shell] - Skip parsing of tasks for better shell support
49
49
  * @param {boolean} [options.quiet] - Disable lint-staged’s own console output
50
50
  * @param {boolean} [options.debug] - Enable debug mode
51
+ * @param {boolean | number} [options.concurrent] - The number of tasks to run concurrently, or false to run tasks serially
51
52
  * @param {Logger} [logger]
52
53
  *
53
54
  * @returns {Promise<boolean>} Promise of whether the linting passed or failed
54
55
  */
55
56
  module.exports = function lintStaged(
56
- { configPath, config, relative = false, shell = false, quiet = false, debug = false } = {},
57
+ {
58
+ configPath,
59
+ config,
60
+ relative = false,
61
+ shell = false,
62
+ quiet = false,
63
+ debug = false,
64
+ concurrent = true
65
+ } = {},
57
66
  logger = console
58
67
  ) {
59
68
  debugLog('Loading config using `cosmiconfig`')
@@ -76,7 +85,7 @@ module.exports = function lintStaged(
76
85
  debugLog('lint-staged config:\n%O', config)
77
86
  }
78
87
 
79
- return runAll({ config, relative, shell, quiet, debug }, logger)
88
+ return runAll({ config, relative, shell, quiet, debug, concurrent }, logger)
80
89
  .then(() => {
81
90
  debugLog('tasks were executed successfully!')
82
91
  return Promise.resolve(true)
package/src/runAll.js CHANGED
@@ -33,15 +33,23 @@ const MAX_ARG_LENGTH =
33
33
  * @param {boolean} [options.shell] - Skip parsing of tasks for better shell support
34
34
  * @param {boolean} [options.quiet] - Disable lint-staged’s own console output
35
35
  * @param {boolean} [options.debug] - Enable debug mode
36
+ * @param {boolean | number} [options.concurrent] - The number of tasks to run concurrently, or false to run tasks serially
36
37
  * @param {Logger} logger
37
38
  * @returns {Promise}
38
39
  */
39
40
  module.exports = async function runAll(
40
- { config, cwd = process.cwd(), debug = false, quiet = false, relative = false, shell = false },
41
+ {
42
+ config,
43
+ cwd = process.cwd(),
44
+ debug = false,
45
+ quiet = false,
46
+ relative = false,
47
+ shell = false,
48
+ concurrent = true
49
+ },
41
50
  logger = console
42
51
  ) {
43
52
  debugLog('Running all linter scripts')
44
-
45
53
  const gitDir = await resolveGitDir({ cwd })
46
54
 
47
55
  if (!gitDir) {
@@ -120,7 +128,7 @@ https://github.com/okonet/lint-staged#using-js-functions-to-customize-linter-com
120
128
  },
121
129
  {
122
130
  title: 'Running tasks...',
123
- task: () => new Listr(tasks, { ...listrOptions, concurrent: true, exitOnError: false })
131
+ task: () => new Listr(tasks, { ...listrOptions, concurrent, exitOnError: false })
124
132
  },
125
133
  {
126
134
  title: 'Updating stash...',