Skip to content

Commit 73db492

Browse files
committed
fix: add --no-stash as hidden option for backwards-compatibility
1 parent ff320fb commit 73db492

File tree

5 files changed

+50
-18
lines changed

5 files changed

+50
-18
lines changed

bin/lint-staged.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@ require('please-upgrade-node')(
2222
})
2323
)
2424

25-
const cmdline = require('commander')
25+
const { Command, Option } = require('commander')
2626
const debugLib = require('debug')
2727
const lintStaged = require('../lib')
2828
const { CONFIG_STDIN_ERROR } = require('../lib/messages')
2929

3030
const debug = debugLib('lint-staged:bin')
3131

32-
cmdline
33-
.version(pkg.version)
32+
const program = new Command('lint-staged')
33+
34+
program.version(pkg.version)
35+
36+
program
3437
.option('--allow-empty', 'allow empty commits when tasks revert all staged changes', false)
3538
.option('-c, --config [path]', 'path to configuration file, or - to read from stdin')
3639
.option('-d, --debug', 'print additional debug information', false)
@@ -48,9 +51,13 @@ cmdline
4851
'show task output even when tasks succeed; by default only failed output is shown',
4952
false
5053
)
51-
.parse(process.argv)
5254

53-
if (cmdline.debug) {
55+
// Added for backwards-compatibility
56+
program.addOption(new Option('--no-stash').hideHelp())
57+
58+
program.parse(process.argv)
59+
60+
if (program.debug) {
5461
debugLib.enable('lint-staged*')
5562
}
5663

@@ -74,19 +81,20 @@ const getMaxArgLength = () => {
7481
}
7582
}
7683

77-
const cmdlineOptions = cmdline.opts()
84+
const programOpts = program.opts()
7885

7986
const options = {
80-
allowEmpty: !!cmdlineOptions.allowEmpty,
81-
concurrent: JSON.parse(cmdlineOptions.concurrent),
82-
configPath: cmdlineOptions.config,
83-
debug: !!cmdlineOptions.debug,
87+
allowEmpty: !!programOpts.allowEmpty,
88+
concurrent: JSON.parse(programOpts.concurrent),
89+
configPath: programOpts.config,
90+
debug: !!programOpts.debug,
8491
maxArgLength: getMaxArgLength() / 2,
85-
quiet: !!cmdlineOptions.quiet,
86-
relative: !!cmdlineOptions.relative,
87-
reset: !!cmdlineOptions.reset, // commander inverts `no-<x>` flags to `!x`
88-
shell: cmdlineOptions.shell /* Either a boolean or a string pointing to the shell */,
89-
verbose: !!cmdlineOptions.verbose,
92+
quiet: !!programOpts.quiet,
93+
relative: !!programOpts.relative,
94+
reset: !!programOpts.reset, // commander inverts `no-<x>` flags to `!x`
95+
shell: programOpts.shell /* Either a boolean or a string pointing to the shell */,
96+
stash: programOpts.stash /** kept for backwards-compatibility */,
97+
verbose: !!programOpts.verbose,
9098
}
9199

92100
debug('Options parsed from command-line:', options)

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ const lintStaged = async (
7373
relative = false,
7474
reset = true,
7575
shell = false,
76+
stash, // kept for backwards-compatibility
7677
verbose = false,
7778
} = {},
7879
logger = console
7980
) => {
80-
await validateOptions({ shell }, logger)
81+
await validateOptions({ shell, stash }, logger)
8182

8283
debugLog('Loading config using `cosmiconfig`')
8384

@@ -121,7 +122,7 @@ const lintStaged = async (
121122
maxArgLength,
122123
quiet,
123124
relative,
124-
reset,
125+
reset: reset || !!stash,
125126
shell,
126127
verbose,
127128
},

lib/messages.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ const DEPRECATED_GIT_ADD = yellow(
3838
`
3939
)
4040

41+
const DEPRECATED_NO_STASH = yellow(
42+
`${warning} The \`--no-stash\` option has been renamed to \`--no-reset\`.
43+
`
44+
)
45+
4146
const TASK_ERROR = 'Skipped because of errors from tasks.'
4247

4348
const SKIPPED_GIT_ERROR = 'Skipped because of previous git error.'
@@ -63,6 +68,7 @@ module.exports = {
6368
CONFIG_STDIN_ERROR,
6469
configurationError,
6570
DEPRECATED_GIT_ADD,
71+
DEPRECATED_NO_STASH,
6672
FAILED_GET_STAGED_FILES,
6773
GIT_ERROR,
6874
incorrectBraces,

lib/validateOptions.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { promises: fs, constants } = require('fs')
22

3-
const { invalidOption } = require('./messages')
3+
const { DEPRECATED_NO_STASH, invalidOption } = require('./messages')
44
const { InvalidOptionsError } = require('./symbols')
55

66
const debug = require('debug')('lint-staged:options')
@@ -25,6 +25,10 @@ const validateOptions = async (options = {}, logger) => {
2525
}
2626
}
2727

28+
if (typeof options.stash === 'boolean') {
29+
logger.warn(DEPRECATED_NO_STASH)
30+
}
31+
2832
debug('Validated options!')
2933
}
3034

test/validateOptions.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,17 @@ describe('validateOptions', () => {
6262
See https://github.com/okonet/lint-staged#command-line-flags"
6363
`)
6464
})
65+
66+
it('should warn when deprecated stash option is used', async () => {
67+
const logger = makeConsoleMock()
68+
69+
await expect(validateOptions({ stash: false }, logger)).resolves.toBeUndefined()
70+
71+
expect(logger.history()).toHaveLength(1)
72+
expect(logger.printHistory()).toMatchInlineSnapshot(`
73+
"
74+
WARN ⚠ The \`--no-stash\` option has been renamed to \`--no-reset\`.
75+
"
76+
`)
77+
})
6578
})

0 commit comments

Comments
 (0)