lint-staged 12.3.0 → 12.3.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 +2 -2
- package/lib/resolveGitRepo.js +2 -1
- package/lib/runAll.js +20 -6
- package/package.json +13 -10
package/README.md
CHANGED
|
@@ -103,14 +103,14 @@ Options:
|
|
|
103
103
|
|
|
104
104
|
- **`--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.
|
|
105
105
|
- **`--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:
|
|
106
|
-
- uses [debug](https://github.com/visionmedia/debug) internally to log additional 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*`.
|
|
107
|
-
- uses [`verbose` renderer](https://github.com/SamVerschueren/listr-verbose-renderer) for `listr`; this causes serial, uncoloured output to the terminal, instead of the default (beautified, dynamic) output.
|
|
108
106
|
- `false`: Run all tasks serially
|
|
109
107
|
- `true` (default) : _Infinite_ concurrency. Runs as many tasks in parallel as possible.
|
|
110
108
|
- `{number}`: Run the specified number of tasks in parallel, where `1` is equivalent to `false`.
|
|
111
109
|
- **`--config [path]`**: Manually specify a path to a config file or npm package name. Note: when used, lint-staged won't perform the config file search and will print an error if the specified file cannot be found. If '-' is provided as the filename then the config will be read from stdin, allowing piping in the config like `cat my-config.json | npx lint-staged --config -`.
|
|
112
110
|
- **`--cwd [path]`**: By default tasks run in the current working directory. Use the `--cwd some/directory` to override this. The path can be absolute or relative to the current working directory.
|
|
113
111
|
- **`--debug`**: Run in debug mode. When set, it does the following:
|
|
112
|
+
- uses [debug](https://github.com/visionmedia/debug) internally to log additional 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*`.
|
|
113
|
+
- uses [`verbose` renderer](https://github.com/SamVerschueren/listr-verbose-renderer) for `listr`; this causes serial, uncoloured output to the terminal, instead of the default (beautified, dynamic) output.
|
|
114
114
|
- **`--no-stash`**: By default a backup stash will be created before running the tasks, and all task modifications will be reverted in case of an error. This option will disable creating the stash, and instead leave all modifications in the index when aborting the commit.
|
|
115
115
|
- **`--quiet`**: Supress all CLI output, except from tasks.
|
|
116
116
|
- **`--relative`**: Pass filepaths relative to `process.cwd()` (where `lint-staged` runs) to tasks. Default is `false`.
|
package/lib/resolveGitRepo.js
CHANGED
|
@@ -14,7 +14,8 @@ const debugLog = debug('lint-staged:resolveGitRepo')
|
|
|
14
14
|
* submodules and worktrees
|
|
15
15
|
*/
|
|
16
16
|
const resolveGitConfigDir = async (gitDir) => {
|
|
17
|
-
|
|
17
|
+
// Get the real path in case it's a symlink
|
|
18
|
+
const defaultDir = normalize(await fs.realpath(path.join(gitDir, '.git')))
|
|
18
19
|
const stats = await fs.lstat(defaultDir)
|
|
19
20
|
// If .git is a directory, use it
|
|
20
21
|
if (stats.isDirectory()) return defaultDir
|
package/lib/runAll.js
CHANGED
|
@@ -80,7 +80,8 @@ export const runAll = async (
|
|
|
80
80
|
debugLog('Running all linter scripts...')
|
|
81
81
|
|
|
82
82
|
// Resolve relative CWD option
|
|
83
|
-
|
|
83
|
+
const hasExplicitCwd = !!cwd
|
|
84
|
+
cwd = hasExplicitCwd ? path.resolve(cwd) : process.cwd()
|
|
84
85
|
debugLog('Using working directory `%s`', cwd)
|
|
85
86
|
|
|
86
87
|
const ctx = getInitialState({ quiet })
|
|
@@ -120,6 +121,8 @@ export const runAll = async (
|
|
|
120
121
|
|
|
121
122
|
const configGroups = await getConfigGroups({ configObject, configPath, cwd, files }, logger)
|
|
122
123
|
|
|
124
|
+
const hasMultipleConfigs = Object.keys(configGroups).length > 1
|
|
125
|
+
|
|
123
126
|
// lint-staged 10 will automatically add modifications to index
|
|
124
127
|
// Warn user when their command includes `git add`
|
|
125
128
|
let hasDeprecatedGitAdd = false
|
|
@@ -138,21 +141,25 @@ export const runAll = async (
|
|
|
138
141
|
const matchedFiles = new Set()
|
|
139
142
|
|
|
140
143
|
for (const [configPath, { config, files }] of Object.entries(configGroups)) {
|
|
144
|
+
const relativeConfig = normalize(path.relative(cwd, configPath))
|
|
141
145
|
const stagedFileChunks = chunkFiles({ baseDir: gitDir, files, maxArgLength, relative })
|
|
142
146
|
|
|
147
|
+
// Use actual cwd if it's specified, or there's only a single config file.
|
|
148
|
+
// Otherwise use the directory of the config file for each config group,
|
|
149
|
+
// to make sure tasks are separated from each other.
|
|
150
|
+
const groupCwd = hasMultipleConfigs && !hasExplicitCwd ? path.dirname(configPath) : cwd
|
|
151
|
+
|
|
143
152
|
const chunkCount = stagedFileChunks.length
|
|
144
153
|
if (chunkCount > 1) {
|
|
145
154
|
debugLog('Chunked staged files from `%s` into %d part', configPath, chunkCount)
|
|
146
155
|
}
|
|
147
156
|
|
|
148
157
|
for (const [index, files] of stagedFileChunks.entries()) {
|
|
149
|
-
const relativeConfig = normalize(path.relative(cwd, configPath))
|
|
150
|
-
|
|
151
158
|
const chunkListrTasks = await Promise.all(
|
|
152
|
-
generateTasks({ config, cwd, files, relative }).map((task) =>
|
|
159
|
+
generateTasks({ config, cwd: groupCwd, files, relative }).map((task) =>
|
|
153
160
|
makeCmdTasks({
|
|
154
161
|
commands: task.commands,
|
|
155
|
-
cwd,
|
|
162
|
+
cwd: groupCwd,
|
|
156
163
|
files: task.fileList,
|
|
157
164
|
gitDir,
|
|
158
165
|
renderer: listrOptions.renderer,
|
|
@@ -161,7 +168,14 @@ export const runAll = async (
|
|
|
161
168
|
}).then((subTasks) => {
|
|
162
169
|
// Add files from task to match set
|
|
163
170
|
task.fileList.forEach((file) => {
|
|
164
|
-
|
|
171
|
+
// Make sure relative files are normalized to the
|
|
172
|
+
// group cwd, because other there might be identical
|
|
173
|
+
// relative filenames in the entire set.
|
|
174
|
+
const normalizedFile = path.isAbsolute(file)
|
|
175
|
+
? file
|
|
176
|
+
: normalize(path.join(groupCwd, file))
|
|
177
|
+
|
|
178
|
+
matchedFiles.add(normalizedFile)
|
|
165
179
|
})
|
|
166
180
|
|
|
167
181
|
hasDeprecatedGitAdd =
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lint-staged",
|
|
3
|
-
"version": "12.3.
|
|
3
|
+
"version": "12.3.4",
|
|
4
4
|
"description": "Lint files staged by git",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/okonet/lint-staged",
|
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
},
|
|
19
19
|
"type": "module",
|
|
20
20
|
"bin": "./bin/lint-staged.js",
|
|
21
|
-
"exports":
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./lib/index.js",
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
22
25
|
"files": [
|
|
23
26
|
"bin",
|
|
24
27
|
"lib"
|
|
@@ -35,28 +38,28 @@
|
|
|
35
38
|
"debug": "^4.3.3",
|
|
36
39
|
"execa": "^5.1.1",
|
|
37
40
|
"lilconfig": "2.0.4",
|
|
38
|
-
"listr2": "^
|
|
41
|
+
"listr2": "^4.0.1",
|
|
39
42
|
"micromatch": "^4.0.4",
|
|
40
43
|
"normalize-path": "^3.0.0",
|
|
41
|
-
"object-inspect": "^1.
|
|
44
|
+
"object-inspect": "^1.12.0",
|
|
42
45
|
"string-argv": "^0.3.1",
|
|
43
46
|
"supports-color": "^9.2.1",
|
|
44
47
|
"yaml": "^1.10.2"
|
|
45
48
|
},
|
|
46
49
|
"devDependencies": {
|
|
47
|
-
"@babel/core": "^7.16.
|
|
50
|
+
"@babel/core": "^7.16.12",
|
|
48
51
|
"@babel/eslint-parser": "^7.16.5",
|
|
49
|
-
"@babel/preset-env": "^7.16.
|
|
50
|
-
"babel-jest": "^27.4.
|
|
52
|
+
"@babel/preset-env": "^7.16.11",
|
|
53
|
+
"babel-jest": "^27.4.6",
|
|
51
54
|
"consolemock": "^1.1.0",
|
|
52
|
-
"eslint": "^8.
|
|
55
|
+
"eslint": "^8.7.0",
|
|
53
56
|
"eslint-config-prettier": "^8.3.0",
|
|
54
|
-
"eslint-plugin-import": "^2.25.
|
|
57
|
+
"eslint-plugin-import": "^2.25.4",
|
|
55
58
|
"eslint-plugin-node": "^11.1.0",
|
|
56
59
|
"eslint-plugin-prettier": "^4.0.0",
|
|
57
60
|
"fs-extra": "^10.0.0",
|
|
58
61
|
"husky": "^7.0.4",
|
|
59
|
-
"jest": "^27.4.
|
|
62
|
+
"jest": "^27.4.7",
|
|
60
63
|
"jest-snapshot-serializer-ansi": "^1.0.0",
|
|
61
64
|
"prettier": "^2.5.1"
|
|
62
65
|
},
|