55
55
56
56
import assert from 'node:assert/strict'
57
57
import { parse as commaParse } from 'comma-separated-tokens'
58
- import camelcase from 'camelcase'
59
58
import json5 from 'json5'
60
59
import minimist from 'minimist'
61
60
import table from 'text-table'
@@ -110,33 +109,31 @@ while (++index < schema.length) {
110
109
// eslint-disable-next-line complexity
111
110
export function parseArgv ( flags , options ) {
112
111
/** @type {Record<string, Array<string> | string | boolean | undefined> } */
113
- const miniconfig = minimist ( flags , minischema )
112
+ const config = minimist ( flags , minischema )
114
113
let index = - 1
115
114
116
115
// Fix defaults: minimist only understand `null`, not `undefined`, so we had to use `null`.
117
116
// But we want `undefined`, so clean it here.
118
117
/** @type {string } */
119
118
let key
120
119
121
- for ( key in miniconfig ) {
122
- if ( miniconfig [ key ] === null ) {
123
- miniconfig [ key ] = undefined
120
+ for ( key in config ) {
121
+ if ( config [ key ] === null ) {
122
+ config [ key ] = undefined
124
123
}
125
124
}
126
125
127
126
// Crash on passed but missing string values.
128
127
while ( ++ index < schema . length ) {
129
128
const field = schema [ index ]
130
- if ( field . type === 'string' && miniconfig [ field . long ] === '' ) {
129
+ if ( field . type === 'string' && config [ field . long ] === '' ) {
131
130
throw new Error ( 'Missing value: ' + inspect ( field ) . join ( ' ' ) . trimStart ( ) )
132
131
}
133
132
}
134
133
135
- const config = toCamelCase ( miniconfig )
136
-
137
134
// Make sure we parsed everything correctly.
138
135
// Minimist guarantees that `''` is an array of strings.
139
- assert ( Array . isArray ( config [ '' ] ) )
136
+ assert ( Array . isArray ( config . _ ) )
140
137
// Minimist guarantees that our booleans are never strings.
141
138
// Most have defaults, so they’re not `undefined`.
142
139
assert ( typeof config . color === 'boolean' )
@@ -147,19 +144,23 @@ export function parseArgv(flags, options) {
147
144
assert ( typeof config . inspect === 'boolean' )
148
145
assert ( typeof config . quiet === 'boolean' )
149
146
assert ( typeof config . silent === 'boolean' )
150
- assert ( typeof config . silentlyIgnore === 'boolean' )
147
+ assert ( typeof config [ 'silently-ignore' ] === 'boolean' )
151
148
assert ( typeof config . tree === 'boolean' )
152
149
assert ( typeof config . version === 'boolean' )
153
150
assert ( typeof config . watch === 'boolean' )
154
151
assert ( config . stdout === undefined || typeof config . stdout === 'boolean' )
155
- assert ( config . treeIn === undefined || typeof config . treeIn === 'boolean' )
156
- assert ( config . treeOut === undefined || typeof config . treeOut === 'boolean' )
152
+ assert (
153
+ config [ 'tree-in' ] === undefined || typeof config [ 'tree-in' ] === 'boolean'
154
+ )
155
+ assert (
156
+ config [ 'tree-out' ] === undefined || typeof config [ 'tree-out' ] === 'boolean'
157
+ )
157
158
158
159
// The rest are strings, never booleans, but with minimist they could be
159
160
// arrays.
160
161
// `ignore-path-resolve-from` is an enum.
161
162
const ignorePathResolveFrom = undefinedIfBoolean (
162
- lastIfArray ( config . ignorePathResolveFrom )
163
+ lastIfArray ( config [ 'ignore-path-resolve-from' ] )
163
164
)
164
165
165
166
if (
@@ -174,14 +175,15 @@ export function parseArgv(flags, options) {
174
175
)
175
176
}
176
177
177
- const filePath = lastIfArray ( undefinedIfBoolean ( config . filePath ) )
178
- const ignorePath = lastIfArray ( undefinedIfBoolean ( config . ignorePath ) )
179
- const rcPath = lastIfArray ( undefinedIfBoolean ( config . rcPath ) )
178
+ const filePath = lastIfArray ( undefinedIfBoolean ( config [ 'file-path' ] ) )
179
+ const ignorePath = lastIfArray ( undefinedIfBoolean ( config [ 'ignore-path' ] ) )
180
+ const rcPath = lastIfArray ( undefinedIfBoolean ( config [ 'rc-path' ] ) )
180
181
const output = lastIfArray ( config . output )
181
182
182
183
const ext = parseIfString ( joinIfArray ( undefinedIfBoolean ( config . ext ) ) ) || [ ]
183
184
const ignorePattern =
184
- parseIfString ( joinIfArray ( undefinedIfBoolean ( config . ignorePattern ) ) ) || [ ]
185
+ parseIfString ( joinIfArray ( undefinedIfBoolean ( config [ 'ignore-pattern' ] ) ) ) ||
186
+ [ ]
185
187
186
188
const setting = toArray ( undefinedIfBoolean ( config . setting ) ) || [ ]
187
189
/** @type {Record<string, unknown> } */
@@ -229,7 +231,7 @@ export function parseArgv(flags, options) {
229
231
detectIgnore : config . ignore ,
230
232
extensions : ext . length === 0 ? options . extensions : ext ,
231
233
filePath,
232
- files : config [ '' ] ,
234
+ files : config . _ ,
233
235
frail : config . frail ,
234
236
ignoreName : options . ignoreName ,
235
237
ignorePath,
@@ -249,10 +251,10 @@ export function parseArgv(flags, options) {
249
251
reporterOptions,
250
252
settings,
251
253
silent : config . silent ,
252
- silentlyIgnore : config . silentlyIgnore ,
254
+ silentlyIgnore : config [ 'silently-ignore' ] ,
253
255
tree : config . tree ,
254
- treeIn : config . treeIn ,
255
- treeOut : config . treeOut
256
+ treeIn : config [ 'tree-in' ] ,
257
+ treeOut : config [ 'tree-out' ]
256
258
}
257
259
}
258
260
}
@@ -286,7 +288,7 @@ function generateHelpMessage(options) {
286
288
}
287
289
288
290
/**
289
- * Parse configuration, as JSON5, and camelcase the result .
291
+ * Parse configuration as JSON5.
290
292
*
291
293
* @param {string } value
292
294
* Settings.
@@ -302,7 +304,7 @@ function parseConfig(value, cache) {
302
304
let flag
303
305
304
306
try {
305
- flags = toCamelCase ( json5 . parse ( '{' + value + '}' ) )
307
+ flags = json5 . parse ( '{' + value + '}' )
306
308
} catch ( error ) {
307
309
const cause = /** @type {Error } */ ( error )
308
310
cause . message = cause . message . replace ( / a t (? = p o s i t i o n ) / , 'around' )
@@ -415,39 +417,6 @@ function splitOptions(value) {
415
417
: [ value . slice ( 0 , index ) , value . slice ( index + 1 ) ]
416
418
}
417
419
418
- /**
419
- * Transform the keys on an object to camelcase, recursivly.
420
- *
421
- * @template {Record<string, unknown>} T
422
- * Record.
423
- * @param {T } object
424
- * Value.
425
- * @returns {T }
426
- * Camelcased record.
427
- */
428
- function toCamelCase ( object ) {
429
- const result = /** @type {T } */ ( { } )
430
- /** @type {keyof T } */
431
- let key
432
-
433
- for ( key in object ) {
434
- if ( own . call ( object , key ) ) {
435
- /** @type {keyof T } */
436
- const camelcased = camelcase ( key )
437
- let value = object [ key ]
438
-
439
- if ( value && typeof value === 'object' && ! Array . isArray ( value ) ) {
440
- // @ts -expect-error: objects are indexable.
441
- value = toCamelCase ( value )
442
- }
443
-
444
- result [ camelcased ] = value
445
- }
446
- }
447
-
448
- return result
449
- }
450
-
451
420
/**
452
421
* @template {unknown} T
453
422
* Value.
0 commit comments