lint-staged 10.2.11 → 10.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 +33 -5
- package/bin/lint-staged.js +1 -1
- package/lib/formatConfig.js +7 -0
- package/lib/gitWorkflow.js +2 -1
- package/lib/index.js +3 -1
- package/package.json +18 -18
package/README.md
CHANGED
|
@@ -189,14 +189,40 @@ For example:
|
|
|
189
189
|
|
|
190
190
|
going to execute `eslint` and if it exits with `0` code, it will execute `prettier --write` on all staged `*.js` files.
|
|
191
191
|
|
|
192
|
-
## Using JS
|
|
192
|
+
## Using JS configuration file
|
|
193
193
|
|
|
194
|
-
|
|
194
|
+
Writing the configuration file in JavaScript is the most powerful way to configure _lint-staged_ (`lint-staged.config.js`, [similar](https://github.com/okonet/lint-staged/README.md#configuration), or passed via `--config`). From the configuration file, you can export either a single function, or an object.
|
|
195
|
+
|
|
196
|
+
If the `exports` value is a function, it will receive an array of all staged filenames. You can then build your own matchers for the files, and return a command string, or an array or command strings. These strings are considered complete and should include the filename arguments, if wanted.
|
|
197
|
+
|
|
198
|
+
If the `exports` value is an object, its keys should be glob matches (like in the normal non-js config format). The values can either be like in the normal config, or individual functions like described above. Instead of receiving all matched files, the functions in the exported object will only receive the staged files matching the corresponding glob key.
|
|
199
|
+
|
|
200
|
+
### Function signature
|
|
201
|
+
|
|
202
|
+
The function can also be async:
|
|
195
203
|
|
|
196
204
|
```ts
|
|
197
|
-
|
|
205
|
+
(filenames: string[]) => string | string[] | Promise<string | string[]>
|
|
198
206
|
```
|
|
199
207
|
|
|
208
|
+
### Example: Export a function to build your own matchers
|
|
209
|
+
|
|
210
|
+
```js
|
|
211
|
+
// lint-staged.config.js
|
|
212
|
+
const micromatch = require('micromatch')
|
|
213
|
+
|
|
214
|
+
module.exports = (allStagedFiles) => {
|
|
215
|
+
const shFiles = micromatch(allStagedFiles, ['**/src/**/*.sh']);
|
|
216
|
+
if (shFiles.length) {
|
|
217
|
+
return `printf '%s\n' "Script files aren't allowed in src directory" >&2`
|
|
218
|
+
}
|
|
219
|
+
const codeFiles = micromatch(allStagedFiles, ['**/*.js', '**/*.ts']);
|
|
220
|
+
const docFiles = micromatch(allStagedFiles, ['**/*.md']);
|
|
221
|
+
return [`eslint ${codeFiles.join(' ')}`, `mdl ${docFiles.join(' ')}`];
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
|
|
200
226
|
### Example: Wrap filenames in single quotes and run once per file
|
|
201
227
|
|
|
202
228
|
```js
|
|
@@ -226,6 +252,7 @@ module.exports = {
|
|
|
226
252
|
```
|
|
227
253
|
|
|
228
254
|
### Example: Use your own globs
|
|
255
|
+
It's better to use the [function-based configuration (seen above)](https://github.com/okonet/lint-staged/README.md#example-export-a-function-to-build-your-own-matchers), if your use case is this.
|
|
229
256
|
|
|
230
257
|
```js
|
|
231
258
|
// lint-staged.config.js
|
|
@@ -233,8 +260,9 @@ const micromatch = require('micromatch')
|
|
|
233
260
|
|
|
234
261
|
module.exports = {
|
|
235
262
|
'*': (allFiles) => {
|
|
236
|
-
const
|
|
237
|
-
|
|
263
|
+
const codeFiles = micromatch(allFiles, ['**/*.js', '**/*.ts']);
|
|
264
|
+
const docFiles = micromatch(allFiles, ['**/*.md']);
|
|
265
|
+
return [`eslint ${codeFiles.join(' ')}`, `mdl ${docFiles.join(' ')}`];
|
|
238
266
|
}
|
|
239
267
|
}
|
|
240
268
|
```
|
package/bin/lint-staged.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
// Force colors for packages that depend on https://www.npmjs.com/package/supports-color
|
|
6
6
|
const { supportsColor } = require('chalk')
|
|
7
|
-
if (supportsColor) {
|
|
7
|
+
if (supportsColor && supportsColor.level) {
|
|
8
8
|
process.env.FORCE_COLOR = supportsColor.level.toString()
|
|
9
9
|
}
|
|
10
10
|
|
package/lib/gitWorkflow.js
CHANGED
|
@@ -53,6 +53,7 @@ const GIT_DIFF_ARGS = [
|
|
|
53
53
|
'--src-prefix=a/', // force prefix for consistent behaviour
|
|
54
54
|
'--dst-prefix=b/', // force prefix for consistent behaviour
|
|
55
55
|
'--patch', // output a patch that can be applied
|
|
56
|
+
'--submodule=short', // always use the default short format for submodules
|
|
56
57
|
]
|
|
57
58
|
const GIT_APPLY_ARGS = ['-v', '--whitespace=nowarn', '--recount', '--unidiff-zero']
|
|
58
59
|
|
|
@@ -99,7 +100,7 @@ class GitWorkflow {
|
|
|
99
100
|
ctx.errors.add(GetBackupStashError)
|
|
100
101
|
throw new Error('lint-staged automatic backup is missing!')
|
|
101
102
|
}
|
|
102
|
-
return `stash@{${index}}`
|
|
103
|
+
return `refs/stash@{${index}}`
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
/**
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const { PREVENTED_EMPTY_COMMIT, GIT_ERROR, RESTORE_STASH_EXAMPLE } = require('./
|
|
|
9
9
|
const printTaskOutput = require('./printTaskOutput')
|
|
10
10
|
const runAll = require('./runAll')
|
|
11
11
|
const { ApplyEmptyCommitError, GetBackupStashError, GitError } = require('./symbols')
|
|
12
|
+
const formatConfig = require('./formatConfig')
|
|
12
13
|
const validateConfig = require('./validateConfig')
|
|
13
14
|
|
|
14
15
|
const errConfigNotFound = new Error('Config could not be found')
|
|
@@ -88,7 +89,8 @@ module.exports = async function lintStaged(
|
|
|
88
89
|
debugLog('Successfully loaded config from `%s`:\n%O', resolved.filepath, resolved.config)
|
|
89
90
|
// resolved.config is the parsed configuration object
|
|
90
91
|
// resolved.filepath is the path to the config file that was found
|
|
91
|
-
const
|
|
92
|
+
const formattedConfig = formatConfig(resolved.config)
|
|
93
|
+
const config = validateConfig(formattedConfig)
|
|
92
94
|
if (debug) {
|
|
93
95
|
// Log using logger to be able to test through `consolemock`.
|
|
94
96
|
logger.log('Running lint-staged with the following config:')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lint-staged",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.4.0",
|
|
4
4
|
"description": "Lint files staged by git",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/okonet/lint-staged",
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"chalk": "^4.
|
|
36
|
-
"cli-truncate": "2.1.0",
|
|
37
|
-
"commander": "^
|
|
38
|
-
"cosmiconfig": "^
|
|
35
|
+
"chalk": "^4.1.0",
|
|
36
|
+
"cli-truncate": "^2.1.0",
|
|
37
|
+
"commander": "^6.0.0",
|
|
38
|
+
"cosmiconfig": "^7.0.0",
|
|
39
39
|
"debug": "^4.1.1",
|
|
40
40
|
"dedent": "^0.7.0",
|
|
41
|
-
"enquirer": "^2.3.
|
|
42
|
-
"execa": "^4.0.
|
|
43
|
-
"listr2": "^2.
|
|
41
|
+
"enquirer": "^2.3.6",
|
|
42
|
+
"execa": "^4.0.3",
|
|
43
|
+
"listr2": "^2.6.0",
|
|
44
44
|
"log-symbols": "^4.0.0",
|
|
45
45
|
"micromatch": "^4.0.2",
|
|
46
46
|
"normalize-path": "^3.0.0",
|
|
@@ -49,22 +49,22 @@
|
|
|
49
49
|
"stringify-object": "^3.3.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@babel/core": "^7.
|
|
53
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.
|
|
54
|
-
"@babel/preset-env": "^7.
|
|
52
|
+
"@babel/core": "^7.11.4",
|
|
53
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
|
|
54
|
+
"@babel/preset-env": "^7.11.0",
|
|
55
55
|
"babel-eslint": "10.1.0",
|
|
56
|
-
"babel-jest": "^26.0
|
|
56
|
+
"babel-jest": "^26.3.0",
|
|
57
57
|
"consolemock": "^1.1.0",
|
|
58
|
-
"eslint": "^7.
|
|
58
|
+
"eslint": "^7.7.0",
|
|
59
59
|
"eslint-config-prettier": "^6.11.0",
|
|
60
|
-
"eslint-plugin-import": "^2.
|
|
60
|
+
"eslint-plugin-import": "^2.22.0",
|
|
61
61
|
"eslint-plugin-node": "^11.1.0",
|
|
62
|
-
"eslint-plugin-prettier": "^3.1.
|
|
63
|
-
"fs-extra": "^9.0.
|
|
62
|
+
"eslint-plugin-prettier": "^3.1.4",
|
|
63
|
+
"fs-extra": "^9.0.1",
|
|
64
64
|
"husky": "^4.2.5",
|
|
65
|
-
"jest": "^26.
|
|
65
|
+
"jest": "^26.4.2",
|
|
66
66
|
"jest-snapshot-serializer-ansi": "^1.0.0",
|
|
67
|
-
"prettier": "^2.0
|
|
67
|
+
"prettier": "^2.1.0"
|
|
68
68
|
},
|
|
69
69
|
"config": {
|
|
70
70
|
"commitizen": {
|