Skip to content

Commit

Permalink
refactor(linter): remove LintResult (#8712)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Jan 29, 2025
1 parent ad35e82 commit 194a5ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 37 deletions.
7 changes: 1 addition & 6 deletions apps/oxlint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,5 @@ mod walk;

pub mod cli {

pub use crate::{
command::*,
lint::LintRunner,
result::{CliRunResult, LintResult},
runner::Runner,
};
pub use crate::{command::*, lint::LintRunner, result::CliRunResult, runner::Runner};
}
11 changes: 3 additions & 8 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use oxc_span::VALID_EXTENSIONS;
use serde_json::Value;

use crate::{
cli::{CliRunResult, LintCommand, LintResult, MiscOptions, Runner, WarningOptions},
cli::{CliRunResult, LintCommand, MiscOptions, Runner, WarningOptions},
output_formatter::{LintCommandInfo, OutputFormatter},
walk::{Extensions, Walk},
};
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Runner for LintRunner {
// filtered, return early.
if provided_path_count > 0 {
// ToDo: when oxc_linter (config) validates the configuration, we can use exit_code = 1 to fail
return CliRunResult::LintResult(LintResult::default());
return CliRunResult::LintResult(ExitCode::SUCCESS);
}

paths.push(self.cwd.clone());
Expand Down Expand Up @@ -226,12 +226,7 @@ impl Runner for LintRunner {
stdout.write_all(end.as_bytes()).or_else(Self::check_for_writer_error).unwrap();
};

CliRunResult::LintResult(LintResult {
number_of_files,
number_of_warnings: diagnostic_result.warnings_count(),
number_of_errors: diagnostic_result.errors_count(),
exit_code: ExitCode::from(u8::from(diagnostic_failed)),
})
CliRunResult::LintResult(ExitCode::from(u8::from(diagnostic_failed)))
}
}

Expand Down
35 changes: 12 additions & 23 deletions apps/oxlint/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,18 @@ use std::{
#[derive(Debug)]
pub enum CliRunResult {
None,
InvalidOptions { message: String },
PathNotFound { paths: Vec<PathBuf> },
LintResult(LintResult),
PrintConfigResult,
ConfigFileInitResult { message: String },
}

/// A summary of a complete linter run.
#[derive(Debug, Default)]
pub struct LintResult {
/// The number of files that were linted.
pub number_of_files: usize,
/// The number of warnings that were found.
pub number_of_warnings: usize,
/// The number of errors that were found.
pub number_of_errors: usize,
InvalidOptions {
message: String,
},
PathNotFound {
paths: Vec<PathBuf>,
},
/// The exit unix code for, in general 0 or 1 (from `--deny-warnings` or `--max-warnings` for example)
pub exit_code: ExitCode,
LintResult(ExitCode),
PrintConfigResult,
ConfigFileInitResult {
message: String,
},
}

impl Termination for CliRunResult {
Expand All @@ -39,12 +33,7 @@ impl Termination for CliRunResult {
println!("Path {paths:?} does not exist.");
ExitCode::from(1)
}
Self::LintResult(LintResult {
number_of_files: _, // ToDo: only for tests, make snapshots
number_of_warnings: _, // ToDo: only for tests, make snapshots
number_of_errors: _,
exit_code,
}) => exit_code,
Self::LintResult(exit_code) => exit_code,
Self::ConfigFileInitResult { message } => {
println!("{message}");
ExitCode::from(0)
Expand Down

0 comments on commit 194a5ff

Please sign in to comment.