lint-staged 15.2.11 → 15.4.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 +38 -6
- package/bin/lint-staged.js +28 -23
- package/lib/configFiles.js +6 -0
- package/lib/gitWorkflow.js +19 -6
- package/lib/index.js +21 -4
- package/lib/loadConfig.js +6 -4
- package/lib/messages.js +4 -5
- package/lib/runAll.js +2 -2
- package/lib/state.js +4 -5
- package/lib/types.d.ts +101 -0
- package/lib/version.js +6 -0
- package/package.json +12 -9
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ npm install --save-dev lint-staged # requires further setup
|
|
|
13
13
|
```
|
|
14
14
|
$ git commit
|
|
15
15
|
|
|
16
|
-
✔
|
|
16
|
+
✔ Backed up original state in git stash (5bda95f)
|
|
17
17
|
❯ Running tasks for staged files...
|
|
18
18
|
❯ packages/frontend/.lintstagedrc.json — 1 file
|
|
19
19
|
↓ *.js — no files [SKIPPED]
|
|
@@ -70,6 +70,9 @@ Now change a few files, `git add` or `git add --patch` some of them to your comm
|
|
|
70
70
|
|
|
71
71
|
See [examples](#examples) and [configuration](#configuration) for more information.
|
|
72
72
|
|
|
73
|
+
> [!CAUTION]
|
|
74
|
+
> _Lint-staged_ runs `git` operations affecting the files in your repository. By default _lint-staged_ creates a `git stash` as a backup of the original state before running any configured tasks to help prevent data loss.
|
|
75
|
+
|
|
73
76
|
## Changelog
|
|
74
77
|
|
|
75
78
|
See [Releases](https://github.com/okonet/lint-staged/releases).
|
|
@@ -117,9 +120,10 @@ Options:
|
|
|
117
120
|
-c, --config [path] path to configuration file, or - to read from stdin
|
|
118
121
|
--cwd [path] run all tasks in specific directory, instead of the current
|
|
119
122
|
-d, --debug print additional debug information (default: false)
|
|
120
|
-
--diff [string] override the default "--staged" flag of "git diff" to get list of files.
|
|
121
|
-
"--no-stash".
|
|
122
|
-
--diff-filter [string] override the default "--diff-filter=ACMR" flag of "git diff" to get list of
|
|
123
|
+
--diff [string] override the default "--staged" flag of "git diff" to get list of files.
|
|
124
|
+
Implies "--no-stash".
|
|
125
|
+
--diff-filter [string] override the default "--diff-filter=ACMR" flag of "git diff" to get list of
|
|
126
|
+
files
|
|
123
127
|
--max-arg-length [number] maximum length of the command-line argument string (default: 0)
|
|
124
128
|
--no-stash disable the backup stash, and do not revert in case of errors. Implies
|
|
125
129
|
"--no-hide-partially-staged".
|
|
@@ -127,9 +131,15 @@ Options:
|
|
|
127
131
|
-q, --quiet disable lint-staged’s own console output (default: false)
|
|
128
132
|
-r, --relative pass relative filepaths to tasks (default: false)
|
|
129
133
|
-x, --shell [path] skip parsing of tasks for better shell support (default: false)
|
|
130
|
-
-v, --verbose show task output even when tasks succeed; by default only failed output is
|
|
131
|
-
(default: false)
|
|
134
|
+
-v, --verbose show task output even when tasks succeed; by default only failed output is
|
|
135
|
+
shown (default: false)
|
|
132
136
|
-h, --help display help for command
|
|
137
|
+
|
|
138
|
+
Any lost modifications can be restored from a git stash:
|
|
139
|
+
|
|
140
|
+
> git stash list
|
|
141
|
+
stash@{0}: automatic lint-staged backup
|
|
142
|
+
> git stash apply --index stash@{0}
|
|
133
143
|
```
|
|
134
144
|
|
|
135
145
|
- **`--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.
|
|
@@ -198,6 +208,28 @@ So, considering you did `git add file1.ext file2.ext`, lint-staged will run the
|
|
|
198
208
|
|
|
199
209
|
`your-cmd file1.ext file2.ext`
|
|
200
210
|
|
|
211
|
+
### TypeScript
|
|
212
|
+
|
|
213
|
+
_Lint-staged_ provides TypeScript types for the configuration and main Node.js API. You can use the JSDoc syntax in your JS configuration files:
|
|
214
|
+
|
|
215
|
+
```js
|
|
216
|
+
/**
|
|
217
|
+
* @filename: lint-staged.config.js
|
|
218
|
+
* @type {import('lint-staged').Configuration}
|
|
219
|
+
*/
|
|
220
|
+
export default {
|
|
221
|
+
'*': 'prettier --write',
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
It's also possible to use the `.ts` file extension for the configuration if your Node.js version supports it. The `--experimental-strip-types` flag was introduced in [Node.js v22.6.0](https://github.com/nodejs/node/releases/tag/v22.6.0) and unflagged in [v23.6.0](https://github.com/nodejs/node/releases/tag/v23.6.0), enabling Node.js to execute TypeScript files without additional configuration.
|
|
226
|
+
|
|
227
|
+
```shell
|
|
228
|
+
export NODE_OPTIONS="--experimental-strip-types"
|
|
229
|
+
|
|
230
|
+
npx lint-staged --config lint-staged.config.ts
|
|
231
|
+
```
|
|
232
|
+
|
|
201
233
|
### Task concurrency
|
|
202
234
|
|
|
203
235
|
By default _lint-staged_ will run configured tasks concurrently. This means that for every glob, all the commands will be started at the same time. With the following config, both `eslint` and `prettier` will run at the same time:
|
package/bin/lint-staged.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { userInfo } from 'node:os'
|
|
4
4
|
|
|
5
5
|
import { supportsColor } from 'chalk'
|
|
6
6
|
import { Option, program } from 'commander'
|
|
7
7
|
import debug from 'debug'
|
|
8
8
|
|
|
9
9
|
import lintStaged from '../lib/index.js'
|
|
10
|
-
import { CONFIG_STDIN_ERROR } from '../lib/messages.js'
|
|
10
|
+
import { CONFIG_STDIN_ERROR, RESTORE_STASH_EXAMPLE } from '../lib/messages.js'
|
|
11
11
|
import { readStdin } from '../lib/readStdin.js'
|
|
12
|
+
import { getVersion } from '../lib/version.js'
|
|
12
13
|
|
|
13
14
|
// Force colors for packages that depend on https://www.npmjs.com/package/supports-color
|
|
14
15
|
if (supportsColor) {
|
|
@@ -20,45 +21,42 @@ const debugLog = debug('lint-staged:bin')
|
|
|
20
21
|
// Do not terminate main Listr process on SIGINT
|
|
21
22
|
process.on('SIGINT', () => {})
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
const version = packageJson.version
|
|
24
|
+
program.version(await getVersion())
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
program.option('--allow-empty', 'allow empty commits when tasks revert all staged changes', false)
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
cli.option(
|
|
28
|
+
program.option(
|
|
31
29
|
'-p, --concurrent <number|boolean>',
|
|
32
30
|
'the number of tasks to run concurrently, or false for serial',
|
|
33
31
|
true
|
|
34
32
|
)
|
|
35
33
|
|
|
36
|
-
|
|
34
|
+
program.option('-c, --config [path]', 'path to configuration file, or - to read from stdin')
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
program.option('--cwd [path]', 'run all tasks in specific directory, instead of the current')
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
program.option('-d, --debug', 'print additional debug information', false)
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
program.addOption(
|
|
43
41
|
new Option(
|
|
44
42
|
'--diff [string]',
|
|
45
43
|
'override the default "--staged" flag of "git diff" to get list of files. Implies "--no-stash".'
|
|
46
44
|
).implies({ stash: false })
|
|
47
45
|
)
|
|
48
46
|
|
|
49
|
-
|
|
47
|
+
program.option(
|
|
50
48
|
'--diff-filter [string]',
|
|
51
49
|
'override the default "--diff-filter=ACMR" flag of "git diff" to get list of files'
|
|
52
50
|
)
|
|
53
51
|
|
|
54
|
-
|
|
52
|
+
program.option('--max-arg-length [number]', 'maximum length of the command-line argument string', 0)
|
|
55
53
|
|
|
56
54
|
/**
|
|
57
55
|
* We don't want to show the `--stash` flag because it's on by default, and only show the
|
|
58
56
|
* negatable flag `--no-stash` in stead. There seems to be a bug in Commander.js where
|
|
59
57
|
* configuring only the latter won't actually set the default value.
|
|
60
58
|
*/
|
|
61
|
-
|
|
59
|
+
program
|
|
62
60
|
.addOption(
|
|
63
61
|
new Option('--stash', 'enable the backup stash, and revert in case of errors')
|
|
64
62
|
.default(true)
|
|
@@ -78,7 +76,7 @@ cli
|
|
|
78
76
|
* negatable flag `--no-hide-partially-staged` in stead. There seems to be a bug in Commander.js where
|
|
79
77
|
* configuring only the latter won't actually set the default value.
|
|
80
78
|
*/
|
|
81
|
-
|
|
79
|
+
program
|
|
82
80
|
.addOption(
|
|
83
81
|
new Option('--hide-partially-staged', 'hide unstaged changes from partially staged files')
|
|
84
82
|
.default(true)
|
|
@@ -91,26 +89,26 @@ cli
|
|
|
91
89
|
).default(false)
|
|
92
90
|
)
|
|
93
91
|
|
|
94
|
-
|
|
92
|
+
program.option('-q, --quiet', 'disable lint-staged’s own console output', false)
|
|
95
93
|
|
|
96
|
-
|
|
94
|
+
program.option('-r, --relative', 'pass relative filepaths to tasks', false)
|
|
97
95
|
|
|
98
|
-
|
|
96
|
+
program.option('-x, --shell [path]', 'skip parsing of tasks for better shell support', false)
|
|
99
97
|
|
|
100
|
-
|
|
98
|
+
program.option(
|
|
101
99
|
'-v, --verbose',
|
|
102
100
|
'show task output even when tasks succeed; by default only failed output is shown',
|
|
103
101
|
false
|
|
104
102
|
)
|
|
105
103
|
|
|
106
|
-
|
|
104
|
+
program.addHelpText('afterAll', '\n' + RESTORE_STASH_EXAMPLE)
|
|
105
|
+
|
|
106
|
+
const cliOptions = program.parse(process.argv).opts()
|
|
107
107
|
|
|
108
108
|
if (cliOptions.debug) {
|
|
109
109
|
debug.enable('lint-staged*')
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
debugLog('Running `lint-staged@%s` on Node.js %s (%s)', version, process.version, process.platform)
|
|
113
|
-
|
|
114
112
|
const options = {
|
|
115
113
|
allowEmpty: !!cliOptions.allowEmpty,
|
|
116
114
|
concurrent: JSON.parse(cliOptions.concurrent),
|
|
@@ -128,6 +126,13 @@ const options = {
|
|
|
128
126
|
verbose: !!cliOptions.verbose,
|
|
129
127
|
}
|
|
130
128
|
|
|
129
|
+
try {
|
|
130
|
+
const { shell } = userInfo()
|
|
131
|
+
debugLog('Using shell: %s', shell)
|
|
132
|
+
} catch {
|
|
133
|
+
debugLog('Could not determine current shell')
|
|
134
|
+
}
|
|
135
|
+
|
|
131
136
|
debugLog('Options parsed from command-line: %o', options)
|
|
132
137
|
|
|
133
138
|
if (options.configPath === '-') {
|
package/lib/configFiles.js
CHANGED
|
@@ -16,9 +16,15 @@ export const CONFIG_FILE_NAMES = [
|
|
|
16
16
|
'.lintstagedrc.yaml',
|
|
17
17
|
'.lintstagedrc.yml',
|
|
18
18
|
'.lintstagedrc.mjs',
|
|
19
|
+
'.lintstagedrc.mts',
|
|
19
20
|
'.lintstagedrc.js',
|
|
21
|
+
'.lintstagedrc.ts',
|
|
20
22
|
'.lintstagedrc.cjs',
|
|
23
|
+
'.lintstagedrc.cts',
|
|
21
24
|
'lint-staged.config.mjs',
|
|
25
|
+
'.lint-staged.config.mts',
|
|
22
26
|
'lint-staged.config.js',
|
|
27
|
+
'.lint-staged.config.ts',
|
|
23
28
|
'lint-staged.config.cjs',
|
|
29
|
+
'.lint-staged.config.cts',
|
|
24
30
|
]
|
package/lib/gitWorkflow.js
CHANGED
|
@@ -98,7 +98,11 @@ export class GitWorkflow {
|
|
|
98
98
|
*/
|
|
99
99
|
async getBackupStash(ctx) {
|
|
100
100
|
const stashes = await this.execGit(['stash', 'list'])
|
|
101
|
-
|
|
101
|
+
|
|
102
|
+
const index = stashes
|
|
103
|
+
.split('\n')
|
|
104
|
+
.findIndex((line) => line.includes(STASH) && line.includes(ctx.backupHash))
|
|
105
|
+
|
|
102
106
|
if (index === -1) {
|
|
103
107
|
ctx.errors.add(GetBackupStashError)
|
|
104
108
|
throw new Error('lint-staged automatic backup is missing!')
|
|
@@ -190,9 +194,9 @@ export class GitWorkflow {
|
|
|
190
194
|
/**
|
|
191
195
|
* Create a diff of partially staged files and backup stash if enabled.
|
|
192
196
|
*/
|
|
193
|
-
async prepare(ctx) {
|
|
197
|
+
async prepare(ctx, task) {
|
|
194
198
|
try {
|
|
195
|
-
debugLog(
|
|
199
|
+
debugLog(task.title)
|
|
196
200
|
|
|
197
201
|
// Get a list of files with bot staged and unstaged changes.
|
|
198
202
|
// Unstaged changes to these files should be hidden before the tasks run.
|
|
@@ -223,10 +227,19 @@ export class GitWorkflow {
|
|
|
223
227
|
// Save stash of all staged files.
|
|
224
228
|
// The `stash create` command creates a dangling commit without removing any files,
|
|
225
229
|
// and `stash store` saves it as an actual stash.
|
|
226
|
-
const
|
|
227
|
-
await this.execGit(['
|
|
230
|
+
const stashHash = await this.execGit(['stash', 'create'])
|
|
231
|
+
ctx.backupHash = await this.execGit(['rev-parse', '--short', stashHash])
|
|
232
|
+
await this.execGit([
|
|
233
|
+
'stash',
|
|
234
|
+
'store',
|
|
235
|
+
'--quiet',
|
|
236
|
+
'--message',
|
|
237
|
+
`${STASH} (${ctx.backupHash})`,
|
|
238
|
+
ctx.backupHash,
|
|
239
|
+
])
|
|
228
240
|
|
|
229
|
-
|
|
241
|
+
task.title = `Backed up original state in git stash (${ctx.backupHash})`
|
|
242
|
+
debugLog(task.title)
|
|
230
243
|
} catch (error) {
|
|
231
244
|
handleError(error, ctx)
|
|
232
245
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import debugLib from 'debug'
|
|
2
2
|
|
|
3
3
|
import { execGit } from './execGit.js'
|
|
4
4
|
import {
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from './messages.js'
|
|
10
10
|
import { printTaskOutput } from './printTaskOutput.js'
|
|
11
11
|
import { runAll } from './runAll.js'
|
|
12
|
+
import { cleanupSkipped } from './state.js'
|
|
12
13
|
import {
|
|
13
14
|
ApplyEmptyCommitError,
|
|
14
15
|
ConfigNotFoundError,
|
|
@@ -16,8 +17,9 @@ import {
|
|
|
16
17
|
GitError,
|
|
17
18
|
} from './symbols.js'
|
|
18
19
|
import { validateOptions } from './validateOptions.js'
|
|
20
|
+
import { getVersion } from './version.js'
|
|
19
21
|
|
|
20
|
-
const debugLog =
|
|
22
|
+
const debugLog = debugLib('lint-staged')
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* Get the maximum length of a command-line argument string based on current platform
|
|
@@ -83,6 +85,18 @@ const lintStaged = async (
|
|
|
83
85
|
} = {},
|
|
84
86
|
logger = console
|
|
85
87
|
) => {
|
|
88
|
+
// Seemingly enable debug twice (also done in bin), so that it also works when using the Node.js API
|
|
89
|
+
if (debug) {
|
|
90
|
+
debugLib.enable('lint-staged*')
|
|
91
|
+
|
|
92
|
+
debugLog(
|
|
93
|
+
'Running `lint-staged@%s` on Node.js %s (%s)',
|
|
94
|
+
await getVersion(),
|
|
95
|
+
process.version,
|
|
96
|
+
process.platform
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
86
100
|
const gitVersion = await execGit(['version', '--build-options'], { cwd })
|
|
87
101
|
debugLog('%s', gitVersion)
|
|
88
102
|
|
|
@@ -123,11 +137,14 @@ const lintStaged = async (
|
|
|
123
137
|
logger.error(NO_CONFIGURATION)
|
|
124
138
|
} else if (ctx.errors.has(ApplyEmptyCommitError)) {
|
|
125
139
|
logger.warn(PREVENTED_EMPTY_COMMIT)
|
|
126
|
-
} else if (
|
|
140
|
+
} else if (
|
|
141
|
+
(ctx.errors.has(GitError) || cleanupSkipped(ctx)) &&
|
|
142
|
+
!ctx.errors.has(GetBackupStashError)
|
|
143
|
+
) {
|
|
127
144
|
logger.error(GIT_ERROR)
|
|
128
145
|
if (ctx.shouldBackup) {
|
|
129
146
|
// No sense to show this if the backup stash itself is missing.
|
|
130
|
-
logger.error(RESTORE_STASH_EXAMPLE)
|
|
147
|
+
logger.error(RESTORE_STASH_EXAMPLE + '\n')
|
|
131
148
|
}
|
|
132
149
|
}
|
|
133
150
|
|
package/lib/loadConfig.js
CHANGED
|
@@ -57,19 +57,21 @@ const NO_EXT = 'noExt'
|
|
|
57
57
|
* assumption is in `cosmiconfig` as well.
|
|
58
58
|
*/
|
|
59
59
|
const loaders = {
|
|
60
|
+
[NO_EXT]: yamlParse,
|
|
61
|
+
'.cjs': dynamicImport,
|
|
62
|
+
'.cts': dynamicImport,
|
|
60
63
|
'.js': dynamicImport,
|
|
61
64
|
'.json': jsonParse,
|
|
62
65
|
'.mjs': dynamicImport,
|
|
63
|
-
'.
|
|
66
|
+
'.mts': dynamicImport,
|
|
67
|
+
'.ts': dynamicImport,
|
|
64
68
|
'.yaml': yamlParse,
|
|
65
69
|
'.yml': yamlParse,
|
|
66
|
-
[NO_EXT]: yamlParse,
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
const readFile = async (filepath) => {
|
|
70
73
|
const absolutePath = path.resolve(filepath)
|
|
71
|
-
|
|
72
|
-
return await file.toString()
|
|
74
|
+
return fs.readFile(absolutePath, 'utf-8')
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
const loadConfigByExt = async (filepath) => {
|
package/lib/messages.js
CHANGED
|
@@ -77,12 +77,11 @@ export const PREVENTED_EMPTY_COMMIT = `
|
|
|
77
77
|
Use the --allow-empty option to continue, or check your task configuration`)}
|
|
78
78
|
`
|
|
79
79
|
|
|
80
|
-
export const RESTORE_STASH_EXAMPLE = `
|
|
80
|
+
export const RESTORE_STASH_EXAMPLE = `Any lost modifications can be restored from a git stash:
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
`
|
|
82
|
+
> git stash list
|
|
83
|
+
stash@{0}: automatic lint-staged backup
|
|
84
|
+
> git stash apply --index stash@{0}`
|
|
86
85
|
|
|
87
86
|
export const CONFIG_STDIN_ERROR = chalk.redBright(`${error} Failed to read config from stdin.`)
|
|
88
87
|
|
package/lib/runAll.js
CHANGED
|
@@ -291,8 +291,8 @@ export const runAll = async (
|
|
|
291
291
|
const runner = new Listr(
|
|
292
292
|
[
|
|
293
293
|
{
|
|
294
|
-
title: 'Preparing lint-staged...',
|
|
295
|
-
task: (ctx) => git.prepare(ctx),
|
|
294
|
+
title: ctx.shouldBackup ? 'Backing up original state...' : 'Preparing lint-staged...',
|
|
295
|
+
task: (ctx, task) => git.prepare(ctx, task),
|
|
296
296
|
},
|
|
297
297
|
{
|
|
298
298
|
title: 'Hiding unstaged changes to partially staged files...',
|
package/lib/state.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
export const getInitialState = ({ quiet = false } = {}) => ({
|
|
13
13
|
hasPartiallyStagedFiles: null,
|
|
14
14
|
shouldBackup: null,
|
|
15
|
+
backupHash: null,
|
|
15
16
|
shouldHidePartiallyStaged: true,
|
|
16
17
|
errors: new Set([]),
|
|
17
18
|
events: new EventEmitter(),
|
|
@@ -40,6 +41,7 @@ export const restoreUnstagedChangesSkipped = (ctx) => {
|
|
|
40
41
|
if (ctx.errors.has(GitError)) {
|
|
41
42
|
return GIT_ERROR
|
|
42
43
|
}
|
|
44
|
+
|
|
43
45
|
// Should be skipped when tasks fail
|
|
44
46
|
if (ctx.errors.has(TaskError)) {
|
|
45
47
|
return TASK_ERROR
|
|
@@ -67,13 +69,10 @@ export const cleanupEnabled = (ctx) => ctx.shouldBackup
|
|
|
67
69
|
|
|
68
70
|
export const cleanupSkipped = (ctx) => {
|
|
69
71
|
// Should be skipped in case of unknown git errors
|
|
70
|
-
if (
|
|
71
|
-
ctx.errors.has(GitError) &&
|
|
72
|
-
!ctx.errors.has(ApplyEmptyCommitError) &&
|
|
73
|
-
!ctx.errors.has(RestoreUnstagedChangesError)
|
|
74
|
-
) {
|
|
72
|
+
if (restoreOriginalStateSkipped(ctx)) {
|
|
75
73
|
return GIT_ERROR
|
|
76
74
|
}
|
|
75
|
+
|
|
77
76
|
// Should be skipped when reverting to original state fails
|
|
78
77
|
if (ctx.errors.has(RestoreOriginalStateError)) {
|
|
79
78
|
return GIT_ERROR
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
type SyncFunctionTask = (stagedFileNames: string[]) => string | string[]
|
|
2
|
+
|
|
3
|
+
type AsyncFunctionTask = (stagedFileNames: string[]) => Promise<string | string[]>
|
|
4
|
+
|
|
5
|
+
type FunctionTask = SyncFunctionTask | AsyncFunctionTask
|
|
6
|
+
|
|
7
|
+
export type Configuration =
|
|
8
|
+
| Record<string, string | FunctionTask | (string | FunctionTask)[]>
|
|
9
|
+
| FunctionTask
|
|
10
|
+
|
|
11
|
+
export type Options = {
|
|
12
|
+
/**
|
|
13
|
+
* Allow empty commits when tasks revert all staged changes
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
allowEmpty?: boolean
|
|
17
|
+
/**
|
|
18
|
+
* The number of tasks to run concurrently, or `false` to run tasks serially
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
concurrent?: boolean | number
|
|
22
|
+
/**
|
|
23
|
+
* Manual task configuration; disables automatic config file discovery when used
|
|
24
|
+
*/
|
|
25
|
+
config?: Configuration
|
|
26
|
+
/**
|
|
27
|
+
* Path to single configuration file; disables automatic config file discovery when used
|
|
28
|
+
*/
|
|
29
|
+
configPath?: string
|
|
30
|
+
/**
|
|
31
|
+
* Working directory to run all tasks in, defaults to current working directory
|
|
32
|
+
*/
|
|
33
|
+
cwd?: string
|
|
34
|
+
/**
|
|
35
|
+
* Whether or not to enable debug output
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
debug?: boolean
|
|
39
|
+
/**
|
|
40
|
+
* Override the default `--staged` flag of `git diff` to get list of files.
|
|
41
|
+
* @warn changing this also implies `stash: false`.
|
|
42
|
+
* @example HEAD...origin/main
|
|
43
|
+
*/
|
|
44
|
+
diff?: string
|
|
45
|
+
/**
|
|
46
|
+
* Override the default `--diff-filter=ACMR` flag of `git diff` to get list of files
|
|
47
|
+
* @default "ACMR"
|
|
48
|
+
*/
|
|
49
|
+
diffFilter?: string
|
|
50
|
+
/**
|
|
51
|
+
* Maximum argument string length, by default automatically detected
|
|
52
|
+
*/
|
|
53
|
+
maxArgLength?: number
|
|
54
|
+
/**
|
|
55
|
+
* Disable lint-staged’s own console output
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
quiet?: boolean
|
|
59
|
+
/**
|
|
60
|
+
* Pass filepaths relative to `CWD` to tasks, instead of absolute
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
relative?: boolean
|
|
64
|
+
/**
|
|
65
|
+
* Skip parsing of tasks for better shell support
|
|
66
|
+
* @default false
|
|
67
|
+
*/
|
|
68
|
+
shell?: boolean
|
|
69
|
+
/**
|
|
70
|
+
* Enable the backup stash, and revert in case of errors.
|
|
71
|
+
* @warn Disabling this also implies `hidePartiallyStaged: false`.
|
|
72
|
+
* @default true
|
|
73
|
+
*/
|
|
74
|
+
stash?: boolean
|
|
75
|
+
/**
|
|
76
|
+
* Whether to hide unstaged changes from partially staged files before running tasks
|
|
77
|
+
* @default true
|
|
78
|
+
*/
|
|
79
|
+
hidePartiallyStaged?: boolean
|
|
80
|
+
/**
|
|
81
|
+
* Show task output even when tasks succeed; by default only failed output is shown
|
|
82
|
+
* @default false
|
|
83
|
+
*/
|
|
84
|
+
verbose?: boolean
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
type LogFunction = (...params: any) => void
|
|
88
|
+
|
|
89
|
+
type Logger = {
|
|
90
|
+
log: LogFunction
|
|
91
|
+
warn: LogFunction
|
|
92
|
+
error: LogFunction
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @returns {boolean} `true` when linting was successful, `false` when some tasks failed with errors
|
|
97
|
+
* @throws {Error} when failed to some other errors
|
|
98
|
+
*/
|
|
99
|
+
type lintStaged = (options: Options, logger?: Logger) => Promise<boolean>
|
|
100
|
+
|
|
101
|
+
export default lintStaged
|
package/lib/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lint-staged",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.4.0",
|
|
4
4
|
"description": "Lint files staged by git",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/lint-staged/lint-staged",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"./bin": "./bin/lint-staged.js",
|
|
24
24
|
"./package.json": "./package.json"
|
|
25
25
|
},
|
|
26
|
+
"types": "lib/types.d.ts",
|
|
26
27
|
"files": [
|
|
27
28
|
"bin",
|
|
28
29
|
"lib"
|
|
@@ -31,12 +32,13 @@
|
|
|
31
32
|
"lint": "eslint .",
|
|
32
33
|
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jest --coverage",
|
|
33
34
|
"test:watch": "npm run test -- --watch",
|
|
35
|
+
"typecheck": "tsc --noEmit --strict test/unit/types.ts",
|
|
34
36
|
"version": "npx changeset version",
|
|
35
37
|
"postversion": "npm i --package-lock-only && git commit -am \"chore(changeset): release\"",
|
|
36
38
|
"tag": "npx changeset tag"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
|
-
"chalk": "~5.
|
|
41
|
+
"chalk": "~5.4.1",
|
|
40
42
|
"commander": "~12.1.0",
|
|
41
43
|
"debug": "~4.4.0",
|
|
42
44
|
"execa": "~8.0.1",
|
|
@@ -49,16 +51,16 @@
|
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
53
|
"@changesets/changelog-github": "0.5.0",
|
|
52
|
-
"@changesets/cli": "2.27.
|
|
53
|
-
"@commitlint/cli": "19.6.
|
|
54
|
+
"@changesets/cli": "2.27.11",
|
|
55
|
+
"@commitlint/cli": "19.6.1",
|
|
54
56
|
"@commitlint/config-conventional": "19.6.0",
|
|
55
|
-
"@eslint/js": "9.
|
|
57
|
+
"@eslint/js": "9.17.0",
|
|
56
58
|
"consolemock": "1.1.0",
|
|
57
59
|
"cross-env": "7.0.3",
|
|
58
|
-
"eslint": "9.
|
|
60
|
+
"eslint": "9.17.0",
|
|
59
61
|
"eslint-config-prettier": "9.1.0",
|
|
60
|
-
"eslint-plugin-jest": "28.
|
|
61
|
-
"eslint-plugin-n": "17.15.
|
|
62
|
+
"eslint-plugin-jest": "28.10.0",
|
|
63
|
+
"eslint-plugin-n": "17.15.1",
|
|
62
64
|
"eslint-plugin-prettier": "5.2.1",
|
|
63
65
|
"eslint-plugin-simple-import-sort": "12.1.1",
|
|
64
66
|
"husky": "9.1.7",
|
|
@@ -66,7 +68,8 @@
|
|
|
66
68
|
"jest-snapshot-serializer-ansi": "2.1.0",
|
|
67
69
|
"mock-stdin": "1.0.0",
|
|
68
70
|
"prettier": "3.4.2",
|
|
69
|
-
"semver": "7.6.3"
|
|
71
|
+
"semver": "7.6.3",
|
|
72
|
+
"typescript": "5.7.3"
|
|
70
73
|
},
|
|
71
74
|
"keywords": [
|
|
72
75
|
"lint",
|