Skip to content

Commit

Permalink
refactor(linter): refactor LintBuilder to prep for nested configs
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Dec 20, 2024
1 parent 0487198 commit 30c712c
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 114 deletions.
28 changes: 20 additions & 8 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::{
use ignore::gitignore::Gitignore;
use oxc_diagnostics::{DiagnosticService, GraphicalReportHandler};
use oxc_linter::{
loader::LINT_PARTIAL_LOADER_EXT, AllowWarnDeny, InvalidFilterKind, LintFilter, LintService,
LintServiceOptions, Linter, LinterBuilder, Oxlintrc,
loader::LINT_PARTIAL_LOADER_EXT, AllowWarnDeny, ConfigStoreBuilder, InvalidFilterKind,
LintFilter, LintOptions, LintService, LintServiceOptions, Linter, Oxlintrc,
};
use oxc_span::VALID_EXTENSIONS;

Expand Down Expand Up @@ -130,20 +130,32 @@ impl Runner for LintRunner {

let oxlintrc_for_print =
if misc_options.print_config { Some(oxlintrc.clone()) } else { None };
let builder = LinterBuilder::from_oxlintrc(false, oxlintrc)
.with_filters(filter)
.with_fix(fix_options.fix_kind());
let config_builder =
ConfigStoreBuilder::from_oxlintrc(false, oxlintrc).with_filters(filter);

if let Some(basic_config_file) = oxlintrc_for_print {
return CliRunResult::PrintConfigResult {
config_file: builder.resolve_final_config_file(basic_config_file),
config_file: config_builder.resolve_final_config_file(basic_config_file),
};
}

let mut options = LintServiceOptions::new(self.cwd, paths)
.with_cross_module(builder.plugins().has_import());
.with_cross_module(config_builder.plugins().has_import());

let lint_config = match config_builder.build() {
Ok(config) => config,
Err(diagnostic) => {
let handler = GraphicalReportHandler::new();
let mut err = String::new();
handler.render_report(&mut err, &diagnostic).unwrap();
return CliRunResult::InvalidOptions {
message: format!("Failed to parse configuration file.\n{err}"),
};
}
};

let linter = builder.build();
let linter =
Linter::new(LintOptions::default(), lint_config).with_fix(fix_options.fix_kind());

let tsconfig = basic_options.tsconfig;
if let Some(path) = tsconfig.as_ref() {
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_language_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tower_lsp::{
Client, LanguageServer, LspService, Server,
};

use oxc_linter::{FixKind, LinterBuilder, Oxlintrc};
use oxc_linter::{ConfigStoreBuilder, ConfigStoreBuilder, FixKind, Oxlintrc};

use crate::capabilities::{Capabilities, CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC};
use crate::linter::error_with_position::DiagnosticReport;
Expand Down Expand Up @@ -489,7 +489,7 @@ impl Backend {
let config = Oxlintrc::from_file(&config_path)
.expect("should have initialized linter with new options");
*linter = ServerLinter::new_with_linter(
LinterBuilder::from_oxlintrc(true, config.clone())
ConfigStoreBuilder::from_oxlintrc(true, config.clone())
.with_fix(FixKind::SafeFix)
.build(),
);
Expand Down
Loading

0 comments on commit 30c712c

Please sign in to comment.