mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(cli): return error if --format receives an unknown value
This commit is contained in:
parent
f3a28c61b9
commit
c250b288ef
1 changed files with 14 additions and 4 deletions
|
|
@ -149,10 +149,11 @@ pub enum OutputFormat {
|
|||
impl FromStr for OutputFormat {
|
||||
type Err = String;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(match s {
|
||||
"json" => Self::Json,
|
||||
_ => Self::Default,
|
||||
})
|
||||
match s {
|
||||
"json" => Ok(Self::Json),
|
||||
"default" => Ok(Self::Default),
|
||||
_ => Err(format!("'{s}' is not a known format")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -316,6 +317,15 @@ mod lint_options {
|
|||
assert!(options.paths.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_error() {
|
||||
let args = "-f asdf".split(' ').map(std::string::ToString::to_string).collect::<Vec<_>>();
|
||||
let result = lint_command().run_inner(args.as_slice());
|
||||
assert!(result.is_err_and(
|
||||
|err| err.unwrap_stderr() == "couldn't parse `asdf`: 'asdf' is not a known format"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_rules() {
|
||||
let options = get_lint_options("--rules");
|
||||
|
|
|
|||
Loading…
Reference in a new issue