refactor(linter): remove LintResult (#8712)

This commit is contained in:
Sysix 2025-01-29 02:26:18 +00:00
parent ad35e82165
commit 194a5ff76a
3 changed files with 16 additions and 37 deletions

View file

@ -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};
}

View file

@ -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},
};
@ -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());
@ -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)))
}
}

View file

@ -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 {
@ -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)