Skip to content

Commit

Permalink
Use display on windows
Browse files Browse the repository at this point in the history
This avoids two backslashes in the output because the debug escape backslashes
  • Loading branch information
konstin authored and charliermarsh committed Feb 6, 2024
1 parent c6c72e1 commit be4ea99
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
4 changes: 2 additions & 2 deletions crates/ruff/src/commands/show_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ pub(crate) fn show_settings(

let settings = resolver.resolve(&path);

writeln!(writer, "Resolved settings for: {path:?}")?;
writeln!(writer, "Resolved settings for: \"{}\"", path.display())?;
if let Some(settings_path) = pyproject_config.path.as_ref() {
writeln!(writer, "Settings path: {settings_path:?}")?;
writeln!(writer, "Settings path: \"{}\"", settings_path.display())?;
}
write!(writer, "{settings}")?;

Expand Down
8 changes: 3 additions & 5 deletions crates/ruff/tests/show_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ fn display_default_settings() {
.unwrap()
.parent()
.unwrap();
println!("base_path: {:?}", base_path);
let base_path = base_path.to_string_lossy();

#[cfg(not(target_os = "windows"))]
let test_filters = &[(base_path.as_ref(), "[BASEPATH]")];

#[cfg(target_os = "windows")]
// Escape the backslashes for the regex.
let base_path = regex::escape(&base_path);

#[cfg(not(target_os = "windows"))]
let test_filters = &[(base_path.as_ref(), "[BASEPATH]")];

#[cfg(target_os = "windows")]
let test_filters = &[
(base_path.as_ref(), "[BASEPATH]"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ linter.external = []
linter.ignore_init_module_imports = false
linter.logger_objects = []
linter.namespace_packages = []
linter.src = ["[BASEPATH]"]
linter.src = [
"[BASEPATH]",
]
linter.tab_size = 4
linter.line_length = 88
linter.task_tags = [
Expand Down
21 changes: 19 additions & 2 deletions crates/ruff_linter/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ macro_rules! display_settings {
(@field $fmt:ident, $prefix:ident, $settings:ident.$field:ident | debug) => {
writeln!($fmt, "{}{} = {:?}", $prefix, stringify!($field), $settings.$field)?;
};
(@field $fmt:ident, $prefix:ident, $settings:ident.$field:ident | display) => {
writeln!($fmt, "{}{} = \"{}\"", $prefix, stringify!($field), $settings.$field.display())?;
};
(@field $fmt:ident, $prefix:ident, $settings:ident.$field:ident | quoted) => {
writeln!($fmt, "{}{} = \"{}\"", $prefix, stringify!($field), $settings.$field)?;
};
Expand Down Expand Up @@ -152,6 +155,20 @@ macro_rules! display_settings {
}
}
};
(@field $fmt:ident, $prefix:ident, $settings:ident.$field:ident | display_array) => {
{
write!($fmt, "{}{} = ", $prefix, stringify!($field))?;
if $settings.$field.is_empty() {
writeln!($fmt, "[]")?;
} else {
writeln!($fmt, "[")?;
for elem in &$settings.$field {
writeln!($fmt, "\t\"{}\",", elem.display())?;
}
writeln!($fmt, "]")?;
}
}
};
(@field $fmt:ident, $prefix:ident, $settings:ident.$field:ident) => {
writeln!($fmt, "{}{} = {}", $prefix, stringify!($field), $settings.$field)?;
};
Expand Down Expand Up @@ -220,7 +237,7 @@ impl Display for LinterSettings {
namespace = "linter",
fields = [
self.exclude,
self.project_root | debug,
self.project_root | display,

self.rules | nested,
self.per_file_ignores,
Expand All @@ -238,7 +255,7 @@ impl Display for LinterSettings {
self.ignore_init_module_imports,
self.logger_objects | array,
self.namespace_packages | debug,
self.src | debug,
self.src | display_array,
self.tab_size,
self.line_length,
self.task_tags | array,
Expand Down
6 changes: 2 additions & 4 deletions crates/ruff_workspace/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ impl fmt::Display for Settings {
display_settings! {
formatter = f,
fields = [
// We want the quotes and lossy UTF8 conversion for this path, so
// using PathBuf's `Debug` formatter suffices.
self.cache_dir | debug,
self.cache_dir | display,
self.fix,
self.fix_only,
self.output_format,
Expand Down Expand Up @@ -101,7 +99,7 @@ impl fmt::Display for FileResolverSettings {
self.include,
self.extend_include,
self.respect_gitignore,
self.project_root | debug,
self.project_root | display,
]
}
Ok(())
Expand Down

0 comments on commit be4ea99

Please sign in to comment.