Skip to content

Commit 1f67271

Browse files
committed
fix: default maxArgLength to undefined instead of NaN when parsing cli args
1 parent 2862964 commit 1f67271

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

.changeset/pretty-roses-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'lint-staged': patch
3+
---
4+
5+
Correctly set the `--max-arg-length` default value based on the running platform. This controls how very long lists of staged files are split into multiple chunks.

lib/cli.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ export const parseCliOptions = (argv) => {
167167
values['hide-unstaged'] = false // becomes redundant
168168
}
169169

170+
const maxArgLength =
171+
values['max-arg-length'] !== undefined ? parseInt(values['max-arg-length'], 10) : undefined
172+
173+
if (Number.isNaN(maxArgLength)) {
174+
throw new TypeError(`Option '--mar-arg-length' takes a numeric argument`, {
175+
cause: { '--max-arg-length': values['max-arg-length'] },
176+
})
177+
}
178+
170179
return {
171180
allowEmpty: values['allow-empty'] ?? false,
172181
concurrent: values.concurrent === undefined ? true : JSON.parse(values.concurrent),
@@ -181,7 +190,7 @@ export const parseCliOptions = (argv) => {
181190
hidePartiallyStaged: values['hide-partially-staged'] ?? true,
182191
hideUnstaged: !!values['hide-unstaged'],
183192
hideAll: !!values['hide-all'],
184-
maxArgLength: parseInt(values['max-arg-length'], 10),
193+
maxArgLength,
185194
quiet: !!values.quiet,
186195
relative: !!values.relative,
187196
revert: values.revert ?? true,

test/unit/cli.spec.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ suite('cli', () => {
2323
hidePartiallyStaged: true,
2424
hideUnstaged: false,
2525
hideAll: false,
26-
maxArgLength: NaN,
26+
maxArgLength: undefined,
2727
quiet: false,
2828
relative: false,
2929
revert: true,
@@ -78,7 +78,19 @@ suite('cli', () => {
7878
expect(options.concurrent).toBe(10)
7979
})
8080

81-
it('should parse max-arg-length option', ({ expect }) => {
81+
it('should throw when using max-arg-length without value', ({ expect }) => {
82+
expect(() => parseCliOptions(['--max-arg-length'])).toThrow(
83+
`Option '--max-arg-length <value>' argument missing`
84+
)
85+
})
86+
87+
it('should throw when using max-arg-length with non-numeric value', ({ expect }) => {
88+
expect(() => parseCliOptions(['--max-arg-length=test'])).toThrow(
89+
`Option '--mar-arg-length' takes a numeric argument`
90+
)
91+
})
92+
93+
it('should parse max-arg-length option as integer', ({ expect }) => {
8294
const options = parseCliOptions(['--max-arg-length=100'])
8395
expect(options.maxArgLength).toBe(100)
8496
})

0 commit comments

Comments
 (0)