chore(tools): Support per-pattern regex mode in fs_modify_file#876
Merged
Conversation
Patterns passed to `fs_modify_file` can now set their own `regex` flag,
overriding the call-level `replace_using_regex`. This lets a single
call mix literal and regex patterns instead of forcing all patterns
into the same mode:
```json
{
"path": "src/lib.rs",
"patterns": [
{"old": "stream().await", "new": "stream()"},
{"old": "fn (\w+)_old", "new": "fn ${1}_new", "regex": true}
],
"replace_using_regex": false
}
```
Fixes two related bugs in regex mode. A regex that compiled but
matched nothing was previously reported as applied even though no
replacement happened; it is now reported as not found alongside
literal-mode misses. A regex that failed to compile silently skipped
the pattern with no feedback; it now surfaces as an "Invalid regex
patterns" section in the report, separate from "Patterns not found",
so callers can tell a typo in the regex apart from a pattern that
simply is not present.
The `find_blocked_regex_patterns` guard against overly-broad patterns
(e.g. bare `.*`) now only applies to patterns actually running in
regex mode, respecting the same per-pattern override. Tool docs and
the JSON schema are updated to describe the new `regex` field and to
warn that parentheses are capture groups, not literal characters, in
regex mode.
Signed-off-by: Jean Mertz <git@jeanmertz.com>
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.
Patterns passed to
fs_modify_filecan now set their ownregexflag, overriding the call-levelreplace_using_regex. This lets a single call mix literal and regex patterns instead of forcing all patterns into the same mode:{ "path": "src/lib.rs", "patterns": [ {"old": "stream().await", "new": "stream()"}, {"old": "fn (\w+)_old", "new": "fn ${1}_new", "regex": true} ], "replace_using_regex": false }Fixes two related bugs in regex mode. A regex that compiled but matched nothing was previously reported as applied even though no replacement happened; it is now reported as not found alongside literal-mode misses. A regex that failed to compile silently skipped the pattern with no feedback; it now surfaces as an "Invalid regex patterns" section in the report, separate from "Patterns not found", so callers can tell a typo in the regex apart from a pattern that simply is not present.
The
find_blocked_regex_patternsguard against overly-broad patterns (e.g. bare.*) now only applies to patterns actually running in regex mode, respecting the same per-pattern override. Tool docs and the JSON schema are updated to describe the newregexfield and to warn that parentheses are capture groups, not literal characters, in regex mode.