lint-staged 7.2.2 → 7.3.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 +16 -8
- package/package.json +1 -1
- package/src/generateTasks.js +7 -5
package/README.md
CHANGED
|
@@ -133,15 +133,10 @@ To extend and customise lint-staged, advanced options are available. To use thes
|
|
|
133
133
|
{
|
|
134
134
|
"lint-staged": {
|
|
135
135
|
"linters": {
|
|
136
|
-
"*.{js,scss}": [
|
|
137
|
-
"some command",
|
|
138
|
-
"git add"
|
|
139
|
-
]
|
|
136
|
+
"*.{js,scss}": ["some command", "git add"]
|
|
140
137
|
},
|
|
141
|
-
"ignore": [
|
|
142
|
-
|
|
143
|
-
]
|
|
144
|
-
},
|
|
138
|
+
"ignore": ["**/dist/*.min.js"]
|
|
139
|
+
}
|
|
145
140
|
}
|
|
146
141
|
```
|
|
147
142
|
|
|
@@ -346,3 +341,16 @@ If you wish to use `lint-staged` in a multi package monorepo, it is recommended
|
|
|
346
341
|
[`lerna`](https://github.com/lerna/lerna) can be used to execute the `precommit` script in all sub-packages.
|
|
347
342
|
|
|
348
343
|
Example repo: [sudo-suhas/lint-staged-multi-pkg](https://github.com/sudo-suhas/lint-staged-multi-pkg).
|
|
344
|
+
|
|
345
|
+
### Can I lint files outside of the current project folder?
|
|
346
|
+
|
|
347
|
+
tl;dr: Yes, but the pattern should start with `../`.
|
|
348
|
+
|
|
349
|
+
By default, `lint-staged` executes linters only on the files present inside the project folder(where `lint-staged` is installed and run from).
|
|
350
|
+
So this question is relevant _only_ when the project folder is a child folder inside the git repo.
|
|
351
|
+
In certain project setups, it might be desirable to bypass this restriction. See [#425](https://github.com/okonet/lint-staged/issues/425), [#487](https://github.com/okonet/lint-staged/issues/487) for more context.
|
|
352
|
+
|
|
353
|
+
`lint-staged` provides an escape hatch for the same(`>= v7.3.0`). For patterns that start with `../`, all the staged files are allowed to match against the pattern.
|
|
354
|
+
Note that patterns like `*.js`, `**/*.js` will still only match the project files and not any of the files in parent or sibling directories.
|
|
355
|
+
|
|
356
|
+
Example repo: [sudo-suhas/lint-staged-django-react-demo](https://github.com/sudo-suhas/lint-staged-django-react-demo).
|
package/package.json
CHANGED
package/src/generateTasks.js
CHANGED
|
@@ -8,7 +8,7 @@ const resolveGitDir = require('./resolveGitDir')
|
|
|
8
8
|
|
|
9
9
|
const debug = require('debug')('lint-staged:gen-tasks')
|
|
10
10
|
|
|
11
|
-
module.exports = function generateTasks(config,
|
|
11
|
+
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
|
|
@@ -17,16 +17,18 @@ module.exports = function generateTasks(config, relFiles) {
|
|
|
17
17
|
|
|
18
18
|
const gitDir = resolveGitDir()
|
|
19
19
|
const cwd = process.cwd()
|
|
20
|
-
const
|
|
20
|
+
const stagedFiles = stagedRelFiles.map(file => path.resolve(gitDir, file))
|
|
21
21
|
|
|
22
22
|
return Object.keys(linters).map(pattern => {
|
|
23
|
+
const isParentDirPattern = pattern.startsWith('../')
|
|
23
24
|
const patterns = [pattern].concat(ignorePatterns)
|
|
24
25
|
const commands = linters[pattern]
|
|
25
26
|
|
|
26
27
|
const fileList = micromatch(
|
|
27
|
-
|
|
28
|
-
// Only worry about children of the CWD
|
|
29
|
-
|
|
28
|
+
stagedFiles
|
|
29
|
+
// Only worry about children of the CWD unless the pattern explicitly
|
|
30
|
+
// specifies that it concerns a parent directory.
|
|
31
|
+
.filter(file => isParentDirPattern || pathIsInside(file, cwd))
|
|
30
32
|
// Make the paths relative to CWD for filtering
|
|
31
33
|
.map(file => path.relative(cwd, file)),
|
|
32
34
|
patterns,
|