lint-staged 10.4.2 → 10.5.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 +2 -2
- package/bin/lint-staged.js +20 -1
- package/lib/messages.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ Options:
|
|
|
62
62
|
-V, --version output the version number
|
|
63
63
|
--allow-empty allow empty commits when tasks revert all staged changes
|
|
64
64
|
(default: false)
|
|
65
|
-
-c, --config [path] path to configuration file
|
|
65
|
+
-c, --config [path] path to configuration file, or - to read from stdin
|
|
66
66
|
-d, --debug print additional debug information (default: false)
|
|
67
67
|
--no-stash disable the backup stash, and do not revert in case of
|
|
68
68
|
errors
|
|
@@ -78,7 +78,7 @@ Options:
|
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
- **`--allow-empty`**: By default, when linter tasks undo all staged changes, lint-staged will exit with an error and abort the commit. Use this flag to allow creating empty git commits.
|
|
81
|
-
- **`--config [path]`**: Manually specify a path to a config file or npm package name. Note: when used, lint-staged won't perform the config file search and print an error if the specified file cannot be found.
|
|
81
|
+
- **`--config [path]`**: Manually specify a path to a config file or npm package name. Note: when used, lint-staged won't perform the config file search and print an error if the specified file cannot be found. If '-' is provided as the filename then the config will be read from stdin, allowing piping in the config like `cat my-config.json | npx lint-staged --config -`.
|
|
82
82
|
- **`--debug`**: Run in debug mode. When set, it does the following:
|
|
83
83
|
- uses [debug](https://github.com/visionmedia/debug) internally to log additional 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*`.
|
|
84
84
|
- uses [`verbose` renderer](https://github.com/SamVerschueren/listr-verbose-renderer) for `listr`; this causes serial, uncoloured output to the terminal, instead of the default (beautified, dynamic) output.
|
package/bin/lint-staged.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
'use strict'
|
|
4
4
|
|
|
5
|
+
const fs = require('fs')
|
|
6
|
+
|
|
5
7
|
// Force colors for packages that depend on https://www.npmjs.com/package/supports-color
|
|
6
8
|
const { supportsColor } = require('chalk')
|
|
7
9
|
if (supportsColor && supportsColor.level) {
|
|
@@ -23,13 +25,14 @@ require('please-upgrade-node')(
|
|
|
23
25
|
const cmdline = require('commander')
|
|
24
26
|
const debugLib = require('debug')
|
|
25
27
|
const lintStaged = require('../lib')
|
|
28
|
+
const { CONFIG_STDIN_ERROR } = require('../lib/messages')
|
|
26
29
|
|
|
27
30
|
const debug = debugLib('lint-staged:bin')
|
|
28
31
|
|
|
29
32
|
cmdline
|
|
30
33
|
.version(pkg.version)
|
|
31
34
|
.option('--allow-empty', 'allow empty commits when tasks revert all staged changes', false)
|
|
32
|
-
.option('-c, --config [path]', 'path to configuration file')
|
|
35
|
+
.option('-c, --config [path]', 'path to configuration file, or - to read from stdin')
|
|
33
36
|
.option('-d, --debug', 'print additional debug information', false)
|
|
34
37
|
.option('--no-stash', 'disable the backup stash, and do not revert in case of errors', false)
|
|
35
38
|
.option(
|
|
@@ -86,6 +89,22 @@ const options = {
|
|
|
86
89
|
|
|
87
90
|
debug('Options parsed from command-line:', options)
|
|
88
91
|
|
|
92
|
+
if (options.configPath === '-') {
|
|
93
|
+
delete options.configPath
|
|
94
|
+
try {
|
|
95
|
+
options.config = fs.readFileSync(process.stdin.fd, 'utf8').toString().trim()
|
|
96
|
+
} catch {
|
|
97
|
+
console.error(CONFIG_STDIN_ERROR)
|
|
98
|
+
process.exit(1)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
options.config = JSON.parse(options.config)
|
|
103
|
+
} catch {
|
|
104
|
+
// Let config parsing complain if it's not JSON
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
89
108
|
lintStaged(options)
|
|
90
109
|
.then((passed) => {
|
|
91
110
|
process.exitCode = passed ? 0 : 1
|
package/lib/messages.js
CHANGED
|
@@ -39,6 +39,8 @@ const RESTORE_STASH_EXAMPLE = ` Any lost modifications can be restored from a g
|
|
|
39
39
|
> git stash apply --index stash@{0}
|
|
40
40
|
`
|
|
41
41
|
|
|
42
|
+
const CONFIG_STDIN_ERROR = 'Error: Could not read config from stdin.'
|
|
43
|
+
|
|
42
44
|
module.exports = {
|
|
43
45
|
NOT_GIT_REPO,
|
|
44
46
|
FAILED_GET_STAGED_FILES,
|
|
@@ -51,4 +53,5 @@ module.exports = {
|
|
|
51
53
|
GIT_ERROR,
|
|
52
54
|
PREVENTED_EMPTY_COMMIT,
|
|
53
55
|
RESTORE_STASH_EXAMPLE,
|
|
56
|
+
CONFIG_STDIN_ERROR,
|
|
54
57
|
}
|