refactor(cli): collect all the paths before linting

This commit is contained in:
Boshen 2023-09-03 16:36:02 +08:00
parent deb50e1a25
commit b9bd5ff7ab
No known key found for this signature in database
GPG key ID: 9C7A8C8AB22BEBD1

View file

@ -1,10 +1,4 @@
use std::{
io::BufWriter,
sync::{
atomic::{AtomicUsize, Ordering},
Arc,
},
};
use std::{io::BufWriter, sync::Arc};
use oxc_diagnostics::DiagnosticService;
use oxc_linter::{LintOptions, LintService, Linter, PathWork};
@ -51,24 +45,18 @@ impl Runner for LintRunner {
.with_quiet(warning_options.quiet)
.with_max_warnings(warning_options.max_warnings);
let number_of_files = Arc::new(AtomicUsize::new(0));
let lint_service = LintService::new(Arc::clone(&linter));
let tx_path = lint_service.tx_path.clone();
lint_service.run(&diagnostic_service.sender().clone());
rayon::spawn({
let number_of_files = Arc::clone(&number_of_files);
let walk = Walk::new(&paths, &ignore_options);
move || {
let mut count = 0;
for path in walk.iter() {
count += 1;
tx_path.send(PathWork::Begin(path)).unwrap();
}
tx_path.send(PathWork::Done).unwrap();
number_of_files.store(count, Ordering::SeqCst);
let paths = Walk::new(&paths, &ignore_options).iter().collect::<Vec<_>>();
let number_of_files = paths.len();
rayon::spawn(move || {
for path in &paths {
tx_path.send(PathWork::Begin(path.clone())).unwrap();
}
tx_path.send(PathWork::Done).unwrap();
});
diagnostic_service.run();
@ -77,7 +65,7 @@ impl Runner for LintRunner {
CliRunResult::LintResult(LintResult {
duration: now.elapsed(),
number_of_rules: linter.number_of_rules(),
number_of_files: number_of_files.load(Ordering::SeqCst),
number_of_files,
number_of_warnings: diagnostic_service.warnings_count(),
number_of_errors: diagnostic_service.errors_count(),
max_warnings_exceeded: diagnostic_service.max_warnings_exceeded(),