Skip to content

Commit

Permalink
refactor(linter): remove unused properties of LintResult
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Jan 28, 2025
1 parent ccb6a89 commit cbe2439
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
2 changes: 1 addition & 1 deletion apps/oxlint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod cli {
pub use crate::{
command::*,
lint::LintRunner,
result::{CliRunResult, LintResult},
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
23 changes: 3 additions & 20 deletions apps/oxlint/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,12 @@ pub enum CliRunResult {
None,
InvalidOptions { message: String },
PathNotFound { paths: Vec<PathBuf> },
LintResult(LintResult),
/// The exit unix code for, in general 0 or 1 (from `--deny-warnings` or `--max-warnings` for example)
LintResult(ExitCode),
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,
/// The exit unix code for, in general 0 or 1 (from `--deny-warnings` or `--max-warnings` for example)
pub exit_code: ExitCode,
}

impl Termination for CliRunResult {
#[allow(clippy::print_stdout, clippy::print_stderr)]
fn report(self) -> ExitCode {
Expand All @@ -39,12 +27,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 cbe2439

Please sign in to comment.