Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: fix negated boolean options not removing implied options #56313

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

islandryu
Copy link
Contributor

When using negated options for boolean options that imply other options (e.g., --inspect-brk), the implied options are not removed as expected. This causes the implied option to remain active, leading to unexpected behavior.

shimaryuuheinoMac-mini:node shimaryuuhei$ node --inspect-brk --no-inspect-brk -e "console.log(\"foo\")"
Debugger listening on ws://127.0.0.1:9229/67479127-5d17-4027-b514-70217b2fe102
For help, see: https://nodejs.org/en/docs/inspector
foo

When using --no-inspect-brk, only the effect of the --inspect option remains.

This change ensures that when a negated option (e.g., --no-...) is used, any implied options are also removed. After this fix, the above example will no longer activate the implied options.

Alternative

Currently, the negated options affected by this change are not documented in the official CLI documentation: https://nodejs.org/api/cli.html

An alternative approach could be to remove these undocumented negated options entirely, ensuring no unexpected behavior arises from their usage.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Dec 19, 2024
Comment on lines -391 to -396
std::string implied_name = name;
if (is_negation) {
// Implications for negated options are defined with "--no-".
implied_name.insert(2, "no-");
}
auto implications = implications_.equal_range(implied_name);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the fix, there was likely code intended to apply negations to implications as well, but options with the --no- prefix were never added to the implications_.

Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.53%. Comparing base (0d00511) to head (6425807).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/node_options-inl.h 66.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56313      +/-   ##
==========================================
+ Coverage   88.04%   88.53%   +0.49%     
==========================================
  Files         657      657              
  Lines      190290   190288       -2     
  Branches    36245    36539     +294     
==========================================
+ Hits       167536   168474     +938     
+ Misses      15893    14985     -908     
+ Partials     6861     6829      -32     
Files with missing lines Coverage Δ
src/node_options-inl.h 79.83% <66.66%> (-0.58%) ⬇️

... and 94 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants