Skip to content

Commit 1e3b3dc

Browse files
committed
Remove auto-camelcasing of settings
1 parent 5546bb5 commit 1e3b3dc

File tree

3 files changed

+28
-60
lines changed

3 files changed

+28
-60
lines changed

lib/parse-argv.js

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555

5656
import assert from 'node:assert/strict'
5757
import {parse as commaParse} from 'comma-separated-tokens'
58-
import camelcase from 'camelcase'
5958
import json5 from 'json5'
6059
import minimist from 'minimist'
6160
import table from 'text-table'
@@ -110,33 +109,31 @@ while (++index < schema.length) {
110109
// eslint-disable-next-line complexity
111110
export function parseArgv(flags, options) {
112111
/** @type {Record<string, Array<string> | string | boolean | undefined>} */
113-
const miniconfig = minimist(flags, minischema)
112+
const config = minimist(flags, minischema)
114113
let index = -1
115114

116115
// Fix defaults: minimist only understand `null`, not `undefined`, so we had to use `null`.
117116
// But we want `undefined`, so clean it here.
118117
/** @type {string} */
119118
let key
120119

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
124123
}
125124
}
126125

127126
// Crash on passed but missing string values.
128127
while (++index < schema.length) {
129128
const field = schema[index]
130-
if (field.type === 'string' && miniconfig[field.long] === '') {
129+
if (field.type === 'string' && config[field.long] === '') {
131130
throw new Error('Missing value: ' + inspect(field).join(' ').trimStart())
132131
}
133132
}
134133

135-
const config = toCamelCase(miniconfig)
136-
137134
// Make sure we parsed everything correctly.
138135
// Minimist guarantees that `''` is an array of strings.
139-
assert(Array.isArray(config['']))
136+
assert(Array.isArray(config._))
140137
// Minimist guarantees that our booleans are never strings.
141138
// Most have defaults, so they’re not `undefined`.
142139
assert(typeof config.color === 'boolean')
@@ -147,19 +144,23 @@ export function parseArgv(flags, options) {
147144
assert(typeof config.inspect === 'boolean')
148145
assert(typeof config.quiet === 'boolean')
149146
assert(typeof config.silent === 'boolean')
150-
assert(typeof config.silentlyIgnore === 'boolean')
147+
assert(typeof config['silently-ignore'] === 'boolean')
151148
assert(typeof config.tree === 'boolean')
152149
assert(typeof config.version === 'boolean')
153150
assert(typeof config.watch === 'boolean')
154151
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+
)
157158

158159
// The rest are strings, never booleans, but with minimist they could be
159160
// arrays.
160161
// `ignore-path-resolve-from` is an enum.
161162
const ignorePathResolveFrom = undefinedIfBoolean(
162-
lastIfArray(config.ignorePathResolveFrom)
163+
lastIfArray(config['ignore-path-resolve-from'])
163164
)
164165

165166
if (
@@ -174,14 +175,15 @@ export function parseArgv(flags, options) {
174175
)
175176
}
176177

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']))
180181
const output = lastIfArray(config.output)
181182

182183
const ext = parseIfString(joinIfArray(undefinedIfBoolean(config.ext))) || []
183184
const ignorePattern =
184-
parseIfString(joinIfArray(undefinedIfBoolean(config.ignorePattern))) || []
185+
parseIfString(joinIfArray(undefinedIfBoolean(config['ignore-pattern']))) ||
186+
[]
185187

186188
const setting = toArray(undefinedIfBoolean(config.setting)) || []
187189
/** @type {Record<string, unknown>} */
@@ -229,7 +231,7 @@ export function parseArgv(flags, options) {
229231
detectIgnore: config.ignore,
230232
extensions: ext.length === 0 ? options.extensions : ext,
231233
filePath,
232-
files: config[''],
234+
files: config._,
233235
frail: config.frail,
234236
ignoreName: options.ignoreName,
235237
ignorePath,
@@ -249,10 +251,10 @@ export function parseArgv(flags, options) {
249251
reporterOptions,
250252
settings,
251253
silent: config.silent,
252-
silentlyIgnore: config.silentlyIgnore,
254+
silentlyIgnore: config['silently-ignore'],
253255
tree: config.tree,
254-
treeIn: config.treeIn,
255-
treeOut: config.treeOut
256+
treeIn: config['tree-in'],
257+
treeOut: config['tree-out']
256258
}
257259
}
258260
}
@@ -286,7 +288,7 @@ function generateHelpMessage(options) {
286288
}
287289

288290
/**
289-
* Parse configuration, as JSON5, and camelcase the result.
291+
* Parse configuration as JSON5.
290292
*
291293
* @param {string} value
292294
* Settings.
@@ -302,7 +304,7 @@ function parseConfig(value, cache) {
302304
let flag
303305

304306
try {
305-
flags = toCamelCase(json5.parse('{' + value + '}'))
307+
flags = json5.parse('{' + value + '}')
306308
} catch (error) {
307309
const cause = /** @type {Error} */ (error)
308310
cause.message = cause.message.replace(/at(?= position)/, 'around')
@@ -415,39 +417,6 @@ function splitOptions(value) {
415417
: [value.slice(0, index), value.slice(index + 1)]
416418
}
417419

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-
451420
/**
452421
* @template {unknown} T
453422
* Value.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
],
3333
"dependencies": {
3434
"@types/text-table": "^0.2.0",
35-
"camelcase": "^8.0.0",
3635
"chalk": "^5.0.0",
3736
"chokidar": "^3.0.0",
3837
"comma-separated-tokens": "^2.0.0",

test/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ test('args', async function (t) {
310310
// Parser and Compiler both log stringified settings.
311311
assert.deepEqual(
312312
[result.stdout, cleanError(result.stderr)],
313-
['{"fooBar":"baz"}\none', 'one.txt: no issues found']
313+
['{"foo-bar":"baz"}\none', 'one.txt: no issues found']
314314
)
315315
})
316316
}
@@ -675,7 +675,7 @@ test('args', async function (t) {
675675
await t.test('should support `--watch`', async function () {
676676
// On Windows, `SIGINT` crashes immediately and results in an error.
677677
// Hence `reject: false`, `exitCode`, and extra lines when non-windows.
678-
const delay = 500
678+
const delay = 1000
679679
const url = new URL('watch.txt', base)
680680

681681
await fs.writeFile(url, 'alpha')
@@ -712,7 +712,7 @@ test('args', async function (t) {
712712
})
713713

714714
await t.test('should not regenerate when watching', async function () {
715-
const delay = 500
715+
const delay = 1000
716716
const url = new URL('watch.txt', base)
717717

718718
await fs.writeFile(url, 'alpha')

0 commit comments

Comments
 (0)