mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Remove unnecessary Path::new
from fs
calls (#3476)
This commit is contained in:
parent
7a80bcec58
commit
2a4d6ab3b2
4 changed files with 10 additions and 14 deletions
|
@ -121,7 +121,7 @@ impl Configuration {
|
||||||
paths
|
paths
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|pattern| {
|
.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)
|
FilePattern::User(pattern, absolute)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -140,7 +140,7 @@ impl Configuration {
|
||||||
paths
|
paths
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|pattern| {
|
.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)
|
FilePattern::User(pattern, absolute)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl FromStr for FilePattern {
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let pattern = s.to_string();
|
let pattern = s.to_string();
|
||||||
let absolute = fs::normalize_path(Path::new(&pattern));
|
let absolute = fs::normalize_path(&pattern);
|
||||||
Ok(Self::User(pattern, absolute))
|
Ok(Self::User(pattern, absolute))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub fn test_resource_path(path: impl AsRef<Path>) -> std::path::PathBuf {
|
||||||
|
|
||||||
/// A convenient wrapper around [`check_path`], that additionally
|
/// A convenient wrapper around [`check_path`], that additionally
|
||||||
/// asserts that autofixes converge after 10 iterations.
|
/// 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 path = test_resource_path("fixtures").join(path);
|
||||||
let contents = std::fs::read_to_string(&path)?;
|
let contents = std::fs::read_to_string(&path)?;
|
||||||
let tokens: Vec<LexResult> = ruff_rustpython::tokenize(&contents);
|
let tokens: Vec<LexResult> = ruff_rustpython::tokenize(&contents);
|
||||||
|
|
|
@ -283,11 +283,7 @@ impl Printer {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Print the filename.
|
// Print the filename.
|
||||||
writeln!(
|
writeln!(stdout, "{}:", relativize_path(filename).underline())?;
|
||||||
stdout,
|
|
||||||
"{}:",
|
|
||||||
relativize_path(Path::new(&filename)).underline()
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Print each message.
|
// Print each message.
|
||||||
for message in messages {
|
for message in messages {
|
||||||
|
@ -316,7 +312,7 @@ impl Printer {
|
||||||
for message in &diagnostics.messages {
|
for message in &diagnostics.messages {
|
||||||
let label = format!(
|
let label = format!(
|
||||||
"{}{}{}{}{}{} {} {}",
|
"{}{}{}{}{}{} {} {}",
|
||||||
relativize_path(Path::new(&message.filename)),
|
relativize_path(&message.filename),
|
||||||
":",
|
":",
|
||||||
message.location.row(),
|
message.location.row(),
|
||||||
":",
|
":",
|
||||||
|
@ -356,7 +352,7 @@ impl Printer {
|
||||||
"fingerprint": fingerprint(message),
|
"fingerprint": fingerprint(message),
|
||||||
"location": {
|
"location": {
|
||||||
"path": project_dir.as_ref().map_or_else(
|
"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),
|
|project_dir| relativize_path_to(&message.filename, project_dir),
|
||||||
),
|
),
|
||||||
"lines": {
|
"lines": {
|
||||||
|
@ -377,7 +373,7 @@ impl Printer {
|
||||||
for message in &diagnostics.messages {
|
for message in &diagnostics.messages {
|
||||||
let label = format!(
|
let label = format!(
|
||||||
"{}:{}: [{}] {}",
|
"{}:{}: [{}] {}",
|
||||||
relativize_path(Path::new(&message.filename)),
|
relativize_path(&message.filename),
|
||||||
message.location.row(),
|
message.location.row(),
|
||||||
message.kind.rule().noqa_code(),
|
message.kind.rule().noqa_code(),
|
||||||
message.kind.body,
|
message.kind.body,
|
||||||
|
@ -612,7 +608,7 @@ fn print_message<T: Write>(
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let label = format!(
|
let label = format!(
|
||||||
"{path}{sep}{row}{sep}{col}{sep} {code_and_body}",
|
"{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(),
|
sep = ":".cyan(),
|
||||||
row = message.location.row(),
|
row = message.location.row(),
|
||||||
col = message.location.column(),
|
col = message.location.column(),
|
||||||
|
@ -691,7 +687,7 @@ fn print_fixed<T: Write>(stdout: &mut T, fixed: &FxHashMap<String, FixTable>) ->
|
||||||
stdout,
|
stdout,
|
||||||
"{} {}{}",
|
"{} {}{}",
|
||||||
"-".cyan(),
|
"-".cyan(),
|
||||||
relativize_path(Path::new(filename)).bold(),
|
relativize_path(filename).bold(),
|
||||||
":".cyan()
|
":".cyan()
|
||||||
)?;
|
)?;
|
||||||
for (rule, count) in table.iter().sorted_by_key(|(.., count)| Reverse(*count)) {
|
for (rule, count) in table.iter().sorted_by_key(|(.., count)| Reverse(*count)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue