diff --git a/crates/oxc_cli/src/command/lint.rs b/crates/oxc_cli/src/command/lint.rs index 9cbd7c7ab..780a88578 100644 --- a/crates/oxc_cli/src/command/lint.rs +++ b/crates/oxc_cli/src/command/lint.rs @@ -149,10 +149,11 @@ pub enum OutputFormat { impl FromStr for OutputFormat { type Err = String; fn from_str(s: &str) -> Result { - 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::>(); + 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");