From 0221b063002ca5a5432bf7af6790cc9a00ed47e2 Mon Sep 17 00:00:00 2001 From: Victorien Elvinger Date: Thu, 23 May 2024 17:04:05 +0200 Subject: [PATCH] refactor: use directly Vec slices --- crates/biome_analyze/src/lib.rs | 25 +++++++++++-------- crates/biome_service/src/file_handlers/css.rs | 2 +- .../src/file_handlers/javascript.rs | 2 +- .../biome_service/src/file_handlers/json.rs | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/crates/biome_analyze/src/lib.rs b/crates/biome_analyze/src/lib.rs index c6fcff2cdd05..c4d60fff800c 100644 --- a/crates/biome_analyze/src/lib.rs +++ b/crates/biome_analyze/src/lib.rs @@ -823,9 +823,10 @@ pub struct AnalysisFilter<'a> { /// Only allow rules with these categories to emit signals pub categories: RuleCategories, /// Only allow rules matching these names to emit signals + /// If `enabled_rules` is set to `None`, then all rules are enabled. pub enabled_rules: Option<&'a [RuleFilter<'a>]>, /// Do not allow rules matching these names to emit signals - pub disabled_rules: Option<&'a [RuleFilter<'a>]>, + pub disabled_rules: &'a [RuleFilter<'a>], /// Only emit signals matching this text range pub range: Option, } @@ -850,20 +851,22 @@ impl<'analysis> AnalysisFilter<'analysis> { && self.enabled_rules.map_or(true, |enabled_rules| { enabled_rules.iter().any(|filter| filter.match_group::()) }) - && self.disabled_rules.map_or(true, |disabled_rules| { - !disabled_rules.iter().any(|filter| { - matches!(filter, RuleFilter::Group(_)) && filter.match_group::() - }) - }) + && !self + .disabled_rules + .iter() + .any(|filter| matches!(filter, RuleFilter::Group(_)) && filter.match_group::()) } /// Return `true` if the rule `R` matches this filter pub fn match_rule(&self) -> bool { - self.enabled_rules.map_or(true, |enabled_rules| { - enabled_rules.iter().any(|filter| filter.match_rule::()) - }) && self.disabled_rules.map_or(true, |disabled_rules| { - !disabled_rules.iter().any(|filter| filter.match_rule::()) - }) + self.match_category::<::Category>() + && self.enabled_rules.map_or(true, |enabled_rules| { + enabled_rules.iter().any(|filter| filter.match_rule::()) + }) + && !self + .disabled_rules + .iter() + .any(|filter| filter.match_rule::()) } } diff --git a/crates/biome_service/src/file_handlers/css.rs b/crates/biome_service/src/file_handlers/css.rs index b86f27bf56d9..135ff5772af8 100644 --- a/crates/biome_service/src/file_handlers/css.rs +++ b/crates/biome_service/src/file_handlers/css.rs @@ -354,7 +354,7 @@ fn lint(params: LintParams) -> LintResults { let filter = AnalysisFilter { categories: params.categories, enabled_rules: Some(enabled_rules.as_slice()), - disabled_rules: (!disabled_rules.is_empty()).then_some(&disabled_rules), + disabled_rules: &disabled_rules, range: None, }; diff --git a/crates/biome_service/src/file_handlers/javascript.rs b/crates/biome_service/src/file_handlers/javascript.rs index d1e9cbbb6d93..44274c7a9e6a 100644 --- a/crates/biome_service/src/file_handlers/javascript.rs +++ b/crates/biome_service/src/file_handlers/javascript.rs @@ -412,7 +412,7 @@ pub(crate) fn lint(params: LintParams) -> LintResults { let filter = AnalysisFilter { categories: params.categories, enabled_rules: Some(enabled_rules.as_slice()), - disabled_rules: (!disabled_rules.is_empty()).then_some(&disabled_rules), + disabled_rules: &disabled_rules, range: None, }; diff --git a/crates/biome_service/src/file_handlers/json.rs b/crates/biome_service/src/file_handlers/json.rs index 200656e188a9..0d1fc890ce08 100644 --- a/crates/biome_service/src/file_handlers/json.rs +++ b/crates/biome_service/src/file_handlers/json.rs @@ -336,7 +336,7 @@ fn lint(params: LintParams) -> LintResults { let filter = AnalysisFilter { categories: params.categories, enabled_rules: Some(enabled_rules.as_slice()), - disabled_rules: (!disabled_rules.is_empty()).then_some(&disabled_rules), + disabled_rules: &disabled_rules, range: None, };