Skip to content

Commit

Permalink
show new glob in warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ntBre committed Feb 26, 2025
1 parent 7c86490 commit 11917c4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions crates/ruff/tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2165,15 +2165,15 @@ fn cookiecutter_globbing() -> Result<()> {
--- {{cookiecutter.repo_name}}/tests/maintest.py
+++ {{cookiecutter.repo_name}}/tests/maintest.py
@@ -1,3 +1,3 @@
import foo
import bar
import foo
import bar
-import foo
/ No newline at end of file
+import foo
----- stderr -----
warning: Error parsing original glob: `"[TMP]/{{cookiecutter.repo_name}}/tests/*"`, trying with escaped braces (`{}`)
warning: Error parsing original glob: `"[TMP]/{{cookiecutter.repo_name}}/tests/*"`, trying with escaped braces: `"[TMP]/[{][{]cookiecutter.repo_name[}][}]/tests/*"`
1 file would be reformatted
"#);
});
Expand Down
14 changes: 7 additions & 7 deletions crates/ruff/tests/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2729,14 +2729,14 @@ fn cookiecutter_globbing() -> Result<()> {
.args(STDIN_BASE_OPTIONS)
.arg("--select=F811")
.current_dir(tempdir.path()), @r#"
success: true
exit_code: 0
----- stdout -----
All checks passed!
success: true
exit_code: 0
----- stdout -----
All checks passed!
----- stderr -----
warning: Error parsing original glob: `"[TMP]/{{cookiecutter.repo_name}}/tests/*"`, trying with escaped braces (`{}`)
"#);
----- stderr -----
warning: Error parsing original glob: `"[TMP]/{{cookiecutter.repo_name}}/tests/*"`, trying with escaped braces: `"[TMP]/[{][{]cookiecutter.repo_name[}][}]/tests/*"`
"#);
});

// after removing the config file with the ignore, F811 applies, so the glob worked above
Expand Down
8 changes: 5 additions & 3 deletions crates/ruff_linter/src/settings/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,11 @@ where
pub fn try_glob_new(s: &str) -> Result<Glob> {
match Glob::new(s) {
Err(e) if *e.kind() == globset::ErrorKind::NestedAlternates => {
log::warn!("Error parsing original glob: `{s:?}`, trying with escaped braces (`{{}}`)");
let s = s.replace("{{", "[{][{]").replace("}}", "[}][}]");
Ok(Glob::new(&s)?)
let new = s.replace("{{", "[{][{]").replace("}}", "[}][}]");
log::warn!(
"Error parsing original glob: `{s:?}`, trying with escaped braces: `{new:?}`"
);
Ok(Glob::new(&new)?)
}
glob => Ok(glob?),
}
Expand Down

0 comments on commit 11917c4

Please sign in to comment.