diff --git a/tests/cli/options.js b/tests/cli/options.js index 637aae3493..666a3ee2d4 100644 --- a/tests/cli/options.js +++ b/tests/cli/options.js @@ -52,3 +52,6 @@ optionsUtil.addDefaults(config, merged); assert.deepStrictEqual(merged.enable, ["a", "c"]); assert.deepStrictEqual(merged.disable, ["b", "d"]); assert.deepStrictEqual(merged.other, ["x"]); + +let value = optionsUtil.sanitizeValue(false, "s"); +assert.deepStrictEqual(value, null); \ No newline at end of file diff --git a/util/options.d.ts b/util/options.d.ts index facc36d622..aa153a7483 100644 --- a/util/options.d.ts +++ b/util/options.d.ts @@ -68,3 +68,6 @@ export function resolvePath(path: string, baseDir: string, useNodeResolution?: b /** Populates default values on a parsed options result. */ export function addDefaults(config: Config, options: OptionSet): void; + +/** Sanitizes an option value to be a valid value of the option's type. */ +export function sanitizeValue(value: any, type: string): boolean | number | string | null | number[] | string[]; // eslint-disable-line @typescript-eslint/no-explicit-any \ No newline at end of file diff --git a/util/options.js b/util/options.js index d0633b19e2..40132fe155 100644 --- a/util/options.js +++ b/util/options.js @@ -141,7 +141,7 @@ export function help(config, options) { } /** Sanitizes an option value to be a valid value of the option's type. */ -function sanitizeValue(value, type) { +export function sanitizeValue(value, type) { if (value != null) { switch (type) { case undefined: @@ -150,6 +150,7 @@ function sanitizeValue(value, type) { case "f": return Number(value) || 0; case "s": { if (value === true) return ""; + if (value === false) return null; return String(value); } case "I": { @@ -233,6 +234,7 @@ export function merge(config, currentOptions, parentOptions, parentBaseDir) { return mergedOptions; } + /** Normalizes a path. */ export function normalizePath(p) { const parsed = path.parse(p);