src,test: fix config file parsing for flags defaulted to true

PR-URL: https://github.com/nodejs/node/pull/59110
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Edy Silva 2025-07-20 01:47:16 -03:00 committed by GitHub
parent c8d5b394e4
commit ab694d5661
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 0 deletions

View file

@ -55,6 +55,10 @@ ParseResult ConfigReader::ProcessOptionValue(
if (result) {
// If the value is true, we need to set the flag
output->push_back(option_name);
} else {
// Ensure negation is made putting the "--no-" prefix
output->push_back("--no-" +
option_name.substr(2, option_name.size() - 2));
}
break;

5
test/fixtures/rc/warnings-false.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
"nodeOptions": {
"warnings": false
}
}

View file

@ -60,6 +60,17 @@ test('should parse boolean flag', async () => {
strictEqual(result.code, 0);
});
test('should parse boolean flag defaulted to true', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-config-file',
fixtures.path('rc/warnings-false.json'),
'-p', 'process.emitWarning("A warning")',
]);
strictEqual(result.stderr, '');
strictEqual(result.stdout, 'undefined\n');
strictEqual(result.code, 0);
});
test('should throw an error when a flag is declared twice', async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',