Skip to content

Commit 06f7ecb

Browse files
committed
refactor(oxlint): run oxlint before tsgolint
This PR changes the order in which oxlint and tsgolint are run. Previously, we run tsgolint, THEN oxlint, however in order to support disable directives, this is going to be reversed, this will allow the disable directives data to be parsed + stored for both the oxlint run, and then the tsgolint run, and finally, we can report unused disable directives
1 parent 1b425d6 commit 06f7ecb

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed

apps/oxlint/src/lint.rs

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -305,21 +305,10 @@ impl LintRunner {
305305
.filter(|path| !ignore_matcher.should_ignore(Path::new(path)))
306306
.collect::<Vec<Arc<OsStr>>>();
307307

308-
// Run type-aware linting through tsgolint
309-
// TODO: Add a warning message if `tsgolint` cannot be found, but type-aware rules are enabled
310-
if self.options.type_aware {
311-
if let Err(err) = TsGoLintState::new(options.cwd(), config_store.clone())
312-
.with_silent(misc_options.silent)
313-
.lint(&files_to_lint, tx_error.clone())
314-
{
315-
print_and_flush_stdout(stdout, &err);
316-
return CliRunResult::TsGoLintError;
317-
}
318-
}
319-
320-
let linter = Linter::new(LintOptions::default(), config_store, self.external_linter)
321-
.with_fix(fix_options.fix_kind())
322-
.with_report_unused_directives(report_unused_directives);
308+
let linter =
309+
Linter::new(LintOptions::default(), config_store.clone(), self.external_linter)
310+
.with_fix(fix_options.fix_kind())
311+
.with_report_unused_directives(report_unused_directives);
323312

324313
let number_of_files = files_to_lint.len();
325314

@@ -344,21 +333,41 @@ impl LintRunner {
344333

345334
let number_of_rules = linter.number_of_rules(self.options.type_aware);
346335

336+
let cwd = options.cwd().to_path_buf();
337+
347338
// Spawn linting in another thread so diagnostics can be printed immediately from diagnostic_service.run.
348-
rayon::spawn(move || {
349-
let mut lint_service = LintService::new(linter, options);
350-
lint_service.with_paths(files_to_lint);
339+
{
340+
let tx_error = tx_error.clone();
341+
let files_to_lint = files_to_lint.clone();
342+
rayon::spawn(move || {
343+
let mut lint_service = LintService::new(linter, options);
344+
lint_service.with_paths(files_to_lint);
345+
346+
// Use `RawTransferFileSystem` if `oxlint2` feature is enabled.
347+
// This reads the source text into start of allocator, instead of the end.
348+
#[cfg(all(feature = "oxlint2", not(feature = "disable_oxlint2")))]
349+
{
350+
use crate::raw_fs::RawTransferFileSystem;
351+
lint_service.with_file_system(Box::new(RawTransferFileSystem));
352+
}
353+
354+
lint_service.run(&tx_error);
355+
});
356+
}
351357

352-
// Use `RawTransferFileSystem` if `oxlint2` feature is enabled.
353-
// This reads the source text into start of allocator, instead of the end.
354-
#[cfg(all(feature = "oxlint2", not(feature = "disable_oxlint2")))]
358+
// Run type-aware linting through tsgolint
359+
// TODO: Add a warning message if `tsgolint` cannot be found, but type-aware rules are enabled
360+
if self.options.type_aware {
361+
if let Err(err) = TsGoLintState::new(&cwd, config_store)
362+
.with_silent(misc_options.silent)
363+
.lint(&files_to_lint, tx_error)
355364
{
356-
use crate::raw_fs::RawTransferFileSystem;
357-
lint_service.with_file_system(Box::new(RawTransferFileSystem));
365+
print_and_flush_stdout(stdout, &err);
366+
return CliRunResult::TsGoLintError;
358367
}
359-
360-
lint_service.run(&tx_error);
361-
});
368+
} else {
369+
drop(tx_error);
370+
}
362371

363372
let diagnostic_result = diagnostic_service.run(stdout);
364373

@@ -1250,4 +1259,13 @@ mod test {
12501259
let args = &["--type-aware", "no-floating-promises", "-c", "config-test.json"];
12511260
Tester::new().with_cwd("fixtures/tsgolint".into()).test_and_snapshot(args);
12521261
}
1262+
1263+
#[test]
1264+
#[cfg(not(target_endian = "big"))]
1265+
fn test_type_aware_rule_disable_directive() {
1266+
let args = &["--type-aware", "-D", "no-floating-promises"];
1267+
Tester::new()
1268+
.with_cwd("fixtures/type_aware_rule_disable_directive".into())
1269+
.test_and_snapshot(args);
1270+
}
12531271
}

0 commit comments

Comments
 (0)