lint-staged 8.1.1 → 8.1.5

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 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
- The latest versions of `lint-staged` require Node.js v6 or newer. (Versions of `lint-staged` prior to v7 still work with Node.js v4.)
5
+ [![asciicast](https://asciinema.org/a/199934.svg)](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
- > A fast way to perform the below is to run `npx mrm lint-staged`. It does most of the setup for you.
24
+ The fastest way to start using lint-staged is to run following command in your terminal:
25
25
 
26
- 1. `npm install --save-dev lint-staged husky`
27
- 1. Install and setup your linters just like you would do normally. Add appropriate `.eslintrc`, `.stylelintrc`, etc.
28
- 1. Update your `package.json` like this:
26
+ ```bash
27
+ npx mrm lint-staged
28
+ ```
29
29
 
30
- ```diff json
31
- {
32
- + "husky": {
33
- + "hooks": {
34
- + "pre-commit": "lint-staged"
35
- + }
36
- + },
37
- + "lint-staged": {
38
- + "*.js": ["eslint --fix", "git add"]
39
- + }
40
- }
41
- ```
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.
42
31
 
43
- Now change a few files, `git add` some of them to your commit and try to `git commit` them.
32
+ Don't forget to commit changes to `package.json` to share this setup with your team!
44
33
 
45
- This is how it looks in action:
34
+ Now change a few files, `git add` or `git add --patch` some of them to your commit and try to `git commit` them.
46
35
 
47
- <p align="center">
48
- <img src="./screenshots/lint-staged-prettier.gif" alt="lint-staged with prettier example"
49
- width="640" height="432">
50
- </p>
51
-
52
- See [examples](#examples) and [configuration](#configuration) below.
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
- [releases](https://github.com/okonet/lint-staged/releases)
40
+ See [Releases](https://github.com/okonet/lint-staged/releases)
59
41
 
60
42
  ## Command line flags
61
43
 
@@ -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": ["eslint --fix", "git add"]
189
+ "*.js": ["prettier --write", "git add"]
208
190
  }
209
191
  ```
210
192
 
package/index.js CHANGED
@@ -3,11 +3,13 @@
3
3
  'use strict'
4
4
 
5
5
  const pkg = require('./package.json')
6
- require('please-upgrade-node')({
7
- engines: {
8
- node: '>=8.6.0'
9
- }
10
- })
6
+ require('please-upgrade-node')(
7
+ Object.assign({}, pkg, {
8
+ engines: {
9
+ node: '>=8.6.0'
10
+ }
11
+ })
12
+ )
11
13
 
12
14
  const cmdline = require('commander')
13
15
  const debugLib = require('debug')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "8.1.1",
3
+ "version": "8.1.5",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/okonet/lint-staged",
@@ -29,7 +29,6 @@
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
34
  "cosmiconfig": "^5.0.2",
@@ -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
- "lodash": "^4.17.5",
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",
@@ -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
- patterns,
35
- globOptions
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) {
package/src/runAll.js CHANGED
@@ -62,51 +62,54 @@ module.exports = function runAll(config) {
62
62
  renderer
63
63
  }
64
64
 
65
- if (tasks.length) {
66
- // Do not terminate main Listr process on SIGINT
67
- process.on('SIGINT', () => {})
65
+ // If all of the configured "linters" should be skipped
66
+ // avoid executing any lint-staged logic
67
+ if (tasks.every(task => task.skip())) {
68
+ console.log('No staged files match any of provided globs.')
69
+ return 'No tasks to run.'
70
+ }
68
71
 
69
- return new Listr(
70
- [
71
- {
72
- title: 'Stashing changes...',
73
- skip: async () => {
74
- const hasPSF = await git.hasPartiallyStagedFiles()
75
- if (!hasPSF) {
76
- return 'No partially staged files found...'
77
- }
78
- return false
79
- },
80
- task: ctx => {
81
- ctx.hasStash = true
82
- return git.gitStashSave()
72
+ // Do not terminate main Listr process on SIGINT
73
+ process.on('SIGINT', () => {})
74
+
75
+ return new Listr(
76
+ [
77
+ {
78
+ title: 'Stashing changes...',
79
+ skip: async () => {
80
+ const hasPSF = await git.hasPartiallyStagedFiles()
81
+ if (!hasPSF) {
82
+ return 'No partially staged files found...'
83
83
  }
84
+ return false
84
85
  },
85
- {
86
- title: 'Running linters...',
87
- task: () =>
88
- new Listr(tasks, {
89
- ...listrBaseOptions,
90
- concurrent,
91
- exitOnError: !concurrent // Wait for all errors when running concurrently
92
- })
93
- },
94
- {
95
- title: 'Updating stash...',
96
- enabled: ctx => ctx.hasStash,
97
- skip: ctx =>
98
- ctx.hasErrors && 'Skipping stash update since some tasks exited with errors',
99
- task: () => git.updateStash()
100
- },
101
- {
102
- title: 'Restoring local changes...',
103
- enabled: ctx => ctx.hasStash,
104
- task: () => git.gitStashPop()
86
+ task: ctx => {
87
+ ctx.hasStash = true
88
+ return git.gitStashSave()
105
89
  }
106
- ],
107
- listrBaseOptions
108
- ).run()
109
- }
110
- return 'No tasks to run.'
90
+ },
91
+ {
92
+ title: 'Running linters...',
93
+ task: () =>
94
+ new Listr(tasks, {
95
+ ...listrBaseOptions,
96
+ concurrent,
97
+ exitOnError: !concurrent // Wait for all errors when running concurrently
98
+ })
99
+ },
100
+ {
101
+ title: 'Updating stash...',
102
+ enabled: ctx => ctx.hasStash,
103
+ skip: ctx => ctx.hasErrors && 'Skipping stash update since some tasks exited with errors',
104
+ task: () => git.updateStash()
105
+ },
106
+ {
107
+ title: 'Restoring local changes...',
108
+ enabled: ctx => ctx.hasStash,
109
+ task: () => git.gitStashPop()
110
+ }
111
+ ],
112
+ listrBaseOptions
113
+ ).run()
111
114
  })
112
115
  }