-
Notifications
You must be signed in to change notification settings - Fork 26
feat(lint): add more lint checks #446
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the CLI linting functionality by adding three new lint checks and improving error message clarity for invalid default subcommands.
Changes:
- Added validation for commands with
subcommand_required=truebut no defined subcommands - Added warning for variadic arguments that aren't positioned last
- Added validation to prevent count flags from having arguments (conflicting semantics)
- Enhanced error messages for invalid default subcommands to display available options
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cli/src/cli/lint.rs
Outdated
| let valid: Vec<_> = spec.cmd.subcommands.keys().collect(); | ||
| let hint = if valid.is_empty() { | ||
| "no subcommands defined".to_string() | ||
| } else { | ||
| format!("valid subcommands: {}", valid.iter().map(|s| s.as_str()).collect::<Vec<_>>().join(", ")) |
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intermediate collect::<Vec<_>>() is unnecessary. You can join the iterator directly without collecting it first. Consider changing to: valid.iter().map(|s| s.as_str()).collect::<Vec<_>>().join(\", \") → valid.iter().map(|s| s.as_str()).collect::<Vec<_>>().join(\", \"). Actually, even better would be to avoid the double collect by using valid.join(\", \") directly since valid is already a Vec<&String>.
| let valid: Vec<_> = spec.cmd.subcommands.keys().collect(); | |
| let hint = if valid.is_empty() { | |
| "no subcommands defined".to_string() | |
| } else { | |
| format!("valid subcommands: {}", valid.iter().map(|s| s.as_str()).collect::<Vec<_>>().join(", ")) | |
| let valid: Vec<String> = spec.cmd.subcommands.keys().cloned().collect(); | |
| let hint = if valid.is_empty() { | |
| "no subcommands defined".to_string() | |
| } else { | |
| format!("valid subcommands: {}", valid.join(", ")) |
3edb2c8 to
96b57c8
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #446 +/- ##
==========================================
+ Coverage 44.81% 45.36% +0.55%
==========================================
Files 47 47
Lines 7145 7221 +76
Branches 7145 7221 +76
==========================================
+ Hits 3202 3276 +74
+ Misses 1992 1987 -5
- Partials 1951 1958 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
96b57c8 to
9264a19
Compare
New checks: - subcommand-required-no-subcommands: command has subcommand_required=true but no subcommands defined (error) - variadic-arg-not-last: variadic argument is not the last argument (warning) - count-flag-with-arg: count flag also has an argument, which is conflicting semantics (error) Improvements: - invalid-default-subcommand now shows valid subcommands in the error message Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
9264a19 to
ab08e6e
Compare
Summary
Adds new lint checks and improves error messages:
New checks:
subcommand-required-no-subcommandssubcommand_required=truebut no subcommands definedvariadic-arg-not-lastcount-flag-with-argImprovements:
invalid-default-subcommanderror now shows the list of valid subcommandsExample output:
🤖 Generated with Claude Code
Note
Adds additional validation and clearer errors in CLI spec linting.
subcommand-required-no-subcommands(error):subcommand_required=truebut no subcommandsvariadic-arg-not-last(warning): variadic arg appears before the last positioncount-flag-with-arg(error): count flag also has an argumentinvalid-default-subcommandto include valid subcommands in the messageWritten by Cursor Bugbot for commit ab08e6e. This will update automatically on new commits. Configure here.