-
Notifications
You must be signed in to change notification settings - Fork 0
Broaden static-regex lint guard to cover supported lazy wrappers (#410) #415
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
Merged
leynos
merged 6 commits into
main
from
issue-410-broaden-static-regex-lint-guard-to-cover-supported-lazy-wrappers
Aug 3, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b6d347b
Broaden static-regex lint to cover once_cell Lazy (#410)
d5f1f26
Harden static-regex guard: RG args and move closures (#410)
f89dde6
Cover argument-bearing RG overrides (#410)
leynos 6683228
Harden argv-recording stub against quoted paths (#410)
leynos 071b918
Add property coverage for the static-regex guard (#410)
leynos f5eadac
Migrate static-regex lint tests to camino and cap-std (#410)
leynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #!/usr/bin/env bash | ||
| # Reject hand-rolled static regular expressions that bypass the `lazy_regex!` | ||
| # convention. | ||
| # | ||
| # The guard scans Rust sources for `static` declarations that wrap `Regex::new` | ||
| # directly in a supported lazy-wrapper constructor. Two wrapper families are | ||
| # supported, each matched whether spelled directly or fully qualified: | ||
| # | ||
| # * `std::sync::LazyLock::new` | ||
| # * `once_cell::sync::Lazy::new` | ||
| # | ||
| # Usage: check-static-regexes.sh [SCAN_DIR] | ||
| # | ||
| # SCAN_DIR defaults to the current directory. The RG environment variable | ||
| # overrides the ripgrep command (default: `rg`). It is split on whitespace, so | ||
| # it may carry arguments — for example `RG='rg --pcre2'` — matching the way the | ||
| # Makefile's `$(RG)` expansion behaved before the scan was extracted here. | ||
| # | ||
| # Exit status: | ||
| # 0 no prohibited declaration found | ||
| # 1 a prohibited declaration was found (diagnostic on stdout) | ||
| # * ripgrep failed to scan (diagnostic on stderr; rg's status propagated) | ||
| set -euo pipefail | ||
|
|
||
| read -r -a rg_cmd <<<"${RG:-rg}" | ||
| scan_dir="${1:-.}" | ||
|
|
||
| # `(?:[[:alnum:]_]+::)*` absorbs any module qualification (for example the | ||
| # `once_cell::sync::` in `once_cell::sync::Lazy::new`), so both the direct and | ||
| # fully qualified spellings of each supported constructor are rejected. | ||
| # `(?:move\s+)?` covers `move` closures such as `LazyLock::new(move || ...)`. | ||
| pattern='\bstatic\b[^;=]*=\s*(?:[[:alnum:]_]+::)*(?:LazyLock|Lazy)::new\s*\(\s*(?:move\s+)?\|\|\s*(\{\s*)?(?:[[:alnum:]_]+::)*Regex::new' | ||
|
|
||
| status=0 | ||
| "${rg_cmd[@]}" -U --glob '*.rs' "$pattern" "$scan_dir" || status=$? | ||
| case $status in | ||
| 0) echo "static regular expressions must use lazy_regex!"; exit 1 ;; | ||
| 1) exit 0 ;; | ||
| *) echo "failed to scan Rust sources (rg exit $status)" >&2; exit "$status" ;; | ||
| esac |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| static RE: LazyLock<Regex> = lazy_regex!("clean"); | ||
| fn build() { let _ = Regex::new("local").unwrap(); } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new("a").unwrap()); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| static RE: LazyLock<Regex> = LazyLock::new(move || Regex::new("e").unwrap()); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| static RE: LazyLock<Regex> = std::sync::LazyLock::new(|| Regex::new("b").unwrap()); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| static RE: Lazy<Regex> = Lazy::new(|| Regex::new("c").unwrap()); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| static RE: Lazy<Regex> = once_cell::sync::Lazy::new(move || Regex::new("f").unwrap()); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| static RE: Lazy<Regex> = once_cell::sync::Lazy::new(|| Regex::new("d").unwrap()); |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.