Skip to content

Commit 0b5c8cb

Browse files
committed
fix: normalize scanUsage option to boolean
The scanUsage option was not passed through toBool(), so string values like "false" were treated as truthy. Use toBool() when the value is provided while preserving the !compare default when it is not. Closes #310
1 parent 94e8619 commit 0b5c8cb

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/config/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function normalizeOptions(raw: RawOptions): Options {
3939
const noColor = toBool(raw.noColor);
4040
const compare = toBool(raw.compare);
4141
const strict = toBool(raw.strict);
42-
const scanUsage = raw.scanUsage ?? !compare;
42+
const scanUsage = raw.scanUsage != null ? toBool(raw.scanUsage) : !compare;
4343

4444
const showUnused = raw.showUnused !== false;
4545
const showStats = raw.showStats !== false;

test/unit/config/options.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,9 @@ describe('normalizeOptions', () => {
8484
expect(normalizeOptions({}).scanUsage).toBe(true);
8585
expect(normalizeOptions({ compare: true }).scanUsage).toBe(false);
8686
});
87+
88+
it('normalizes scanUsage string values to boolean', () => {
89+
expect(normalizeOptions({ scanUsage: 'true' as unknown as boolean }).scanUsage).toBe(true);
90+
expect(normalizeOptions({ scanUsage: 'false' as unknown as boolean }).scanUsage).toBe(false);
91+
});
8792
});

0 commit comments

Comments
 (0)