Skip to content
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

Remove unnecessary Path::new from fs calls #3476

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/ruff/src/settings/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/settings/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 6 additions & 10 deletions crates/ruff_cli/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
":",
Expand Down Expand Up @@ -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": {
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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)) {
Expand Down