diff --git a/crates/ruff/src/settings/configuration.rs b/crates/ruff/src/settings/configuration.rs index 1c58b5f11650c..b83682370f21e 100644 --- a/crates/ruff/src/settings/configuration.rs +++ b/crates/ruff/src/settings/configuration.rs @@ -121,7 +121,7 @@ impl Configuration { paths .into_iter() .map(|pattern| { - let absolute = fs::normalize_path_to(Path::new(&pattern), project_root); + let absolute = fs::normalize_path_to(&pattern, project_root); FilePattern::User(pattern, absolute) }) .collect() @@ -140,7 +140,7 @@ impl Configuration { paths .into_iter() .map(|pattern| { - let absolute = fs::normalize_path_to(Path::new(&pattern), project_root); + let absolute = fs::normalize_path_to(&pattern, project_root); FilePattern::User(pattern, absolute) }) .collect() diff --git a/crates/ruff/src/settings/types.rs b/crates/ruff/src/settings/types.rs index f8b1ae2e43c5e..0516fd456f95b 100644 --- a/crates/ruff/src/settings/types.rs +++ b/crates/ruff/src/settings/types.rs @@ -93,7 +93,7 @@ impl FromStr for FilePattern { fn from_str(s: &str) -> Result { let pattern = s.to_string(); - let absolute = fs::normalize_path(Path::new(&pattern)); + let absolute = fs::normalize_path(&pattern); Ok(Self::User(pattern, absolute)) } } diff --git a/crates/ruff/src/test.rs b/crates/ruff/src/test.rs index fac9c7c69f9bb..b6758e9d5c79d 100644 --- a/crates/ruff/src/test.rs +++ b/crates/ruff/src/test.rs @@ -21,7 +21,7 @@ pub fn test_resource_path(path: impl AsRef) -> std::path::PathBuf { /// A convenient wrapper around [`check_path`], that additionally /// asserts that autofixes converge after 10 iterations. -pub fn test_path(path: &Path, settings: &Settings) -> Result> { +pub fn test_path(path: impl AsRef, settings: &Settings) -> Result> { let path = test_resource_path("fixtures").join(path); let contents = std::fs::read_to_string(&path)?; let tokens: Vec = ruff_rustpython::tokenize(&contents); diff --git a/crates/ruff_cli/src/printer.rs b/crates/ruff_cli/src/printer.rs index 66dbb1e0e9689..2f52aa8d89558 100644 --- a/crates/ruff_cli/src/printer.rs +++ b/crates/ruff_cli/src/printer.rs @@ -283,11 +283,7 @@ impl Printer { ); // Print the filename. - writeln!( - stdout, - "{}:", - relativize_path(Path::new(&filename)).underline() - )?; + writeln!(stdout, "{}:", relativize_path(filename).underline())?; // Print each message. for message in messages { @@ -316,7 +312,7 @@ impl Printer { for message in &diagnostics.messages { let label = format!( "{}{}{}{}{}{} {} {}", - relativize_path(Path::new(&message.filename)), + relativize_path(&message.filename), ":", message.location.row(), ":", @@ -356,7 +352,7 @@ impl Printer { "fingerprint": fingerprint(message), "location": { "path": project_dir.as_ref().map_or_else( - || relativize_path(Path::new(&message.filename)), + || relativize_path(&message.filename), |project_dir| relativize_path_to(&message.filename, project_dir), ), "lines": { @@ -377,7 +373,7 @@ impl Printer { for message in &diagnostics.messages { let label = format!( "{}:{}: [{}] {}", - relativize_path(Path::new(&message.filename)), + relativize_path(&message.filename), message.location.row(), message.kind.rule().noqa_code(), message.kind.body, @@ -612,7 +608,7 @@ fn print_message( ) -> Result<()> { let label = format!( "{path}{sep}{row}{sep}{col}{sep} {code_and_body}", - path = relativize_path(Path::new(&message.filename)).bold(), + path = relativize_path(&message.filename).bold(), sep = ":".cyan(), row = message.location.row(), col = message.location.column(), @@ -691,7 +687,7 @@ fn print_fixed(stdout: &mut T, fixed: &FxHashMap) -> stdout, "{} {}{}", "-".cyan(), - relativize_path(Path::new(filename)).bold(), + relativize_path(filename).bold(), ":".cyan() )?; for (rule, count) in table.iter().sorted_by_key(|(.., count)| Reverse(*count)) {