Skip to content

Commit cbe6e90

Browse files
author
Zhenya.Liu
committed
fix: string field with false value in asconfig.js
1 parent 145cbc6 commit cbe6e90

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

tests/cli/options.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ optionsUtil.addDefaults(config, merged);
5252
assert.deepStrictEqual(merged.enable, ["a", "c"]);
5353
assert.deepStrictEqual(merged.disable, ["b", "d"]);
5454
assert.deepStrictEqual(merged.other, ["x"]);
55+
56+
let value = optionsUtil.sanitizeValue(false, "s");
57+
assert.deepStrictEqual(value, null);

util/options.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ export function resolvePath(path: string, baseDir: string, useNodeResolution?: b
6868

6969
/** Populates default values on a parsed options result. */
7070
export function addDefaults(config: Config, options: OptionSet): void;
71+
72+
/** Sanitizes an option value to be a valid value of the option's type. */
73+
export function sanitizeValue(value: any, type: string): boolean | number | string | null | number[] | string[]; // eslint-disable-line @typescript-eslint/no-explicit-any

util/options.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export function help(config, options) {
141141
}
142142

143143
/** Sanitizes an option value to be a valid value of the option's type. */
144-
function sanitizeValue(value, type) {
144+
export function sanitizeValue(value, type) {
145145
if (value != null) {
146146
switch (type) {
147147
case undefined:
@@ -150,6 +150,7 @@ function sanitizeValue(value, type) {
150150
case "f": return Number(value) || 0;
151151
case "s": {
152152
if (value === true) return "";
153+
if (value === false) return null;
153154
return String(value);
154155
}
155156
case "I": {
@@ -233,6 +234,7 @@ export function merge(config, currentOptions, parentOptions, parentBaseDir) {
233234
return mergedOptions;
234235
}
235236

237+
236238
/** Normalizes a path. */
237239
export function normalizePath(p) {
238240
const parsed = path.parse(p);

0 commit comments

Comments
 (0)