Skip to content

Comments

cli: allow unary-negated eval arguments#61962

Open
jorgitin02 wants to merge 1 commit intonodejs:mainfrom
jorgitin02:fix/43397-cli-eval-unary-negation
Open

cli: allow unary-negated eval arguments#61962
jorgitin02 wants to merge 1 commit intonodejs:mainfrom
jorgitin02:fix/43397-cli-eval-unary-negation

Conversation

@jorgitin02
Copy link

Fixes: #43397

Summary

  • treat unary-negated eval inputs as expressions (e.g. -42, -0, -NaN) instead of missing option args
  • preserve option safety so -e -p still reports missing eval argument
  • add regression coverage in test/parallel/test-cli-eval.js for unary-negation and nearby safety paths

Testing

  • python3 tools/test.py test/parallel/test-cli-eval.js
  • python3 tools/test.py --repeat=5 test/parallel/test-cli-eval.js
  • python3 tools/test.py test/parallel/test-cli-eval.js test/parallel/test-cli-bad-options.js
  • make lint-cpp
  • make lint-js NODE=$(command -v node)
  • scripts/agent-preflight.sh

Fixes: nodejs#43397
Signed-off-by: jorge guerrero <grrr.jrg@gmail.com>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. config Issues or PRs related to the config subsystem needs-ci PRs that need a full CI run. labels Feb 24, 2026
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 24, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 24, 2026
@nodejs-github-bot
Copy link
Collaborator

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 31.81818% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.73%. Comparing base (da5efc4) to head (2086d8c).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/node_options-inl.h 31.81% 7 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61962      +/-   ##
==========================================
+ Coverage   88.84%   89.73%   +0.89%     
==========================================
  Files         674      672       -2     
  Lines      204957   204545     -412     
  Branches    39309    39276      -33     
==========================================
+ Hits       182087   183557    +1470     
+ Misses      15088    13306    -1782     
+ Partials     7782     7682     -100     
Files with missing lines Coverage Δ
src/node_options-inl.h 79.92% <31.81%> (-3.21%) ⬇️

... and 122 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

From the ticket:

For users who prefer setting mandatory option arguments rather than positional arguments, node --print --eval=-42 already works. :)

I think that's the right solution here. Adding behavior that depends on the specific text passed to the flag is going to be dangerous; now you cannot know anymore whether node -e -<text> will work or throw, it's going to depend on the specific value of text (i.e. the behavior is less consistent now, not more).

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++. config Issues or PRs related to the config subsystem needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node CLI eval option can't take unary negation operator

4 participants