Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): fix oxlint --format json yields 0 files to lint #2940

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
})
Boshen marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// 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
Loading