lint-staged 15.2.9 → 15.2.11

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:
@@ -5,12 +5,21 @@ import { getDiffCommand } from './getDiffCommand.js'
5
5
  import { normalizePath } from './normalizePath.js'
6
6
  import { parseGitZOutput } from './parseGitZOutput.js'
7
7
 
8
+ const listSubmoduleRoots = async ({ cwd }) => {
9
+ const lines = await execGit(['submodule', '--quiet', 'foreach', 'echo $displaypath'], { cwd })
10
+ return lines.split('\n').map((file) => normalizePath(path.resolve(cwd, file)))
11
+ }
12
+
8
13
  export const getStagedFiles = async ({ cwd = process.cwd(), diff, diffFilter } = {}) => {
9
14
  try {
10
15
  const lines = await execGit(getDiffCommand(diff, diffFilter), { cwd })
11
16
  if (!lines) return []
12
17
 
13
- return parseGitZOutput(lines).map((file) => normalizePath(path.resolve(cwd, file)))
18
+ const submodules = await listSubmoduleRoots({ cwd })
19
+
20
+ return parseGitZOutput(lines)
21
+ .map((file) => normalizePath(path.resolve(cwd, file)))
22
+ .filter((file) => !submodules.includes(file))
14
23
  } catch {
15
24
  return null
16
25
  }
@@ -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,13 +1,18 @@
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'
9
9
  import { TaskError } from './symbols.js'
10
10
 
11
+ /**
12
+ * @see https://github.com/sindresorhus/execa/blob/f4b8b3ab601c94d1503f1010822952758dcc6350/lib/command.js#L32-L37
13
+ */
14
+ const escapeSpaces = (input) => input.replaceAll(' ', '\\ ')
15
+
11
16
  const TASK_ERROR = 'lint-staged:taskError'
12
17
 
13
18
  const debugLog = debug('lint-staged:resolveTaskFn')
@@ -159,7 +164,10 @@ export const resolveTaskFn = ({
159
164
 
160
165
  return async (ctx = getInitialState()) => {
161
166
  const execaChildProcess = shell
162
- ? execaCommand(isFn ? command : `${command} ${files.join(' ')}`, execaOptions)
167
+ ? execaCommand(
168
+ isFn ? command : `${command} ${files.map(escapeSpaces).join(' ')}`,
169
+ execaOptions
170
+ )
163
171
  : execa(cmd, isFn ? args : args.concat(files), execaOptions)
164
172
 
165
173
  const quitInterruptCheck = interruptExecutionOnError(ctx, execaChildProcess)
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
 
@@ -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.9",
3
+ "version": "15.2.11",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/lint-staged/lint-staged",
@@ -38,32 +38,35 @@
38
38
  "dependencies": {
39
39
  "chalk": "~5.3.0",
40
40
  "commander": "~12.1.0",
41
- "debug": "~4.3.6",
41
+ "debug": "~4.4.0",
42
42
  "execa": "~8.0.1",
43
- "lilconfig": "~3.1.2",
44
- "listr2": "~8.2.4",
45
- "micromatch": "~4.0.7",
43
+ "lilconfig": "~3.1.3",
44
+ "listr2": "~8.2.5",
45
+ "micromatch": "~4.0.8",
46
46
  "pidtree": "~0.6.0",
47
47
  "string-argv": "~0.3.2",
48
- "yaml": "~2.5.0"
48
+ "yaml": "~2.6.1"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@changesets/changelog-github": "0.5.0",
52
- "@changesets/cli": "2.27.7",
53
- "@commitlint/cli": "19.3.0",
54
- "@commitlint/config-conventional": "19.2.2",
52
+ "@changesets/cli": "2.27.10",
53
+ "@commitlint/cli": "19.6.0",
54
+ "@commitlint/config-conventional": "19.6.0",
55
+ "@eslint/js": "9.16.0",
55
56
  "consolemock": "1.1.0",
56
57
  "cross-env": "7.0.3",
57
- "eslint": "8.57.0",
58
+ "eslint": "9.16.0",
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.9.0",
61
+ "eslint-plugin-n": "17.15.0",
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.7",
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.4.2",
69
+ "semver": "7.6.3"
67
70
  },
68
71
  "keywords": [
69
72
  "lint",