Skip to content

Commit 5fd1c6b

Browse files
committed
refactor(oxlint): run oxlint before tsgolint
This refactors the linting process to run oxlint before tsgolint instead of the previous order. This change enables proper support for disable directives by allowing the disable directive data to be parsed and stored during the oxlint run, then utilized during the tsgolint run, and finally enables reporting of unused disable directives. - Moves the oxlint execution to run before tsgolint - Wraps the oxlint spawning in a block scope and clones necessary variables - Adds proper cleanup with drop(tx_error) when type-aware linting is disabled
1 parent b794af1 commit 5fd1c6b

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

apps/oxlint/src/lint.rs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -312,26 +312,7 @@ impl LintRunner {
312312
.filter(|path| !ignore_matcher.should_ignore(Path::new(path)))
313313
.collect::<Vec<Arc<OsStr>>>();
314314

315-
// Run type-aware linting through tsgolint
316-
// TODO: Add a warning message if `tsgolint` cannot be found, but type-aware rules are enabled
317-
if self.options.type_aware {
318-
let state = match TsGoLintState::try_new(options.cwd(), config_store.clone()) {
319-
Ok(state) => state,
320-
Err(err) => {
321-
print_and_flush_stdout(stdout, &err);
322-
return CliRunResult::TsGoLintError;
323-
}
324-
};
325-
326-
if let Err(err) =
327-
state.with_silent(misc_options.silent).lint(&files_to_lint, tx_error.clone())
328-
{
329-
print_and_flush_stdout(stdout, &err);
330-
return CliRunResult::TsGoLintError;
331-
}
332-
}
333-
334-
let linter = Linter::new(LintOptions::default(), config_store, external_linter)
315+
let linter = Linter::new(LintOptions::default(), config_store.clone(), external_linter)
335316
.with_fix(fix_options.fix_kind())
336317
.with_report_unused_directives(report_unused_directives);
337318

@@ -358,21 +339,41 @@ impl LintRunner {
358339

359340
let number_of_rules = linter.number_of_rules(self.options.type_aware);
360341

342+
let cwd = options.cwd().to_path_buf();
343+
361344
// Spawn linting in another thread so diagnostics can be printed immediately from diagnostic_service.run.
362-
rayon::spawn(move || {
363-
let has_external_linter = linter.has_external_linter();
345+
{
346+
let tx_error = tx_error.clone();
347+
let files_to_lint = files_to_lint.clone();
348+
rayon::spawn(move || {
349+
let has_external_linter = linter.has_external_linter();
350+
351+
let mut lint_service = LintService::new(linter, options);
352+
lint_service.with_paths(files_to_lint);
353+
354+
// Use `RawTransferFileSystem` if `ExternalLinter` exists.
355+
// This reads the source text into start of allocator, instead of the end.
356+
if has_external_linter {
357+
lint_service.with_file_system(Box::new(RawTransferFileSystem));
358+
}
364359

365-
let mut lint_service = LintService::new(linter, options);
366-
lint_service.with_paths(files_to_lint);
360+
lint_service.run(&tx_error);
361+
});
362+
}
367363

368-
// Use `RawTransferFileSystem` if `ExternalLinter` exists.
369-
// This reads the source text into start of allocator, instead of the end.
370-
if has_external_linter {
371-
lint_service.with_file_system(Box::new(RawTransferFileSystem));
364+
// Run type-aware linting through tsgolint
365+
// TODO: Add a warning message if `tsgolint` cannot be found, but type-aware rules are enabled
366+
if self.options.type_aware {
367+
if let Err(err) = TsGoLintState::new(&cwd, config_store)
368+
.with_silent(misc_options.silent)
369+
.lint(&files_to_lint, tx_error)
370+
{
371+
print_and_flush_stdout(stdout, &err);
372+
return CliRunResult::TsGoLintError;
372373
}
373-
374-
lint_service.run(&tx_error);
375-
});
374+
} else {
375+
drop(tx_error);
376+
}
376377

377378
let diagnostic_result = diagnostic_service.run(stdout);
378379

0 commit comments

Comments
 (0)