lint-staged 7.1.2 → 7.2.2
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 +27 -7
- package/package.json +2 -3
- package/src/findBin.js +11 -3
- package/src/getConfig.js +1 -0
- package/src/index.js +15 -7
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ The latest versions of `lint-staged` require Node.js v6 or newer. (Versions of `
|
|
|
6
6
|
|
|
7
7
|
## Why
|
|
8
8
|
|
|
9
|
-
Linting makes more sense when
|
|
9
|
+
Linting makes more sense when run before committing your code. By doing so you can ensure no errors go into the repository and enforce code style. But running a lint process on a whole project is slow and linting results can be irrelevant. Ultimately you only want to lint files that will be committed.
|
|
10
10
|
|
|
11
11
|
This project contains a script that will run arbitrary shell tasks with a list of staged files as an argument, filtered by a specified glob pattern.
|
|
12
12
|
|
|
@@ -39,7 +39,7 @@ This project contains a script that will run arbitrary shell tasks with a list o
|
|
|
39
39
|
|
|
40
40
|
Now change a few files, `git add` some of them to your commit and try to `git commit` them.
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
This is how it looks in action:
|
|
43
43
|
|
|
44
44
|
<p align="center">
|
|
45
45
|
<img src="./screenshots/lint-staged-prettier.gif" alt="lint-staged with prettier example"
|
|
@@ -71,14 +71,14 @@ $ ./node_modules/.bin/lint-staged --help
|
|
|
71
71
|
Options:
|
|
72
72
|
|
|
73
73
|
-V, --version output the version number
|
|
74
|
-
-c, --config [path]
|
|
74
|
+
-c, --config [path] Configuration file path or package
|
|
75
75
|
-d, --debug Enable debug mode
|
|
76
76
|
-h, --help output usage information
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
* **`--config [path]`**: This can be used to manually specify the `lint-staged` config file location. However, if the specified file cannot be found, it will error out instead of performing the usual search.
|
|
79
|
+
* **`--config [path]`**: This can be used to manually specify the `lint-staged` config file location. However, if the specified file cannot be found, it will error out instead of performing the usual search. You may pass a npm package name for configuration also.
|
|
80
80
|
* **`--debug`**: Enabling the debug mode does the following:
|
|
81
|
-
* `lint-staged` uses the [debug](https://github.com/visionmedia/debug) module internally to log 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*`.
|
|
81
|
+
* `lint-staged` uses the [debug](https://github.com/visionmedia/debug) module internally to log 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*`.
|
|
82
82
|
* Use the [`verbose` renderer](https://github.com/SamVerschueren/listr-verbose-renderer) for `listr`.
|
|
83
83
|
* Do not pass `--silent` to npm scripts.
|
|
84
84
|
|
|
@@ -125,9 +125,29 @@ So, considering you did `git add file1.ext file2.ext`, lint-staged will run the
|
|
|
125
125
|
|
|
126
126
|
### Advanced config format
|
|
127
127
|
|
|
128
|
-
To
|
|
128
|
+
To extend and customise lint-staged, advanced options are available. To use these options the format should be as the following:
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
#### `package.json` example with `ignore` option:
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"lint-staged": {
|
|
135
|
+
"linters": {
|
|
136
|
+
"*.{js,scss}": [
|
|
137
|
+
"some command",
|
|
138
|
+
"git add"
|
|
139
|
+
]
|
|
140
|
+
},
|
|
141
|
+
"ignore": [
|
|
142
|
+
"**/dist/*.min.js"
|
|
143
|
+
]
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Notice that the linting commands now are nested into the `linters` object. The following options are available for advance configuration:
|
|
149
|
+
|
|
150
|
+
#### Options
|
|
131
151
|
|
|
132
152
|
* `concurrent` — _true_ — runs linters for each glob pattern simultaneously. If you don’t want this, you can set `concurrent: false`
|
|
133
153
|
* `chunkSize` — Max allowed chunk size based on number of files for glob pattern. This option is only applicable on Windows based systems to avoid command length limitations. See [#147](https://github.com/okonet/lint-staged/issues/147)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lint-staged",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.2",
|
|
4
4
|
"description": "Lint files staged by git",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/okonet/lint-staged",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"test:watch": "jest --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"app-root-path": "^2.0.1",
|
|
32
31
|
"chalk": "^2.3.1",
|
|
33
32
|
"commander": "^2.14.1",
|
|
34
33
|
"cosmiconfig": "^5.0.2",
|
|
@@ -38,7 +37,7 @@
|
|
|
38
37
|
"find-parent-dir": "^0.3.0",
|
|
39
38
|
"is-glob": "^4.0.0",
|
|
40
39
|
"is-windows": "^1.0.2",
|
|
41
|
-
"jest-validate": "^
|
|
40
|
+
"jest-validate": "^23.5.0",
|
|
42
41
|
"listr": "^0.14.1",
|
|
43
42
|
"lodash": "^4.17.5",
|
|
44
43
|
"log-symbols": "^2.2.0",
|
package/src/findBin.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const parse = require('string-argv')
|
|
4
|
-
const appRoot = require('app-root-path')
|
|
5
4
|
const npmWhich = require('npm-which')(process.cwd())
|
|
6
5
|
const checkPkgScripts = require('./checkPkgScripts')
|
|
7
6
|
|
|
8
|
-
// Find and load the package.json at the root of the project.
|
|
9
|
-
const pkg = require(appRoot.resolve('package.json')) // eslint-disable-line import/no-dynamic-require
|
|
10
7
|
const debug = require('debug')('lint-staged:find-bin')
|
|
11
8
|
|
|
9
|
+
// Find and load the package.json at the root of the project.
|
|
10
|
+
let pkg
|
|
11
|
+
try {
|
|
12
|
+
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
13
|
+
pkg = require(`${process.cwd()}/package.json`)
|
|
14
|
+
debug('Loaded package.json using `process.cwd()`')
|
|
15
|
+
} catch (ignore) {
|
|
16
|
+
debug('Could not load package.json using `process.cwd()`')
|
|
17
|
+
pkg = {}
|
|
18
|
+
}
|
|
19
|
+
|
|
12
20
|
const cache = new Map()
|
|
13
21
|
|
|
14
22
|
module.exports = function findBin(cmd) {
|
package/src/getConfig.js
CHANGED
|
@@ -138,6 +138,7 @@ function validateConfig(config) {
|
|
|
138
138
|
exampleConfig,
|
|
139
139
|
deprecatedConfig,
|
|
140
140
|
unknown: unknownValidationReporter,
|
|
141
|
+
recursive: false,
|
|
141
142
|
comment:
|
|
142
143
|
'Please refer to https://github.com/okonet/lint-staged#configuration for more information...'
|
|
143
144
|
})
|
package/src/index.js
CHANGED
|
@@ -18,20 +18,28 @@ if (process.stdout.isTTY) {
|
|
|
18
18
|
|
|
19
19
|
const errConfigNotFound = new Error('Config could not be found')
|
|
20
20
|
|
|
21
|
+
function resolveConfig(configPath) {
|
|
22
|
+
try {
|
|
23
|
+
return require.resolve(configPath)
|
|
24
|
+
} catch (ignore) {
|
|
25
|
+
return configPath
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
function loadConfig(configPath) {
|
|
22
30
|
const explorer = cosmiconfig('lint-staged', {
|
|
23
31
|
searchPlaces: [
|
|
24
32
|
'package.json',
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
'.lintstagedrc',
|
|
34
|
+
'.lintstagedrc.json',
|
|
35
|
+
'.lintstagedrc.yaml',
|
|
36
|
+
'.lintstagedrc.yml',
|
|
37
|
+
'.lintstagedrc.js',
|
|
38
|
+
'lint-staged.config.js'
|
|
31
39
|
]
|
|
32
40
|
})
|
|
33
41
|
|
|
34
|
-
return configPath ? explorer.load(configPath) : explorer.search()
|
|
42
|
+
return configPath ? explorer.load(resolveConfig(configPath)) : explorer.search()
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
/**
|