Skip to content

fix: propagate --no- negation to aliases and main option - #225

Merged
pi0 merged 1 commit into
unjs:mainfrom
kaigritun:fix/negated-alias-propagation
Feb 12, 2026
Merged

pi0 merged 1 commit into
unjs:mainfrom
kaigritun:fix/negated-alias-propagation

Conversation

@kaigritun

Copy link
Copy Markdown
Contributor

Summary

Fixes #209

When using --no-flag syntax with an alias (e.g., --no-v where v is an alias for verbose), the negation now correctly propagates to both the alias and the main option, overwriting any default values.

Problem

Previously, --no-v would set v=false but leave verbose=true (if verbose had a default of true) because the propagation logic only copied values when the target was undefined.

For example:

const result = parseRawArgs(['--no-v'], {
  boolean: ['verbose'],
  alias: { v: ['verbose'] },
  default: { verbose: true },
});
// Before: { v: false, verbose: true }  // Bug!
// After:  { v: false, verbose: false } // Fixed!

Solution

When applying negated flags, resolve to both:

  1. The main option name (if the flag is an alias)
  2. All aliases (if the flag is the main option)

This ensures negated flags work consistently regardless of whether you use --no-main or --no-alias.

Tests

Added 3 test cases:

  • --no- negation on main option
  • --no- negation on alias propagates to main option
  • --no- negation on main option propagates to aliases

All 57 tests pass.

When using --no-flag syntax with an alias (e.g., --no-v where v is an alias
for verbose), the negation now correctly propagates to both the alias and
the main option, overwriting any default values.

Previously, --no-v would set v=false but leave verbose=true (if verbose had
a default of true) because the propagation logic only copied values when
the target was undefined.

Fixes unjs#209

@pi0 pi0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thnx!

@pi0
pi0 merged commit 7393b4b into unjs:main Feb 12, 2026
2 checks passed
@codecov

codecov Bot commented Feb 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@b7a18fa). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #225   +/-   ##
=======================================
  Coverage        ?   96.96%           
=======================================
  Files           ?        7           
  Lines           ?      297           
  Branches        ?      116           
=======================================
  Hits            ?      288           
  Misses          ?        8           
  Partials        ?        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

@MichaelDeBoey

Copy link
Copy Markdown

I'm not making any claims about the quality of their work, but I wanted to let you know that @kaigritun is a fully-autonomous non-human actor
https://socket.dev/blog/ai-agent-lands-prs-in-major-oss-projects-targets-maintainers-via-cold-outreach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative flag parsing too permissive (e.g. --no-b-alias, -no-boolean)

3 participants