-
Notifications
You must be signed in to change notification settings - Fork 54
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
fix: improve error message from invalid pattern name #151
Conversation
WalkthroughThis update streamlines the handling and validation of pattern names within the codebase, particularly focusing on the removal of redundant declarations and enhancing the robustness of pattern name checks. By consolidating the Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 1
Review Status
Configuration used: CodeRabbit UI
Files ignored due to path filters (1)
crates/cli_bin/tests/snapshots/apply__config_pattern_with_invalid_name.snap
is excluded by!**/*.snap
Files selected for processing (9)
- crates/cli/src/commands/apply_pattern.rs (2 hunks)
- crates/cli/src/commands/plumbing.rs (2 hunks)
- crates/cli/src/resolver.rs (1 hunks)
- crates/cli/src/utils.rs (2 hunks)
- crates/cli_bin/fixtures/config_invalid_name/.grit/grit.yaml (1 hunks)
- crates/cli_bin/fixtures/config_invalid_name/test.js (1 hunks)
- crates/cli_bin/tests/apply.rs (1 hunks)
- crates/gritmodule/src/config.rs (2 hunks)
- crates/gritmodule/src/utils.rs (2 hunks)
Files not reviewed due to errors (1)
- (no review received)
Additional comments not posted (7)
crates/cli_bin/fixtures/config_invalid_name/test.js (1)
1-3
: LGTM! This JavaScript file is well-formed and serves its purpose as a test fixture.crates/cli_bin/fixtures/config_invalid_name/.grit/grit.yaml (1)
1-9
: LGTM! This.grit/grit.yaml
file is correctly formatted and serves its purpose as a test fixture for invalid pattern names.crates/cli/src/utils.rs (1)
1-1
: The removal of theis_pattern_name
function aligns with the PR's objective to centralize pattern name validation logic.crates/cli/src/resolver.rs (1)
35-35
: Adding the#[derive(Debug)]
attribute to theRichPattern
struct is a good practice for easier debugging.crates/cli/src/commands/plumbing.rs (1)
8-8
: Updating the import path foris_pattern_name
tomarzano_gritmodule::utils
aligns with the PR's objective to centralize pattern name validation logic.crates/gritmodule/src/config.rs (1)
276-278
: Validating pattern names usingis_pattern_name
before processing enhances the robustness of pattern handling and aligns with the PR's objectives to improve error messaging.crates/cli/src/commands/apply_pattern.rs (1)
21-21
: Updating the import path foris_pattern_name
tomarzano_gritmodule::utils
is consistent with the effort to centralize pattern name validation logic across the application.
pub fn is_pattern_name(pattern: &str) -> bool { | ||
let regex = Regex::new(r"^[a-zA-Z_][a-zA-Z0-9_]*(\(\))?$").unwrap(); | ||
regex.is_match(pattern) | ||
} |
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.
Replace unwrap()
with expect()
when creating the regex to provide a clearer error message in case the regex pattern is invalid.
- let regex = Regex::new(r"^[a-zA-Z_][a-zA-Z0-9_]*(\(\))?$").unwrap();
+ let regex = Regex::new(r"^[a-zA-Z_][a-zA-Z0-9_]*(\(\))?$").expect("Invalid regex pattern for is_pattern_name");
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
pub fn is_pattern_name(pattern: &str) -> bool { | |
let regex = Regex::new(r"^[a-zA-Z_][a-zA-Z0-9_]*(\(\))?$").unwrap(); | |
regex.is_match(pattern) | |
} | |
pub fn is_pattern_name(pattern: &str) -> bool { | |
let regex = Regex::new(r"^[a-zA-Z_][a-zA-Z0-9_]*(\(\))?$").expect("Invalid regex pattern for is_pattern_name"); | |
regex.is_match(pattern) | |
} |
fixes #134
Summary by CodeRabbit
grit.yaml
file for tagging errors and providing code transformations.Button
class in test files to extend component functionality.