Skip to content

Commit

Permalink
fix(cli): fix oxlint --format json yields 0 files to lint
Browse files Browse the repository at this point in the history
closes #2930
  • Loading branch information
Boshen committed Apr 11, 2024
1 parent 02adc76 commit d2c4ac2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions crates/oxc_cli/src/command/lint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{path::PathBuf, str::FromStr};

use bpaf::Bpaf;
use oxc_linter::AllowWarnDeny;
Expand Down Expand Up @@ -136,8 +136,7 @@ pub struct WarningOptions {
#[derive(Debug, Clone, Bpaf)]
pub struct OutputOptions {
/// Use a specific output format (default, json)
// last flag is the default
#[bpaf(long, short, flag(OutputFormat::Json, OutputFormat::Default))]
#[bpaf(long, short, fallback(OutputFormat::Default))]
pub format: OutputFormat,
}

Expand All @@ -147,6 +146,16 @@ pub enum OutputFormat {
Json,
}

impl FromStr for OutputFormat {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"json" => Self::Json,
_ => Self::Default,
})
}
}

/// Enable Plugins
#[allow(clippy::struct_field_names)]
#[derive(Debug, Clone, Bpaf)]
Expand Down Expand Up @@ -304,6 +313,7 @@ mod lint_options {
fn format() {
let options = get_lint_options("-f json");
assert_eq!(options.output_options.format, OutputFormat::Json);
assert!(options.paths.is_empty());
}

#[test]
Expand Down

0 comments on commit d2c4ac2

Please sign in to comment.