chore(benchmark): reopen jest and jsx-a11y for benchmark (#1169)

This commit is contained in:
Wenzhe Wang 2023-11-07 10:48:16 +08:00 committed by GitHub
parent 9b66646278
commit 6a03775c49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 14 deletions

View file

@ -89,6 +89,7 @@ const JSX_A11Y_PLUGIN_NAME: &str = "jsx_a11y";
impl LintOptions {
pub fn derive_rules(&self) -> Vec<RuleEnum> {
let mut rules: FxHashSet<RuleEnum> = FxHashSet::default();
let all_rules = self.get_filtered_rules();
for (allow_warn_deny, name_or_category) in &self.filter {
let maybe_category = RuleCategory::from(name_or_category.as_str());
@ -96,14 +97,14 @@ impl LintOptions {
AllowWarnDeny::Deny => {
match maybe_category {
Some(category) => rules.extend(
RULES.iter().filter(|rule| rule.category() == category).cloned(),
all_rules.iter().filter(|rule| rule.category() == category).cloned(),
),
None => {
if name_or_category == "all" {
rules.extend(RULES.iter().cloned());
rules.extend(all_rules.iter().cloned());
} else {
rules.extend(
RULES
all_rules
.iter()
.filter(|rule| rule.name() == name_or_category)
.cloned(),
@ -127,24 +128,25 @@ impl LintOptions {
}
}
self.extends_or_exclude_plugins(&mut rules);
let mut rules = rules.into_iter().collect::<Vec<_>>();
// for stable diagnostics output ordering
rules.sort_unstable_by_key(RuleEnum::name);
rules
}
fn extends_or_exclude_plugins(&self, rules: &mut FxHashSet<RuleEnum>) {
let mut extends_or_exclude = |yes: bool, name: &str| {
if yes {
rules.extend(RULES.iter().filter(|rule| rule.plugin_name() == name).cloned());
} else {
// get final filtered rules by reading `self.jest_plugin` and `self.jsx_a11y_plugin`
fn get_filtered_rules(&self) -> Vec<RuleEnum> {
let mut rules = RULES.clone();
let mut may_exclude_plugin_rules = |yes: bool, name: &str| {
if !yes {
rules.retain(|rule| rule.plugin_name() != name);
}
};
extends_or_exclude(self.jest_plugin, JEST_PLUGIN_NAME);
extends_or_exclude(self.jsx_a11y_plugin, JSX_A11Y_PLUGIN_NAME);
may_exclude_plugin_rules(self.jest_plugin, JEST_PLUGIN_NAME);
may_exclude_plugin_rules(self.jsx_a11y_plugin, JSX_A11Y_PLUGIN_NAME);
rules
}
}

View file

@ -31,8 +31,10 @@ fn bench_linter(criterion: &mut Criterion) {
.with_trivias(ret.trivias)
.build_module_record(PathBuf::new(), program)
.build(program);
let lint_options =
LintOptions::default().with_filter(vec![(AllowWarnDeny::Deny, "all".into())]);
let lint_options = LintOptions::default()
.with_filter(vec![(AllowWarnDeny::Deny, "all".into())])
.with_jest_plugin(true)
.with_jsx_a11y_plugin(true);
let linter = Linter::from_options(lint_options);
let semantic = Rc::new(semantic_ret.semantic);
b.iter(|| {