Conversation
`parseArgs` checks `required` in the final `else if` of the per-argument
chain, but an `enum` argument is caught by the preceding `else if
(arg.type === "enum")` branch and never reaches it. `{ type: "enum",
required: true }` therefore parsed to `undefined` without error, while
`--help` still rendered the argument as `(Required)`, since `usage.ts`
reads `arg.required` for every non-positional type.
Handle the missing value inside the enum branch: throw the same
`Missing required argument: --<name>` error the other types produce.
A default still satisfies the check, because `parseRawArgs` has already
applied it by this point — matching how `required` behaves for strings.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughChangesEnum argument validation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Required enum arguments now consistently reject missing values while allowing defaults, with focused coverage for both behaviors. The change is ready to merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
required: trueis silently ignored fortype: "enum"arguments.parseArgsvalidates each argument through oneif / else ifchain, and the generic required check is the last branch:An enum argument always matches the
enumbranch, so it never reaches the required check. Omitting it yieldsundefinedinstead of an error:The inconsistency is visible in the help output too:
usage.tsreadsarg.requiredfor every non-positional type, so--helprenders the argument as(Required)while the parser does not enforce it.Change
The enum branch now handles the missing-value case itself and throws the same
Missing required argument: --<name>error the other types produce. The existing options check moves to theelse, so a supplied value is validated exactly as before.A default still satisfies the requirement —
parseRawArgshas already appliedparseOptions.defaultby this point, soparsedArgsProxy[arg.name]is defined. That matches howrequired+defaultbehave for string arguments today.Scope
Anyone relying on the current behaviour was declaring
required: trueand getting nothing for it, so this only turns a silentundefinedinto the documented error.Tests
Two cases added to
test/args.test.ts:Missing required argument: --value;defaultparses to the default.pnpm testpasses: 111 tests + 1 expected fail,oxlint/oxfmtclean,tsgo --noEmitclean.Summary by CodeRabbit
Bug Fixes
Tests