lint-staged 15.2.1 → 15.2.4

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
@@ -223,15 +223,43 @@ Pay extra attention when the configured globs overlap, and tasks make edits to f
223
223
  }
224
224
  ```
225
225
 
226
- If necessary, you can limit the concurrency using `--concurrent <number>` or disable it entirely with `--concurrent false`.
226
+ You can solve it using the negation pattern and the array syntax:
227
+
228
+ ```json
229
+ {
230
+ "!(*.ts)": "prettier --write",
231
+ "*.ts": ["eslint --fix", "prettier --write"]
232
+ }
233
+ ```
234
+
235
+ Another example in which tasks make edits to files and globs match multiple files but don't overlap:
236
+
237
+ ```json
238
+ {
239
+ "*.css": [
240
+ "stylelint --fix",
241
+ "prettier --write"
242
+ ],
243
+ "*.{js,jsx}": [
244
+ "eslint --fix",
245
+ "prettier --write"
246
+ ],
247
+ "!(*.css|*.js|*.jsx)": [
248
+ "prettier --write"
249
+ ]
250
+ }
251
+ ```
252
+
253
+ Or, if necessary, you can limit the concurrency using `--concurrent <number>` or disable it entirely with `--concurrent false`.
227
254
 
228
255
  ## Filtering files
229
256
 
230
257
  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:
231
258
 
232
- - If the glob pattern contains no slashes (`/`), micromatch's `matchBase` option will enabled, so globs match a file's basename regardless of directory:
259
+ - If the glob pattern contains no slashes (`/`), micromatch's `matchBase` option will be enabled, so globs match a file's basename regardless of directory:
233
260
  - `"*.js"` will match all JS files, like `/test.js` and `/foo/bar/test.js`
234
261
  - `"!(*test).js"` will match all JS files, except those ending in `test.js`, so `foo.js` but not `foo.test.js`
262
+ - `"!(*.css|*.js)"` will match all files except CSS and JS files
235
263
  - If the glob pattern does contain a slash (`/`), it will match for paths as well:
236
264
  - `"./*.js"` will match all JS files in the git repo root, so `/test.js` but not `/foo/bar/test.js`
237
265
  - `"foo/**/*.js"` will match all JS files inside the `/foo` directory, so `/foo/bar/test.js` but not `/test.js`
@@ -879,7 +907,7 @@ ESLint throws out `warning File ignored because of a matching ignore pattern. Us
879
907
  <details>
880
908
  <summary>Click to expand</summary>
881
909
 
882
- Based on the discussion from [this issue](https://github.com/eslint/eslint/issues/9977), it was decided that using [the outlined script ](https://github.com/eslint/eslint/issues/9977#issuecomment-406420893)is the best route to fix this.
910
+ Based on the discussion from [this issue](https://github.com/eslint/eslint/issues/9977), it was decided that using [the outlined script](https://github.com/eslint/eslint/issues/9977#issuecomment-406420893)is the best route to fix this.
883
911
 
884
912
  So you can setup a `.lintstagedrc.js` config file to do this:
885
913
 
@@ -96,7 +96,7 @@ const interruptExecutionOnError = (ctx, execaChildProcess) => {
96
96
  }
97
97
 
98
98
  /**
99
- * Create a error output dependding on process result.
99
+ * Create a error output depending on process result.
100
100
  *
101
101
  * @param {string} command
102
102
  * @param {Object} result
@@ -13,10 +13,9 @@ import { CONFIG_FILE_NAMES } from './configFiles.js'
13
13
 
14
14
  const debugLog = debug('lint-staged:searchConfigs')
15
15
 
16
- const EXEC_GIT = ['ls-files', '-z', '--full-name']
16
+ const EXEC_GIT = ['ls-files', '-z', '--full-name', '-t']
17
17
 
18
- const filterPossibleConfigFiles = (files) =>
19
- files.filter((file) => CONFIG_FILE_NAMES.includes(path.basename(file)))
18
+ const filterPossibleConfigFiles = (file) => CONFIG_FILE_NAMES.includes(path.basename(file))
20
19
 
21
20
  const numberOfLevels = (file) => file.split('/').length
22
21
 
@@ -58,17 +57,23 @@ export const searchConfigs = async (
58
57
  return { [configPath]: validateConfig(config, filepath, logger) }
59
58
  }
60
59
 
61
- const [cachedFiles, otherFiles] = await Promise.all([
60
+ const [cachedFilesWithStatus, otherFilesWithStatus] = await Promise.all([
62
61
  /** Get all possible config files known to git */
63
- execGit(EXEC_GIT, { cwd: gitDir }).then(parseGitZOutput).then(filterPossibleConfigFiles),
62
+ execGit(EXEC_GIT, { cwd: gitDir }).then(parseGitZOutput),
64
63
  /** Get all possible config files from uncommitted files */
65
- execGit([...EXEC_GIT, '--others', '--exclude-standard'], { cwd: gitDir })
66
- .then(parseGitZOutput)
67
- .then(filterPossibleConfigFiles),
64
+ execGit([...EXEC_GIT, '--others', '--exclude-standard'], { cwd: gitDir }).then(parseGitZOutput),
68
65
  ])
69
66
 
70
67
  /** Sort possible config files so that deepest is first */
71
- const possibleConfigFiles = [...cachedFiles, ...otherFiles]
68
+ const possibleConfigFiles = [...cachedFilesWithStatus, ...otherFilesWithStatus]
69
+ .flatMap(
70
+ /**
71
+ * Leave out lines starting with "S " to ignore not-checked-out files in a sparse repo.
72
+ * The "S" status means a tracked file that is "skip-worktree"
73
+ * @see https://git-scm.com/docs/git-ls-files#Documentation/git-ls-files.txt--t
74
+ */ (line) => (line.startsWith('S ') ? [] : [line.replace(/^[HSMRCK?U] /, '')])
75
+ )
76
+ .filter(filterPossibleConfigFiles)
72
77
  .map((file) => normalizePath(path.join(gitDir, file)))
73
78
  .filter(isInsideDirectory(cwd))
74
79
  .sort(sortDeepestParth)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "15.2.1",
3
+ "version": "15.2.4",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/okonet/lint-staged",
@@ -37,33 +37,33 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "chalk": "5.3.0",
40
- "commander": "11.1.0",
40
+ "commander": "12.1.0",
41
41
  "debug": "4.3.4",
42
42
  "execa": "8.0.1",
43
- "lilconfig": "3.0.0",
44
- "listr2": "8.0.1",
45
- "micromatch": "4.0.5",
43
+ "lilconfig": "3.1.1",
44
+ "listr2": "8.2.1",
45
+ "micromatch": "4.0.6",
46
46
  "pidtree": "0.6.0",
47
47
  "string-argv": "0.3.2",
48
- "yaml": "2.3.4"
48
+ "yaml": "2.4.2"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@changesets/changelog-github": "0.5.0",
52
- "@changesets/cli": "2.27.1",
53
- "@commitlint/cli": "18.4.4",
54
- "@commitlint/config-conventional": "18.4.4",
52
+ "@changesets/cli": "2.27.3",
53
+ "@commitlint/cli": "19.3.0",
54
+ "@commitlint/config-conventional": "19.2.2",
55
55
  "consolemock": "1.1.0",
56
56
  "cross-env": "7.0.3",
57
- "eslint": "8.56.0",
57
+ "eslint": "8.57.0",
58
58
  "eslint-config-prettier": "9.1.0",
59
59
  "eslint-plugin-import": "2.29.1",
60
60
  "eslint-plugin-node": "11.1.0",
61
61
  "eslint-plugin-prettier": "5.1.3",
62
- "husky": "8.0.3",
62
+ "husky": "9.0.11",
63
63
  "jest": "29.7.0",
64
64
  "jest-snapshot-serializer-ansi": "2.1.0",
65
65
  "mock-stdin": "1.0.0",
66
- "prettier": "3.2.4"
66
+ "prettier": "3.2.5"
67
67
  },
68
68
  "keywords": [
69
69
  "lint",