fix: reject non-boolean --matches-stack values instead of eating a positional - #47
Open
alerizzo wants to merge 1 commit into
Open
fix: reject non-boolean --matches-stack values instead of eating a positional#47alerizzo wants to merge 1 commit into
alerizzo wants to merge 1 commit into
Conversation
…sitional
Code review caught a real bug in the new flag. Commander's optional-value
syntax (`[value]`) greedily consumes the next token, so
codacy patterns gh my-org my-repo --matches-stack eslint
parsed as matchesStack=true with `eslint` silently swallowed, and then failed
with "Ambiguous arguments for 'patterns'. Expected 1 or 4 positional
arguments, got 3." — an error that never mentions the flag that ate the tool
name. Every test and doc example placed the flag after the tool name, so the
broken ordering was never exercised.
`--matches-stack` now uses a new `strictBooleanOption()` that accepts only
true/false and otherwise errors immediately, naming the flag and the offending
value and saying where to put the argument. The three specified behaviours
(bare flag, explicit true, explicit false) are unchanged.
Also drops the redundant tri-state re-derivation in patterns.ts: Commander
already yields exactly true | false | undefined, so the value is passed
through directly.
`issues --false-positives` keeps the lax parser and the same latent hazard —
left alone to keep this change in scope, and flagged as a follow-up in
SPECS/commands/tools-and-patterns.md.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 13 |
| Duplication | 0 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull Request Overview
No merge-blocking issues were identified. Codacy reports the PR is up to standards. The only noted gap is missing coverage for forwarding --matches-stack values in bulk update mode while excluding the filter from the post-update overview request.
Test suggestions
- Strict parser accepts true and false, case-insensitively.
- Strict parser rejects non-boolean and empty values with a descriptive InvalidArgumentError.
- Misordered positional argument after
--matches-stackfails before calling the patterns API. - Bare, true, and false matches-stack values preserve tri-state behavior in patterns list mode.
- Matches-stack values are forwarded correctly in bulk update mode and excluded from the overview request.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Matches-stack values are forwarded correctly in bulk update mode and excluded from the overview request.
TIP How was this review? Give us feedback
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.
Follow-up to #45, which merged before this fix existed. The bug is on
mainbut has not been released — thepatterns-matches-stackchangeset is still pending — so no user has seen it.The bug
Commander's optional-value syntax (
[value]) greedily consumes the next token, including one meant as a positional.patternstakestoolNameas its 4th positional, so:eslintwas silently swallowed as the flag's value (matchesStack=true), and the error never mentions--matches-stack— so a user who did supply a tool name is told their positional count is wrong.--matches-stackis the command's first optional-value option; every other option onpatternsis either a plain boolean (never consumes a token) or a required-value<value>option (consumption is the point). Every test and doc example in #45 placed the flag after the tool name, so the broken ordering was never exercised.The fix
A new
strictBooleanOption()insrc/utils/options.tsaccepts onlytrue/falseand otherwise errors immediately:The three specified behaviours are unchanged: bare flag →
true,true→true,false→false.Also drops a redundant tri-state re-derivation in
patterns.ts— Commander already yields exactlytrue | false | undefined, so the value is now passed through directly.Deliberately not changed
issues --false-positives [value]uses the laxparseBooleanOptionand has the same swallow hazard (issues --false-positives gh org repowould eatgh). Switching it would change existing, shipped behaviour —--false-positives bananacurrently meanstrue— so it's left alone and flagged as a follow-up inSPECS/commands/tools-and-patterns.md. Happy to do it here if you'd rather.Test plan
npm run check-types— cleannpm test— 630 passing (was 625; +5)Verified against
codacy/codacy-cloud-cli/eslint9:trueandfalsestill return disjoint sets (100 vs 21 under--categories Security).🤖 Generated with Claude Code