lint-staged 17.0.8 → 17.1.1
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 +14 -28
- package/bin/lint-staged.js +5 -5
- package/lib/chunkFiles.js +2 -2
- package/lib/cli.js +17 -12
- package/lib/colors.js +26 -8
- package/lib/debug.js +2 -2
- package/lib/figures.js +9 -5
- package/lib/getFunctionTask.js +13 -4
- package/lib/getSpawnedTask.js +9 -9
- package/lib/getSpawnedTasks.js +3 -6
- package/lib/gitWorkflow.js +188 -112
- package/lib/index.js +23 -20
- package/lib/messages.js +36 -29
- package/lib/parseGitZOutput.js +1 -1
- package/lib/printTaskOutput.js +2 -2
- package/lib/runAll.js +103 -103
- package/lib/runParallelTasks.js +112 -0
- package/lib/state.js +14 -9
- package/lib/validateOptions.js +30 -3
- package/package.json +20 -25
- package/lib/getRenderer.js +0 -63
package/lib/state.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { gitError, taskError } from './messages.js'
|
|
2
2
|
import {
|
|
3
3
|
FailOnChangesError,
|
|
4
4
|
GitError,
|
|
@@ -56,31 +56,31 @@ export const updateIndexSkipped = (ctx) => {
|
|
|
56
56
|
|
|
57
57
|
// Should be skipped in case of git errors
|
|
58
58
|
if (ctx.errors.has(GitError)) {
|
|
59
|
-
return
|
|
59
|
+
return gitError()
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// Should be skipped when tasks fail
|
|
63
63
|
if (ctx.errors.has(TaskError)) {
|
|
64
|
-
return
|
|
64
|
+
return taskError()
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export const restoreUnstagedChangesSkipped = (ctx) => {
|
|
69
69
|
// Should be skipped in case of git errors
|
|
70
70
|
if (ctx.errors.has(GitError)) {
|
|
71
|
-
return
|
|
71
|
+
return gitError()
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// When complete reverting to original state is skipped,
|
|
75
75
|
// we can still restore unstaged changes to make it easier
|
|
76
76
|
// to do manually.
|
|
77
77
|
if (!ctx.shouldRevert) {
|
|
78
|
-
false
|
|
78
|
+
return false
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
// Should be skipped when tasks fail
|
|
82
82
|
if (ctx.errors.has(TaskError)) {
|
|
83
|
-
return
|
|
83
|
+
return taskError()
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -94,7 +94,7 @@ export const restoreOriginalStateEnabled = (ctx) =>
|
|
|
94
94
|
export const restoreOriginalStateSkipped = (ctx) => {
|
|
95
95
|
// Should be skipped in case of unknown git errors
|
|
96
96
|
if (ctx.errors.has(GitError) && !ctx.errors.has(RestoreUnstagedChangesError)) {
|
|
97
|
-
return
|
|
97
|
+
return gitError()
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -106,13 +106,18 @@ export const cleanupSkipped = (ctx) => {
|
|
|
106
106
|
return true
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/** Failed to restore hidden unstaged changes, shouldn't drop stash, @see restoreUnstagedChangesSkipped */
|
|
110
|
+
if (ctx.errors.has(RestoreUnstagedChangesError) && !ctx.shouldRevert) {
|
|
111
|
+
return gitError()
|
|
112
|
+
}
|
|
113
|
+
|
|
109
114
|
// Should be skipped in case of unknown git errors
|
|
110
115
|
if (restoreOriginalStateSkipped(ctx)) {
|
|
111
|
-
return
|
|
116
|
+
return gitError()
|
|
112
117
|
}
|
|
113
118
|
|
|
114
119
|
// Should be skipped when reverting to original state fails
|
|
115
120
|
if (ctx.errors.has(RestoreOriginalStateError)) {
|
|
116
|
-
return
|
|
121
|
+
return gitError()
|
|
117
122
|
}
|
|
118
123
|
}
|
package/lib/validateOptions.js
CHANGED
|
@@ -8,6 +8,9 @@ import { InvalidOptionsError } from './symbols.js'
|
|
|
8
8
|
|
|
9
9
|
const debugLog = createDebug('lint-staged:validateOptions')
|
|
10
10
|
|
|
11
|
+
/** @type {(value: number) => boolean} */
|
|
12
|
+
const isValidIntegerValue = (value) => Number.isInteger(value) || value === Infinity
|
|
13
|
+
|
|
11
14
|
/**
|
|
12
15
|
* Validate lint-staged options, either from the Node.js API or the command line flags.
|
|
13
16
|
* @param {*} options
|
|
@@ -17,17 +20,41 @@ const debugLog = createDebug('lint-staged:validateOptions')
|
|
|
17
20
|
export const validateOptions = async (options = {}, logger) => {
|
|
18
21
|
debugLog('Validating options...')
|
|
19
22
|
|
|
23
|
+
const { concurrent, cwd, maxArgLength } = options
|
|
24
|
+
|
|
25
|
+
if (
|
|
26
|
+
concurrent !== undefined &&
|
|
27
|
+
typeof concurrent !== 'boolean' &&
|
|
28
|
+
(!isValidIntegerValue(concurrent) || concurrent < 1)
|
|
29
|
+
) {
|
|
30
|
+
logger.error(
|
|
31
|
+
invalidOption('concurrent', `${concurrent}`, 'Must be boolean, positive integer or Infinite')
|
|
32
|
+
)
|
|
33
|
+
throw InvalidOptionsError
|
|
34
|
+
}
|
|
35
|
+
|
|
20
36
|
/** Ensure the passed cwd option exists; it might also be relative */
|
|
21
|
-
if (typeof
|
|
37
|
+
if (typeof cwd === 'string') {
|
|
22
38
|
try {
|
|
23
|
-
const resolved = path.resolve(
|
|
39
|
+
const resolved = path.resolve(cwd)
|
|
24
40
|
await fs.access(resolved, constants.F_OK)
|
|
25
41
|
} catch (error) {
|
|
26
42
|
debugLog('Failed to validate options: %o', options)
|
|
27
|
-
logger.error(invalidOption('cwd',
|
|
43
|
+
logger.error(invalidOption('cwd', cwd, error.message))
|
|
28
44
|
throw InvalidOptionsError
|
|
29
45
|
}
|
|
30
46
|
}
|
|
31
47
|
|
|
48
|
+
if (
|
|
49
|
+
maxArgLength !== undefined &&
|
|
50
|
+
maxArgLength !== null &&
|
|
51
|
+
(!isValidIntegerValue(maxArgLength) || maxArgLength < 1)
|
|
52
|
+
) {
|
|
53
|
+
logger.error(
|
|
54
|
+
invalidOption('maxArgLength', `${maxArgLength}`, 'Must be positive integer, or Infinite')
|
|
55
|
+
)
|
|
56
|
+
throw InvalidOptionsError
|
|
57
|
+
}
|
|
58
|
+
|
|
32
59
|
debugLog('Validated options: %o', options)
|
|
33
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lint-staged",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.1.1",
|
|
4
4
|
"description": "Lint files staged by git",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"MIGRATION.md"
|
|
45
45
|
],
|
|
46
46
|
"scripts": {
|
|
47
|
-
"lint": "
|
|
47
|
+
"lint": "oxfmt && oxlint",
|
|
48
48
|
"test": "vitest",
|
|
49
49
|
"typecheck": "tsc",
|
|
50
50
|
"version": "npx changeset version",
|
|
@@ -52,8 +52,7 @@
|
|
|
52
52
|
"tag": "npx changeset tag"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"
|
|
56
|
-
"picomatch": "^4.0.4",
|
|
55
|
+
"picomatch": "^4.0.5",
|
|
57
56
|
"string-argv": "^0.3.2",
|
|
58
57
|
"tinyexec": "^1.2.4"
|
|
59
58
|
},
|
|
@@ -62,36 +61,32 @@
|
|
|
62
61
|
},
|
|
63
62
|
"devDependencies": {
|
|
64
63
|
"@changesets/changelog-github": "0.7.0",
|
|
65
|
-
"@changesets/cli": "2.31.
|
|
66
|
-
"@commitlint/cli": "21.
|
|
67
|
-
"@commitlint/config-conventional": "21.0
|
|
68
|
-
"@
|
|
69
|
-
"@vitest/coverage-istanbul": "4.1.9",
|
|
70
|
-
"@vitest/eslint-plugin": "1.6.20",
|
|
64
|
+
"@changesets/cli": "2.31.1",
|
|
65
|
+
"@commitlint/cli": "21.2.1",
|
|
66
|
+
"@commitlint/config-conventional": "21.2.0",
|
|
67
|
+
"@vitest/coverage-istanbul": "4.1.10",
|
|
71
68
|
"consolemock": "1.1.0",
|
|
72
69
|
"cross-env": "10.1.0",
|
|
73
|
-
"eslint": "10.5.0",
|
|
74
|
-
"eslint-config-prettier": "10.1.8",
|
|
75
|
-
"eslint-plugin-n": "18.1.0",
|
|
76
|
-
"eslint-plugin-prettier": "5.5.6",
|
|
77
|
-
"eslint-plugin-simple-import-sort": "13.0.0",
|
|
78
70
|
"husky": "9.1.7",
|
|
79
71
|
"mock-stdin": "1.0.0",
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
72
|
+
"oxfmt": "0.59.0",
|
|
73
|
+
"oxlint": "1.74.0",
|
|
74
|
+
"semver": "7.8.5",
|
|
75
|
+
"vitest": "4.1.10"
|
|
83
76
|
},
|
|
84
77
|
"keywords": [
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"staged",
|
|
78
|
+
"check",
|
|
79
|
+
"code",
|
|
88
80
|
"eslint",
|
|
81
|
+
"format",
|
|
82
|
+
"git",
|
|
83
|
+
"lint",
|
|
84
|
+
"oxlint",
|
|
85
|
+
"oxfmt",
|
|
89
86
|
"prettier",
|
|
90
|
-
"stylelint",
|
|
91
|
-
"code",
|
|
92
87
|
"quality",
|
|
93
|
-
"
|
|
94
|
-
"
|
|
88
|
+
"staged",
|
|
89
|
+
"stylelint",
|
|
95
90
|
"validate"
|
|
96
91
|
]
|
|
97
92
|
}
|
package/lib/getRenderer.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { EOL } from 'node:os'
|
|
2
|
-
import { Writable } from 'node:stream'
|
|
3
|
-
|
|
4
|
-
import { ListrLogger, ProcessOutput } from 'listr2'
|
|
5
|
-
|
|
6
|
-
const EOLRegex = new RegExp(EOL + '$')
|
|
7
|
-
|
|
8
|
-
const bindLogger = (consoleLogMethod) =>
|
|
9
|
-
new Writable({
|
|
10
|
-
write: function (chunk, encoding, next) {
|
|
11
|
-
consoleLogMethod(chunk.toString().replace(EOLRegex, ''))
|
|
12
|
-
next()
|
|
13
|
-
},
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
const getMainRendererOptions = ({ color, debug, quiet }, logger, env) => {
|
|
17
|
-
if (quiet) {
|
|
18
|
-
return {
|
|
19
|
-
renderer: 'silent',
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (env.NODE_ENV === 'test') {
|
|
24
|
-
return {
|
|
25
|
-
renderer: 'test',
|
|
26
|
-
rendererOptions: {
|
|
27
|
-
logger: new ListrLogger({
|
|
28
|
-
processOutput: new ProcessOutput(bindLogger(logger.log), bindLogger(logger.error)),
|
|
29
|
-
}),
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (debug || !color) {
|
|
35
|
-
return {
|
|
36
|
-
renderer: 'verbose',
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
renderer: 'update',
|
|
42
|
-
rendererOptions: {
|
|
43
|
-
formatOutput: 'truncate',
|
|
44
|
-
},
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const getFallbackRenderer = ({ renderer }, { color }) => {
|
|
49
|
-
if (renderer === 'silent' || renderer === 'test' || !color) {
|
|
50
|
-
return renderer
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return 'verbose'
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const getRenderer = ({ color, debug, quiet }, logger, env = process.env) => {
|
|
57
|
-
const mainRendererOptions = getMainRendererOptions({ color, debug, quiet }, logger, env)
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
...mainRendererOptions,
|
|
61
|
-
fallbackRenderer: getFallbackRenderer(mainRendererOptions, { color }),
|
|
62
|
-
}
|
|
63
|
-
}
|