lint-staged 8.1.3 → 8.1.7
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 +12 -30
- package/package.json +6 -6
- package/src/generateTasks.js +6 -5
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Run linters against staged git files and don't let :poop: slip into your code base!
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://asciinema.org/a/199934)
|
|
6
6
|
|
|
7
7
|
## Why
|
|
8
8
|
|
|
@@ -21,41 +21,23 @@ This project contains a script that will run arbitrary shell tasks with a list o
|
|
|
21
21
|
|
|
22
22
|
## Installation and setup
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
The fastest way to start using lint-staged is to run following command in your terminal:
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
```bash
|
|
27
|
+
npx mrm lint-staged
|
|
28
|
+
```
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
+ "husky": {
|
|
33
|
-
+ "hooks": {
|
|
34
|
-
+ "pre-commit": "lint-staged"
|
|
35
|
-
+ }
|
|
36
|
-
+ },
|
|
37
|
-
+ "lint-staged": {
|
|
38
|
-
+ "*.js": ["eslint --fix", "git add"]
|
|
39
|
-
+ }
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Now change a few files, `git add` some of them to your commit and try to `git commit` them.
|
|
30
|
+
It will install and configure [husky](https://github.com/typicode/husky) and lint-staged depending on code quality tools from `package.json` dependencies so please make sure you install (`npm install --save-dev`) and configure all code quality tools like [Prettier](https://prettier.io), [ESlint](https://eslint.org) prior that.
|
|
44
31
|
|
|
45
|
-
|
|
32
|
+
Don't forget to commit changes to `package.json` to share this setup with your team!
|
|
46
33
|
|
|
47
|
-
|
|
48
|
-
<img src="./screenshots/lint-staged-prettier.gif" alt="lint-staged with prettier example"
|
|
49
|
-
width="640" height="432">
|
|
50
|
-
</p>
|
|
34
|
+
Now change a few files, `git add` or `git add --patch` some of them to your commit and try to `git commit` them.
|
|
51
35
|
|
|
52
|
-
See [examples](#examples) and [configuration](#configuration)
|
|
53
|
-
|
|
54
|
-
> I recommend using [husky](https://github.com/typicode/husky) to manage git hooks but you can use any other tool.
|
|
36
|
+
See [examples](#examples) and [configuration](#configuration) for more information.
|
|
55
37
|
|
|
56
38
|
## Changelog
|
|
57
39
|
|
|
58
|
-
[
|
|
40
|
+
See [Releases](https://github.com/okonet/lint-staged/releases)
|
|
59
41
|
|
|
60
42
|
## Command line flags
|
|
61
43
|
|
|
@@ -158,7 +140,7 @@ It is possible to run linters for certain paths only by using glob patterns. [mi
|
|
|
158
140
|
|
|
159
141
|
```js
|
|
160
142
|
{
|
|
161
|
-
// .js files anywhere in the project
|
|
143
|
+
// .js files anywhere in the root directory of the project
|
|
162
144
|
"*.js": "eslint",
|
|
163
145
|
// .js files anywhere in the project
|
|
164
146
|
"**/*.js": "eslint",
|
|
@@ -204,7 +186,7 @@ Tools like [Prettier](https://prettier.io), ESLint/TSLint, or stylelint can refo
|
|
|
204
186
|
|
|
205
187
|
```json
|
|
206
188
|
{
|
|
207
|
-
"*.js": ["
|
|
189
|
+
"*.js": ["prettier --write", "git add"]
|
|
208
190
|
}
|
|
209
191
|
```
|
|
210
192
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lint-staged",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.7",
|
|
4
4
|
"description": "Lint files staged by git",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/okonet/lint-staged",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"cz": "git-cz",
|
|
19
19
|
"lint:base": "eslint --rule \"prettier/prettier: 2\"",
|
|
20
20
|
"lint": "npm run lint:base -- .",
|
|
21
|
-
"lint:fix": "npm run lint --fix",
|
|
21
|
+
"lint:fix": "npm run lint -- --fix",
|
|
22
22
|
"pretest": "npm run lint",
|
|
23
23
|
"test": "jest --coverage",
|
|
24
24
|
"test:watch": "jest --watch"
|
|
@@ -29,10 +29,9 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@iamstarkov/listr-update-renderer": "0.4.1",
|
|
33
32
|
"chalk": "^2.3.1",
|
|
34
33
|
"commander": "^2.14.1",
|
|
35
|
-
"cosmiconfig": "^5.0
|
|
34
|
+
"cosmiconfig": "^5.2.0",
|
|
36
35
|
"debug": "^3.1.0",
|
|
37
36
|
"dedent": "^0.7.0",
|
|
38
37
|
"del": "^3.0.0",
|
|
@@ -42,7 +41,8 @@
|
|
|
42
41
|
"is-glob": "^4.0.0",
|
|
43
42
|
"is-windows": "^1.0.2",
|
|
44
43
|
"listr": "^0.14.2",
|
|
45
|
-
"
|
|
44
|
+
"listr-update-renderer": "^0.5.0",
|
|
45
|
+
"lodash": "^4.17.11",
|
|
46
46
|
"log-symbols": "^2.2.0",
|
|
47
47
|
"micromatch": "^3.1.8",
|
|
48
48
|
"npm-which": "^3.0.1",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"staged-git-files": "1.1.2",
|
|
54
54
|
"string-argv": "^0.0.2",
|
|
55
55
|
"stringify-object": "^3.2.2",
|
|
56
|
-
"yup": "^0.
|
|
56
|
+
"yup": "^0.27.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"babel-core": "^6.26.3",
|
package/src/generateTasks.js
CHANGED
|
@@ -12,8 +12,7 @@ module.exports = function generateTasks(config, stagedRelFiles) {
|
|
|
12
12
|
debug('Generating linter tasks')
|
|
13
13
|
|
|
14
14
|
const normalizedConfig = getConfig(config) // Ensure we have a normalized config
|
|
15
|
-
const { linters, globOptions } = normalizedConfig
|
|
16
|
-
const ignorePatterns = normalizedConfig.ignore.map(pattern => `!${pattern}`)
|
|
15
|
+
const { linters, globOptions, ignore } = normalizedConfig
|
|
17
16
|
|
|
18
17
|
const gitDir = resolveGitDir()
|
|
19
18
|
const cwd = process.cwd()
|
|
@@ -21,7 +20,6 @@ module.exports = function generateTasks(config, stagedRelFiles) {
|
|
|
21
20
|
|
|
22
21
|
return Object.keys(linters).map(pattern => {
|
|
23
22
|
const isParentDirPattern = pattern.startsWith('../')
|
|
24
|
-
const patterns = [pattern].concat(ignorePatterns)
|
|
25
23
|
const commands = linters[pattern]
|
|
26
24
|
|
|
27
25
|
const fileList = micromatch(
|
|
@@ -31,8 +29,11 @@ module.exports = function generateTasks(config, stagedRelFiles) {
|
|
|
31
29
|
.filter(file => isParentDirPattern || pathIsInside(file, cwd))
|
|
32
30
|
// Make the paths relative to CWD for filtering
|
|
33
31
|
.map(file => path.relative(cwd, file)),
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
pattern,
|
|
33
|
+
{
|
|
34
|
+
...globOptions,
|
|
35
|
+
ignore
|
|
36
|
+
}
|
|
36
37
|
).map(file => {
|
|
37
38
|
// if you set relative option, then the file path will be relative to your package.json
|
|
38
39
|
if (config.relative) {
|