Skip to content

Commit

Permalink
refactor: use directly Vec slices
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed May 24, 2024
1 parent 3ba4a5f commit 0221b06
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
25 changes: 14 additions & 11 deletions crates/biome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextRange>,
}
Expand All @@ -850,20 +851,22 @@ impl<'analysis> AnalysisFilter<'analysis> {
&& self.enabled_rules.map_or(true, |enabled_rules| {
enabled_rules.iter().any(|filter| filter.match_group::<G>())
})
&& self.disabled_rules.map_or(true, |disabled_rules| {
!disabled_rules.iter().any(|filter| {
matches!(filter, RuleFilter::Group(_)) && filter.match_group::<G>()
})
})
&& !self
.disabled_rules
.iter()
.any(|filter| matches!(filter, RuleFilter::Group(_)) && filter.match_group::<G>())
}

/// Return `true` if the rule `R` matches this filter
pub fn match_rule<R: Rule>(&self) -> bool {
self.enabled_rules.map_or(true, |enabled_rules| {
enabled_rules.iter().any(|filter| filter.match_rule::<R>())
}) && self.disabled_rules.map_or(true, |disabled_rules| {
!disabled_rules.iter().any(|filter| filter.match_rule::<R>())
})
self.match_category::<<R::Group as RuleGroup>::Category>()
&& self.enabled_rules.map_or(true, |enabled_rules| {
enabled_rules.iter().any(|filter| filter.match_rule::<R>())
})
&& !self
.disabled_rules
.iter()
.any(|filter| filter.match_rule::<R>())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_service/src/file_handlers/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_service/src/file_handlers/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_service/src/file_handlers/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down

0 comments on commit 0221b06

Please sign in to comment.