lint-staged 15.2.8 → 15.2.10

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
@@ -293,6 +293,8 @@ Supported are any executables installed locally or globally via `npm` as well as
293
293
  }
294
294
  ```
295
295
 
296
+ This will result in _lint-staged_ running `eslint --fix file-1.js file-2.js`, when you have staged files `file-1.js`, `file-2.js` and `README.md`.
297
+
296
298
  Pass arguments to your commands separated by space as you would do in the shell. See [examples](#examples) below.
297
299
 
298
300
  ## Running multiple commands in a sequence
@@ -309,6 +311,8 @@ For example:
309
311
 
310
312
  going to execute `eslint` and if it exits with `0` code, it will execute `prettier --write` on all staged `*.js` files.
311
313
 
314
+ This will result in _lint-staged_ running `eslint file-1.js file-2.js`, when you have staged files `file-1.js`, `file-2.js` and `README.md`, and if it passes, `prettier --write file-1.js file-2.js`.
315
+
312
316
  ## Using JS configuration files
313
317
 
314
318
  Writing the configuration file in JavaScript is the most powerful way to configure lint-staged (`lint-staged.config.js`, [similar](https://github.com/okonet/lint-staged#configuration), or passed via `--config`). From the configuration file, you can export either a single function or an object.
@@ -317,6 +321,16 @@ If the `exports` value is a function, it will receive an array of all staged fil
317
321
 
318
322
  If the `exports` value is an object, its keys should be glob matches (like in the normal non-js config format). The values can either be like in the normal config or individual functions like described above. Instead of receiving all matched files, the functions in the exported object will only receive the staged files matching the corresponding glob key.
319
323
 
324
+ To summarize, by default _lint-staged_ automatically adds the list of matched staged files to your command, but when building the command using JS functions it is expected to do this manually. For example:
325
+
326
+ ```js
327
+ export default {
328
+ '*.js': (stagedFiles) => [`eslint .`, `prettier --write ${stagedFiles.join(' ')}`],
329
+ }
330
+ ```
331
+
332
+ This will result in _lint-staged_ first running `eslint .` (matching _all_ files), and if it passes, `prettier --write file-1.js file-2.js`, when you have staged files `file-1.js`, `file-2.js` and `README.md`.
333
+
320
334
  ### Function signature
321
335
 
322
336
  The function can also be async:
@@ -6,12 +6,12 @@ import { execGit } from './execGit.js'
6
6
  import { readFile, unlink, writeFile } from './file.js'
7
7
  import { getDiffCommand } from './getDiffCommand.js'
8
8
  import {
9
- GitError,
10
- RestoreOriginalStateError,
11
9
  ApplyEmptyCommitError,
12
10
  GetBackupStashError,
11
+ GitError,
13
12
  HideUnstagedChangesError,
14
13
  RestoreMergeStatusError,
14
+ RestoreOriginalStateError,
15
15
  RestoreUnstagedChangesError,
16
16
  } from './symbols.js'
17
17
 
package/lib/index.js CHANGED
@@ -2,10 +2,10 @@ import debug from 'debug'
2
2
 
3
3
  import { execGit } from './execGit.js'
4
4
  import {
5
- PREVENTED_EMPTY_COMMIT,
6
5
  GIT_ERROR,
7
- RESTORE_STASH_EXAMPLE,
8
6
  NO_CONFIGURATION,
7
+ PREVENTED_EMPTY_COMMIT,
8
+ RESTORE_STASH_EXAMPLE,
9
9
  } from './messages.js'
10
10
  import { printTaskOutput } from './printTaskOutput.js'
11
11
  import { runAll } from './runAll.js'
package/lib/loadConfig.js CHANGED
@@ -6,15 +6,15 @@ import path from 'node:path'
6
6
  import debug from 'debug'
7
7
  import YAML from 'yaml'
8
8
 
9
- import { dynamicImport } from './dynamicImport.js'
10
- import { failedToLoadConfig } from './messages.js'
11
- import { resolveConfig } from './resolveConfig.js'
12
9
  import {
13
10
  CONFIG_FILE_NAMES,
14
11
  CONFIG_NAME,
15
12
  PACKAGE_JSON_FILE,
16
13
  PACKAGE_YAML_FILES,
17
14
  } from './configFiles.js'
15
+ import { dynamicImport } from './dynamicImport.js'
16
+ import { failedToLoadConfig } from './messages.js'
17
+ import { resolveConfig } from './resolveConfig.js'
18
18
 
19
19
  const debugLog = debug('lint-staged:loadConfig')
20
20
 
@@ -12,7 +12,7 @@ const debugLog = debug('lint-staged:resolveGitRepo')
12
12
  *
13
13
  * @example ".git"
14
14
  */
15
- const resolveRelativeGitDir = async (cwd = process.cwd()) => {
15
+ const resolveRelativeGitDir = async (cwd) => {
16
16
  /**
17
17
  * Absolute repo top-level directory
18
18
  *
@@ -1,8 +1,8 @@
1
1
  import chalk from 'chalk'
2
- import { execa, execaCommand } from 'execa'
3
2
  import debug from 'debug'
4
- import { parseArgsStringToArgv } from 'string-argv'
3
+ import { execa, execaCommand } from 'execa'
5
4
  import pidTree from 'pidtree'
5
+ import { parseArgsStringToArgv } from 'string-argv'
6
6
 
7
7
  import { error, info } from './figures.js'
8
8
  import { getInitialState } from './state.js'
package/lib/runAll.js CHANGED
@@ -17,27 +17,27 @@ import { makeCmdTasks } from './makeCmdTasks.js'
17
17
  import {
18
18
  DEPRECATED_GIT_ADD,
19
19
  FAILED_GET_STAGED_FILES,
20
- NOT_GIT_REPO,
21
20
  NO_STAGED_FILES,
22
21
  NO_TASKS,
22
+ NOT_GIT_REPO,
23
23
  SKIPPED_GIT_ERROR,
24
24
  skippingBackup,
25
25
  skippingHidePartiallyStaged,
26
26
  } from './messages.js'
27
27
  import { normalizePath } from './normalizePath.js'
28
28
  import { resolveGitRepo } from './resolveGitRepo.js'
29
+ import { searchConfigs } from './searchConfigs.js'
29
30
  import {
30
31
  applyModificationsSkipped,
31
32
  cleanupEnabled,
32
33
  cleanupSkipped,
33
34
  getInitialState,
34
- shouldHidePartiallyStagedFiles,
35
35
  restoreOriginalStateEnabled,
36
36
  restoreOriginalStateSkipped,
37
37
  restoreUnstagedChangesSkipped,
38
+ shouldHidePartiallyStagedFiles,
38
39
  } from './state.js'
39
- import { GitRepoError, GetStagedFilesError, GitError, ConfigNotFoundError } from './symbols.js'
40
- import { searchConfigs } from './searchConfigs.js'
40
+ import { ConfigNotFoundError, GetStagedFilesError, GitError, GitRepoError } from './symbols.js'
41
41
 
42
42
  const debugLog = debug('lint-staged:runAll')
43
43
 
@@ -161,6 +161,14 @@ export const runAll = async (
161
161
  ...getRenderer({ debug, quiet }, logger),
162
162
  }
163
163
 
164
+ /**
165
+ * This is used to set max event listener count to the total number
166
+ * of generated tasks. The event listener is used to keep track of
167
+ * the interrupt signal and kill all tasks when it happens. See the
168
+ * `interruptExecutionOnError` in `resolveTaskFn`.
169
+ */
170
+ let listrTaskCount = 0
171
+
164
172
  const listrTasks = []
165
173
 
166
174
  // Set of all staged files that matched a task glob. Values in a set are unique.
@@ -231,6 +239,8 @@ export const runAll = async (
231
239
  )
232
240
  )
233
241
 
242
+ listrTaskCount += chunkListrTasks.length
243
+
234
244
  listrTasks.push({
235
245
  title:
236
246
  `${configName}${chalk.dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
@@ -321,6 +331,9 @@ export const runAll = async (
321
331
  listrOptions
322
332
  )
323
333
 
334
+ debugLog('Set max event listeners to the number of tasks: %i', listrTaskCount)
335
+ ctx.events.setMaxListeners(listrTaskCount)
336
+
324
337
  await runner.run()
325
338
 
326
339
  if (ctx.errors.size > 0) {
@@ -4,12 +4,12 @@ import path from 'node:path'
4
4
 
5
5
  import debug from 'debug'
6
6
 
7
+ import { CONFIG_FILE_NAMES } from './configFiles.js'
7
8
  import { execGit } from './execGit.js'
8
9
  import { loadConfig } from './loadConfig.js'
9
10
  import { normalizePath } from './normalizePath.js'
10
11
  import { parseGitZOutput } from './parseGitZOutput.js'
11
12
  import { validateConfig } from './validateConfig.js'
12
- import { CONFIG_FILE_NAMES } from './configFiles.js'
13
13
 
14
14
  const debugLog = debug('lint-staged:searchConfigs')
15
15
 
package/lib/state.js CHANGED
@@ -3,10 +3,10 @@ import EventEmitter from 'events'
3
3
  import { GIT_ERROR, TASK_ERROR } from './messages.js'
4
4
  import {
5
5
  ApplyEmptyCommitError,
6
- TaskError,
7
- RestoreOriginalStateError,
8
6
  GitError,
7
+ RestoreOriginalStateError,
9
8
  RestoreUnstagedChangesError,
9
+ TaskError,
10
10
  } from './symbols.js'
11
11
 
12
12
  export const getInitialState = ({ quiet = false } = {}) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "15.2.8",
3
+ "version": "15.2.10",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/lint-staged/lint-staged",
@@ -42,7 +42,7 @@
42
42
  "execa": "~8.0.1",
43
43
  "lilconfig": "~3.1.2",
44
44
  "listr2": "~8.2.4",
45
- "micromatch": "~4.0.7",
45
+ "micromatch": "~4.0.8",
46
46
  "pidtree": "~0.6.0",
47
47
  "string-argv": "~0.3.2",
48
48
  "yaml": "~2.5.0"
@@ -50,20 +50,23 @@
50
50
  "devDependencies": {
51
51
  "@changesets/changelog-github": "0.5.0",
52
52
  "@changesets/cli": "2.27.7",
53
- "@commitlint/cli": "19.3.0",
54
- "@commitlint/config-conventional": "19.2.2",
53
+ "@commitlint/cli": "19.4.1",
54
+ "@commitlint/config-conventional": "19.4.1",
55
+ "@eslint/js": "9.9.1",
55
56
  "consolemock": "1.1.0",
56
57
  "cross-env": "7.0.3",
57
- "eslint": "8.57.0",
58
+ "eslint": "9.9.1",
58
59
  "eslint-config-prettier": "9.1.0",
59
- "eslint-plugin-import": "2.29.1",
60
- "eslint-plugin-node": "11.1.0",
60
+ "eslint-plugin-jest": "28.8.1",
61
+ "eslint-plugin-n": "17.10.2",
61
62
  "eslint-plugin-prettier": "5.2.1",
62
- "husky": "9.1.4",
63
+ "eslint-plugin-simple-import-sort": "12.1.1",
64
+ "husky": "9.1.5",
63
65
  "jest": "29.7.0",
64
66
  "jest-snapshot-serializer-ansi": "2.1.0",
65
67
  "mock-stdin": "1.0.0",
66
- "prettier": "3.3.3"
68
+ "prettier": "3.3.3",
69
+ "semver": "7.6.3"
67
70
  },
68
71
  "keywords": [
69
72
  "lint",