Standardize command checks and add input validation#23
Conversation
- Replace `command -v` with zsh-idiomatic `(( ${+commands[X]} ))`
in rc.d/50-editor.zsh and rc.d/84-git-worktrees.zsh
- Add parameter validation to zush_lazy_load() in lib/lazy-loader.zsh
- Improve validation in zushp() with regex format checking
Fixes #18
Co-authored-by: Scott Hyndman <shyndman@users.noreply.github.com>
Pull Request Review: Standardize command checks and add input validationSummaryThis PR addresses issue #18 by standardizing command-existence checks and adding input validation to user-facing functions. The changes are well-aligned with the stated objectives and improve code consistency and error handling. ✅ Strengths1. Correct Use of Zsh IdiomsThe change from
2. Strong Input Validation in zush_lazy_load()lib/lazy-loader.zsh:89-98 - Excellent parameter validation:
3. Improved User/Repo Format Validation in zushp()lib/plugin.zsh:80-89 - Much better validation:
🔍 Areas for Consideration1. Incomplete Standardization in rc.d/The PR only addresses 2 of 7 files using
Recommendation: Consider expanding the scope to standardize all command checks in one pass, or create a follow-up issue to track the remaining conversions. Partial standardization can lead to confusion about which pattern to use. 2. Regex Pattern Edge CasesThe regex in lib/plugin.zsh:86 is generally good but could be more restrictive:
However, the current regex is probably good enough since git will fail gracefully anyway for invalid repos. 3. No Tests for New Validation LogicThe codebase appears to lack test files. While not introduced by this PR, the new validation logic would benefit from test coverage. 🐛 Potential IssuesNone identified - The implementation is solid. 🔒 Security Considerations✅ Improved Security PostureThe regex validation in
⚡ Performance Considerations✅ Minor Performance Improvement
📋 Code Quality✅ High Quality
🎯 Final RecommendationApprove with minor suggestions: This is a solid PR that successfully addresses the stated objectives. The code quality is high, security is improved, and the changes follow zsh best practices. Suggested next steps:
Nitpicks (totally optional):
Great work! 🚀 |
There was a problem hiding this comment.
Pull request overview
This PR standardizes command existence checks and enhances input validation across the zush codebase. The changes migrate from bash-compatible command -v patterns to zsh-idiomatic (( ${+commands[X]} )) syntax and add robust parameter validation to critical functions.
Key changes:
- Standardizes command existence checks using zsh's native
${+commands[X]}syntax in two files - Adds parameter validation to
zush_lazy_load()to prevent silent failures from missing arguments - Enhances
zushp()with regex-based format validation for user/repo input and consistent error handling
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| rc.d/84-git-worktrees.zsh | Replaces command -v git with zsh-idiomatic (( ${+commands[git]} )) check |
| rc.d/50-editor.zsh | Replaces command -v code with zsh-idiomatic (( ${+commands[code]} )) check |
| lib/lazy-loader.zsh | Adds validation for required tool and init_command parameters with descriptive error messages |
| lib/plugin.zsh | Improves validation with regex pattern matching for user/repo format and standardizes error handling using zush_error |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Show the actual value passed when validation fails in zush_lazy_load() and zushp() so users can easily identify their mistake.
command -vwith zsh-idiomatic(( ${+commands[X]} ))in rc.d/50-editor.zsh and rc.d/84-git-worktrees.zshFixes #18