Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 4, 2024
1 parent 2f01b4f commit 06f3006
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
17 changes: 12 additions & 5 deletions crates/ruff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,12 +812,19 @@ impl TypedValueParser for ConfigArgumentParser {
arg: Option<&clap::Arg>,
value: &std::ffi::OsStr,
) -> Result<Self::Value, clap::Error> {
let value = value
.to_str()
.ok_or_else(|| clap::Error::new(clap::error::ErrorKind::InvalidUtf8))?;
// Convert to UTF-8.
let Some(value) = value.to_str() else {
// But respect non-UTF-8 paths.
let path_to_config_file = PathBuf::from(value);
if path_to_config_file.is_file() {
return Ok(SingleConfigArgument::FilePath(path_to_config_file));
}
return Err(clap::Error::new(clap::error::ErrorKind::InvalidUtf8));
};

// Expand environment variables and tildes.
if let Ok(path_to_config_file) =
shellexpand::full(value).map(|config| PathBuf::from(config.as_ref()))
shellexpand::full(value).map(|config| PathBuf::from(&*config))
{
if path_to_config_file.is_file() {
return Ok(SingleConfigArgument::FilePath(path_to_config_file));
Expand Down Expand Up @@ -890,7 +897,7 @@ A `--config` flag must either be a path to a `.toml` configuration file
"
It looks like you were trying to pass a path to a configuration file.
The path `{value}` does not exist"
The path `{value}` does not point to a configuration file"
));
}
} else if value.contains('=') {
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn nonexistent_config_file() {
option
It looks like you were trying to pass a path to a configuration file.
The path `foo.toml` does not exist
The path `foo.toml` does not point to a configuration file
For more information, try '--help'.
"###);
Expand Down
6 changes: 1 addition & 5 deletions crates/ruff/tests/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ fn nonexistent_config_file() {
option
It looks like you were trying to pass a path to a configuration file.
The path `foo.toml` does not exist
The path `foo.toml` does not point to a configuration file
For more information, try '--help'.
"###);
Expand Down Expand Up @@ -1141,9 +1141,6 @@ ignore = ["F841"]
"#,
)?;

insta::with_settings!({
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
.arg("--config")
Expand All @@ -1166,7 +1163,6 @@ def func():
----- stderr -----
"###);
});

Ok(())
}

0 comments on commit 06f3006

Please sign in to comment.