-
-
Notifications
You must be signed in to change notification settings - Fork 427
/
linter.rs
62 lines (57 loc) · 2.37 KB
/
linter.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::{
env,
path::{Path, PathBuf},
rc::Rc,
};
use oxc_allocator::Allocator;
use oxc_benchmark::{criterion_group, criterion_main, BenchmarkId, Criterion};
use oxc_linter::{AllowWarnDeny, LintOptions, Linter};
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
use oxc_span::SourceType;
use oxc_tasks_common::TestFiles;
fn bench_linter(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("linter");
// If `FIXTURE` env is set, only run the specified benchmark. This is used for sharding in CI.
let test_files = if let Ok(fixture_index) = env::var("FIXTURE") {
let fixture_index = fixture_index.parse::<usize>().unwrap();
TestFiles::complicated_one(fixture_index)
} else {
TestFiles::complicated()
};
for file in test_files.files() {
let source_type = SourceType::from_path(&file.file_name).unwrap();
group.bench_with_input(
BenchmarkId::from_parameter(&file.file_name),
&file.source_text,
|b, source_text| {
let allocator = Allocator::default();
let ret = Parser::new(&allocator, source_text, source_type).parse();
let program = allocator.alloc(ret.program);
let semantic_ret = SemanticBuilder::new(source_text, source_type)
.with_trivias(ret.trivias)
.with_cfg(true)
.build_module_record(PathBuf::new(), program)
.build(program);
let filter = vec![
(AllowWarnDeny::Deny, "all".into()),
(AllowWarnDeny::Deny, "nursery".into()),
];
let lint_options = LintOptions::default()
.with_filter(filter)
.with_import_plugin(true)
.with_jsdoc_plugin(true)
.with_jest_plugin(true)
.with_jsx_a11y_plugin(true)
.with_nextjs_plugin(true)
.with_react_perf_plugin(true);
let linter = Linter::from_options(lint_options).unwrap();
let semantic = Rc::new(semantic_ret.semantic);
b.iter(|| linter.run(Path::new(std::ffi::OsStr::new("")), Rc::clone(&semantic)));
},
);
}
group.finish();
}
criterion_group!(linter, bench_linter);
criterion_main!(linter);