lint-staged 13.1.3 → 13.2.0
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 -1
- package/bin/lint-staged.js +3 -3
- package/lib/figures.js +4 -4
- package/lib/gitWorkflow.js +1 -10
- package/lib/messages.js +14 -12
- package/lib/resolveTaskFn.js +4 -4
- package/lib/runAll.js +6 -6
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -126,7 +126,8 @@ Options:
|
|
|
126
126
|
- **`--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.
|
|
127
127
|
- **`--debug`**: Run in debug mode. When set, it does the following:
|
|
128
128
|
- 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*`.
|
|
129
|
-
- uses [`verbose` renderer](https://
|
|
129
|
+
- uses [`verbose` renderer](https://listr2.kilic.dev/renderers/verbose-renderer/) for `listr2`; this causes serial, uncoloured output to the terminal, instead of the default (beautified, dynamic) output.
|
|
130
|
+
(the [`verbose` renderer](https://listr2.kilic.dev/renderers/verbose-renderer/) can also be activated by setting the `TERM=dumb` or `NODE_ENV=test` environment variables)
|
|
130
131
|
- **`--diff`**: By default linters are filtered against all files staged in git, generated from `git diff --staged`. This option allows you to override the `--staged` flag with arbitrary revisions. For example to get a list of changed files between two branches, use `--diff="branch1...branch2"`. You can also read more from about [git diff](https://git-scm.com/docs/git-diff) and [gitrevisions](https://git-scm.com/docs/gitrevisions). This option also implies `--no-stash`.
|
|
131
132
|
- **`--diff-filter`**: By default only files that are _added_, _copied_, _modified_, or _renamed_ are included. Use this flag to override the default `ACMR` value with something else: _added_ (`A`), _copied_ (`C`), _deleted_ (`D`), _modified_ (`M`), _renamed_ (`R`), _type changed_ (`T`), _unmerged_ (`U`), _unknown_ (`X`), or _pairing broken_ (`B`). See also the `git diff` docs for [--diff-filter](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203).
|
|
132
133
|
- **`--max-arg-length`**: long commands (a lot of files) are automatically split into multiple chunks when it detects the current shell cannot handle them. Use this flag to override the maximum length of the generated command string.
|
package/bin/lint-staged.js
CHANGED
|
@@ -4,16 +4,16 @@ import fs from 'node:fs'
|
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
import { fileURLToPath } from 'node:url'
|
|
6
6
|
|
|
7
|
+
import { supportsColor } from 'chalk'
|
|
7
8
|
import { Option, program } from 'commander'
|
|
8
9
|
import debug from 'debug'
|
|
9
|
-
import supportsColor from 'supports-color'
|
|
10
10
|
|
|
11
11
|
import lintStaged from '../lib/index.js'
|
|
12
12
|
import { CONFIG_STDIN_ERROR } from '../lib/messages.js'
|
|
13
13
|
|
|
14
14
|
// Force colors for packages that depend on https://www.npmjs.com/package/supports-color
|
|
15
|
-
if (supportsColor
|
|
16
|
-
process.env.FORCE_COLOR = supportsColor.
|
|
15
|
+
if (supportsColor) {
|
|
16
|
+
process.env.FORCE_COLOR = supportsColor.level.toString()
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// Do not terminate main Listr process on SIGINT
|
package/lib/figures.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import chalk from 'chalk'
|
|
2
2
|
import { figures } from 'listr2'
|
|
3
3
|
|
|
4
|
-
export const info = blue(figures.arrowRight)
|
|
4
|
+
export const info = chalk.blue(figures.arrowRight)
|
|
5
5
|
|
|
6
|
-
export const error = redBright(figures.cross)
|
|
6
|
+
export const error = chalk.redBright(figures.cross)
|
|
7
7
|
|
|
8
|
-
export const warning = yellow(figures.warning)
|
|
8
|
+
export const warning = chalk.yellow(figures.warning)
|
package/lib/gitWorkflow.js
CHANGED
|
@@ -104,16 +104,7 @@ export class GitWorkflow {
|
|
|
104
104
|
throw new Error('lint-staged automatic backup is missing!')
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
* https://github.com/okonet/lint-staged/issues/1121
|
|
109
|
-
* Detect MSYS in login shell mode and escape braces
|
|
110
|
-
* to prevent interpolation
|
|
111
|
-
*/
|
|
112
|
-
if (!!process.env.MSYSTEM && !!process.env.LOGINSHELL) {
|
|
113
|
-
return `refs/stash@\\{${index}\\}`
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return `refs/stash@{${index}}`
|
|
107
|
+
return String(index)
|
|
117
108
|
}
|
|
118
109
|
|
|
119
110
|
/**
|
package/lib/messages.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import chalk from 'chalk'
|
|
2
2
|
import inspect from 'object-inspect'
|
|
3
3
|
|
|
4
4
|
import { error, info, warning } from './figures.js'
|
|
5
5
|
|
|
6
6
|
export const configurationError = (opt, helpMsg, value) =>
|
|
7
|
-
`${redBright(`${error} Validation Error:`)}
|
|
7
|
+
`${chalk.redBright(`${error} Validation Error:`)}
|
|
8
8
|
|
|
9
|
-
Invalid value for '${bold(opt)}': ${bold(
|
|
9
|
+
Invalid value for '${chalk.bold(opt)}': ${chalk.bold(
|
|
10
10
|
inspect(value, { inlineCharacterLimit: Number.POSITIVE_INFINITY })
|
|
11
11
|
)}
|
|
12
12
|
|
|
13
13
|
${helpMsg}`
|
|
14
14
|
|
|
15
|
-
export const NOT_GIT_REPO = redBright(`${error} Current directory is not a git directory!`)
|
|
15
|
+
export const NOT_GIT_REPO = chalk.redBright(`${error} Current directory is not a git directory!`)
|
|
16
16
|
|
|
17
|
-
export const FAILED_GET_STAGED_FILES = redBright(`${error} Failed to get staged files!`)
|
|
17
|
+
export const FAILED_GET_STAGED_FILES = chalk.redBright(`${error} Failed to get staged files!`)
|
|
18
18
|
|
|
19
19
|
export const incorrectBraces = (before, after) =>
|
|
20
|
-
yellow(
|
|
20
|
+
chalk.yellow(
|
|
21
21
|
`${warning} Detected incorrect braces with only single value: \`${before}\`. Reformatted as: \`${after}\`
|
|
22
22
|
`
|
|
23
23
|
)
|
|
@@ -36,10 +36,10 @@ export const skippingBackup = (hasInitialCommit, diff) => {
|
|
|
36
36
|
? '`--no-stash` was used'
|
|
37
37
|
: 'there’s no initial commit yet'
|
|
38
38
|
|
|
39
|
-
return yellow(`${warning} Skipping backup because ${reason}.\n`)
|
|
39
|
+
return chalk.yellow(`${warning} Skipping backup because ${reason}.\n`)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export const DEPRECATED_GIT_ADD = yellow(
|
|
42
|
+
export const DEPRECATED_GIT_ADD = chalk.yellow(
|
|
43
43
|
`${warning} Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.
|
|
44
44
|
`
|
|
45
45
|
)
|
|
@@ -48,18 +48,20 @@ export const TASK_ERROR = 'Skipped because of errors from tasks.'
|
|
|
48
48
|
|
|
49
49
|
export const SKIPPED_GIT_ERROR = 'Skipped because of previous git error.'
|
|
50
50
|
|
|
51
|
-
export const GIT_ERROR = `\n ${redBright(`${error} lint-staged failed due to a git error.`)}`
|
|
51
|
+
export const GIT_ERROR = `\n ${chalk.redBright(`${error} lint-staged failed due to a git error.`)}`
|
|
52
52
|
|
|
53
|
-
export const invalidOption = (name, value, message) => `${redBright(
|
|
53
|
+
export const invalidOption = (name, value, message) => `${chalk.redBright(
|
|
54
|
+
`${error} Validation Error:`
|
|
55
|
+
)}
|
|
54
56
|
|
|
55
|
-
Invalid value for option '${bold(name)}': ${bold(value)}
|
|
57
|
+
Invalid value for option '${chalk.bold(name)}': ${chalk.bold(value)}
|
|
56
58
|
|
|
57
59
|
${message}
|
|
58
60
|
|
|
59
61
|
See https://github.com/okonet/lint-staged#command-line-flags`
|
|
60
62
|
|
|
61
63
|
export const PREVENTED_EMPTY_COMMIT = `
|
|
62
|
-
${yellow(`${warning} lint-staged prevented an empty git commit.
|
|
64
|
+
${chalk.yellow(`${warning} lint-staged prevented an empty git commit.
|
|
63
65
|
Use the --allow-empty option to continue, or check your task configuration`)}
|
|
64
66
|
`
|
|
65
67
|
|
package/lib/resolveTaskFn.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import chalk from 'chalk'
|
|
2
2
|
import { execa, execaCommand } from 'execa'
|
|
3
3
|
import debug from 'debug'
|
|
4
4
|
import { parseArgsStringToArgv } from 'string-argv'
|
|
@@ -32,7 +32,7 @@ const handleOutput = (command, result, ctx, isError = false) => {
|
|
|
32
32
|
const hasOutput = !!stderr || !!stdout
|
|
33
33
|
|
|
34
34
|
if (hasOutput) {
|
|
35
|
-
const outputTitle = isError ? redBright(`${error} ${command}:`) : `${info} ${command}:`
|
|
35
|
+
const outputTitle = isError ? chalk.redBright(`${error} ${command}:`) : `${info} ${command}:`
|
|
36
36
|
const output = []
|
|
37
37
|
.concat(ctx.quiet ? [] : ['', outputTitle])
|
|
38
38
|
.concat(stderr ? stderr : [])
|
|
@@ -41,7 +41,7 @@ const handleOutput = (command, result, ctx, isError = false) => {
|
|
|
41
41
|
} else if (isError) {
|
|
42
42
|
// Show generic error when task had no output
|
|
43
43
|
const tag = getTag(result)
|
|
44
|
-
const message = redBright(`\n${error} ${command} failed without output (${tag}).`)
|
|
44
|
+
const message = chalk.redBright(`\n${error} ${command} failed without output (${tag}).`)
|
|
45
45
|
if (!ctx.quiet) ctx.output.push(message)
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -116,7 +116,7 @@ const makeErr = (command, result, ctx) => {
|
|
|
116
116
|
|
|
117
117
|
handleOutput(command, result, ctx, true)
|
|
118
118
|
const tag = getTag(result)
|
|
119
|
-
return new Error(`${redBright(command)} ${dim(`[${tag}]`)}`)
|
|
119
|
+
return new Error(`${chalk.redBright(command)} ${chalk.dim(`[${tag}]`)}`)
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
/**
|
package/lib/runAll.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import chalk from 'chalk'
|
|
6
6
|
import debug from 'debug'
|
|
7
7
|
import { Listr } from 'listr2'
|
|
8
8
|
import normalize from 'normalize-path'
|
|
@@ -204,7 +204,7 @@ export const runAll = async (
|
|
|
204
204
|
const fileCount = task.fileList.length
|
|
205
205
|
|
|
206
206
|
return {
|
|
207
|
-
title: `${task.pattern}${dim(
|
|
207
|
+
title: `${task.pattern}${chalk.dim(
|
|
208
208
|
` — ${fileCount} ${fileCount === 1 ? 'file' : 'files'}`
|
|
209
209
|
)}`,
|
|
210
210
|
task: async (ctx, task) =>
|
|
@@ -216,7 +216,7 @@ export const runAll = async (
|
|
|
216
216
|
skip: () => {
|
|
217
217
|
// Skip task when no files matched
|
|
218
218
|
if (fileCount === 0) {
|
|
219
|
-
return `${task.pattern}${dim(' — no files')}`
|
|
219
|
+
return `${task.pattern}${chalk.dim(' — no files')}`
|
|
220
220
|
}
|
|
221
221
|
return false
|
|
222
222
|
},
|
|
@@ -227,15 +227,15 @@ export const runAll = async (
|
|
|
227
227
|
|
|
228
228
|
listrTasks.push({
|
|
229
229
|
title:
|
|
230
|
-
`${configName}${dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
|
|
231
|
-
(chunkCount > 1 ? dim(` (chunk ${index + 1}/${chunkCount})...`) : ''),
|
|
230
|
+
`${configName}${chalk.dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
|
|
231
|
+
(chunkCount > 1 ? chalk.dim(` (chunk ${index + 1}/${chunkCount})...`) : ''),
|
|
232
232
|
task: (ctx, task) => task.newListr(chunkListrTasks, { concurrent, exitOnError: true }),
|
|
233
233
|
skip: () => {
|
|
234
234
|
// Skip if the first step (backup) failed
|
|
235
235
|
if (ctx.errors.has(GitError)) return SKIPPED_GIT_ERROR
|
|
236
236
|
// Skip chunk when no every task is skipped (due to no matches)
|
|
237
237
|
if (chunkListrTasks.every((task) => task.skip())) {
|
|
238
|
-
return `${configName}${dim(' — no tasks to run')}`
|
|
238
|
+
return `${configName}${chalk.dim(' — no tasks to run')}`
|
|
239
239
|
}
|
|
240
240
|
return false
|
|
241
241
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lint-staged",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.2.0",
|
|
4
4
|
"description": "Lint files staged by git",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/okonet/lint-staged",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"test:watch": "jest --watch"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"chalk": "5.2.0",
|
|
36
37
|
"cli-truncate": "^3.1.0",
|
|
37
|
-
"colorette": "^2.0.19",
|
|
38
38
|
"commander": "^10.0.0",
|
|
39
39
|
"debug": "^4.3.4",
|
|
40
40
|
"execa": "^7.0.0",
|
|
@@ -45,24 +45,23 @@
|
|
|
45
45
|
"object-inspect": "^1.12.3",
|
|
46
46
|
"pidtree": "^0.6.0",
|
|
47
47
|
"string-argv": "^0.3.1",
|
|
48
|
-
"supports-color": "9.3.1",
|
|
49
48
|
"yaml": "^2.2.1"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
51
|
"@babel/core": "^7.21.0",
|
|
53
52
|
"@babel/eslint-parser": "^7.19.1",
|
|
54
53
|
"@babel/preset-env": "^7.20.2",
|
|
55
|
-
"babel-jest": "^29.
|
|
54
|
+
"babel-jest": "^29.5.0",
|
|
56
55
|
"babel-plugin-transform-imports": "2.0.0",
|
|
57
56
|
"consolemock": "^1.1.0",
|
|
58
57
|
"eslint": "^8.35.0",
|
|
59
|
-
"eslint-config-prettier": "^8.
|
|
58
|
+
"eslint-config-prettier": "^8.7.0",
|
|
60
59
|
"eslint-plugin-import": "^2.27.5",
|
|
61
60
|
"eslint-plugin-node": "^11.1.0",
|
|
62
61
|
"eslint-plugin-prettier": "^4.2.1",
|
|
63
62
|
"fs-extra": "^11.1.0",
|
|
64
63
|
"husky": "^8.0.3",
|
|
65
|
-
"jest": "^29.
|
|
64
|
+
"jest": "^29.5.0",
|
|
66
65
|
"jest-snapshot-serializer-ansi": "^1.0.0",
|
|
67
66
|
"prettier": "^2.8.4"
|
|
68
67
|
},
|