Remove unnecessary Path::new from fs calls (#3476)

This commit is contained in:
Charlie Marsh 2023-03-12 23:18:23 -04:00 committed by GitHub
parent 7a80bcec58
commit 2a4d6ab3b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 14 deletions

View file

@ -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()

View file

@ -93,7 +93,7 @@ impl FromStr for FilePattern {
fn from_str(s: &str) -> Result<Self, Self::Err> {
let pattern = s.to_string();
let absolute = fs::normalize_path(Path::new(&pattern));
let absolute = fs::normalize_path(&pattern);
Ok(Self::User(pattern, absolute))
}
}

View file

@ -21,7 +21,7 @@ pub fn test_resource_path(path: impl AsRef<Path>) -> 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<Vec<Diagnostic>> {
pub fn test_path(path: impl AsRef<Path>, settings: &Settings) -> Result<Vec<Diagnostic>> {
let path = test_resource_path("fixtures").join(path);
let contents = std::fs::read_to_string(&path)?;
let tokens: Vec<LexResult> = ruff_rustpython::tokenize(&contents);

View file

@ -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<T: Write>(
) -> 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<T: Write>(stdout: &mut T, fixed: &FxHashMap<String, FixTable>) ->
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)) {