-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
lowAin't annoying anyone but the QA departmentAin't annoying anyone but the QA department
Description
The current implementation includes a significant amount of custom code for glob pattern parsing, validation, and normalization (e.g., normalize_separators, BraceValidator, process_glob_entry, and related error handling). This custom logic could be greatly simplified and made more robust by replacing it with the globwalk crate, which natively supports features such as brace expansion, escape handling, platform-native separators, and file-only filtering.
Suggested steps for refactoring:
- Add
globwalk = "0.8"to Cargo.toml. - Replace the custom parsing/validation/normalization logic with a function using
GlobWalkerBuilderfromglobwalk, as shown below:use globwalk::{GlobWalkerBuilder, WalkError}; use minijinja::{Error, ErrorKind}; pub(crate) fn glob_paths(pattern: &str) -> Result<Vec<String>, Error> { let walker = GlobWalkerBuilder::new(".", pattern) .case_insensitive(false) .require_literal_separator(true) .require_literal_leading_dot(false) .build() .map_err(|e| Error::new(ErrorKind::InvalidPattern, e.to_string()))?; let paths = walker .filter_map(|r| r.ok()) .filter(|e| e.file_type().is_file()) .map(|e| e.path().to_string_lossy().replace("\\", "/")) .collect(); Ok(paths) }
- Remove all custom glob parsing and validation code, including:
CharContext,BraceValidator,BraceValidationStatenormalize_separators,force_literal_escapes,process_backslashprocess_glob_entry,fetch_metadata,open_root_dir, and custom error plumbing
Benefits:
- Maintains all current features (brace expansion, escape handling, separator normalization, file filtering)
- Reduces code complexity by ~500 lines
- Leverages a well-tested external crate
Action items:
- Refactor glob pattern handling to use
globwalkas described - Remove obsolete custom parsing/validation code
- Ensure all existing tests pass and add new ones if necessary to cover edge cases
This change will simplify maintenance and improve reliability.
I created this issue for @leynos from #168 (comment).
Tips and commands
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
lowAin't annoying anyone but the QA departmentAin't annoying anyone but the QA department