diff --git a/crates/biome_configuration/src/analyzer/assists/actions.rs b/crates/biome_configuration/src/analyzer/assists/actions.rs index d0629b6e2415..af5b307e06c1 100644 --- a/crates/biome_configuration/src/analyzer/assists/actions.rs +++ b/crates/biome_configuration/src/analyzer/assists/actions.rs @@ -86,12 +86,10 @@ impl Actions { #[doc = r" The enabled rules are calculated from the difference with the disabled rules."] pub fn as_enabled_rules(&self) -> FxHashSet> { let mut enabled_rules = FxHashSet::default(); - let mut disabled_rules = FxHashSet::default(); if let Some(group) = self.source.as_ref() { enabled_rules.extend(&group.get_enabled_rules()); - disabled_rules.extend(&group.get_disabled_rules()); } - enabled_rules.difference(&disabled_rules).copied().collect() + enabled_rules } } #[derive(Clone, Debug, Default, Deserialize, Deserializable, Eq, Merge, PartialEq, Serialize)] @@ -135,25 +133,6 @@ impl Source { } index_set } - pub(crate) fn get_disabled_rules(&self) -> FxHashSet> { - let mut index_set = FxHashSet::default(); - if let Some(rule) = self.organize_imports.as_ref() { - if rule.is_disabled() { - index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[0])); - } - } - if let Some(rule) = self.use_sorted_attributes.as_ref() { - if rule.is_disabled() { - index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[1])); - } - } - if let Some(rule) = self.use_sorted_keys.as_ref() { - if rule.is_disabled() { - index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[2])); - } - } - index_set - } #[doc = r" Checks if, given a rule name, matches one of the rules contained in this category"] pub(crate) fn has_rule(rule_name: &str) -> Option<&'static str> { Some(Self::GROUP_RULES[Self::GROUP_RULES.binary_search(&rule_name).ok()?]) diff --git a/crates/biome_service/src/file_handlers/mod.rs b/crates/biome_service/src/file_handlers/mod.rs index adbc67c57024..bf63bd562bfb 100644 --- a/crates/biome_service/src/file_handlers/mod.rs +++ b/crates/biome_service/src/file_handlers/mod.rs @@ -43,6 +43,7 @@ use biome_string_case::StrLikeExtension; use grit::GritFileHandler; use html::HtmlFileHandler; pub use javascript::JsFormatterSettings; +use rustc_hash::FxHashSet; use std::borrow::Cow; use std::ffi::OsStr; use std::path::Path; @@ -825,25 +826,25 @@ impl<'a> RegistryVisitor for SyntaxVisitor<'a> { /// #[derive(Debug)] struct LintVisitor<'a, 'b> { - pub(crate) enabled_rules: Vec>, - pub(crate) disabled_rules: Vec>, + pub(crate) enabled_rules: FxHashSet>, + pub(crate) disabled_rules: FxHashSet>, // lint_params: &'b LintParams<'a>, - only: &'b Vec, - skip: &'b Vec, + only: &'b [RuleSelector], + skip: &'b [RuleSelector], settings: Option<&'b Settings>, path: &'b Path, } impl<'a, 'b> LintVisitor<'a, 'b> { pub(crate) fn new( - only: &'b Vec, - skip: &'b Vec, + only: &'b [RuleSelector], + skip: &'b [RuleSelector], settings: Option<&'b Settings>, path: &'b Path, ) -> Self { Self { - enabled_rules: vec![], - disabled_rules: vec![], + enabled_rules: Default::default(), + disabled_rules: Default::default(), only, skip, settings, @@ -851,20 +852,17 @@ impl<'a, 'b> LintVisitor<'a, 'b> { } } - fn finish(mut self) -> (Vec>, Vec>) { + fn finish(mut self) -> (FxHashSet>, FxHashSet>) { let has_only_filter = !self.only.is_empty(); - let enabled_rules = if !has_only_filter { - self.settings + if !has_only_filter { + let enabled_rules = self + .settings .and_then(|settings| settings.as_linter_rules(self.path)) .as_ref() .map(|rules| rules.as_enabled_rules()) - .unwrap_or_default() - .into_iter() - .collect::>() - } else { - vec![] - }; - self.enabled_rules.extend(enabled_rules); + .unwrap_or_default(); + self.enabled_rules.extend(enabled_rules); + } (self.enabled_rules, self.disabled_rules) } @@ -878,13 +876,13 @@ impl<'a, 'b> LintVisitor<'a, 'b> { for selector in self.only { let filter = RuleFilter::from(selector); if filter.match_rule::() { - self.enabled_rules.push(filter) + self.enabled_rules.insert(filter); } } for selector in self.skip { let filter = RuleFilter::from(selector); if filter.match_rule::() { - self.disabled_rules.push(filter) + self.disabled_rules.insert(filter); } } } @@ -1171,8 +1169,8 @@ impl<'a, 'b> AnalyzerVisitorBuilder<'a, 'b> { #[must_use] pub(crate) fn with_linter_rules( mut self, - only: &'b Vec, - skip: &'b Vec, + only: &'b [RuleSelector], + skip: &'b [RuleSelector], path: &'b Path, ) -> Self { self.lint = Some(LintVisitor::new(only, skip, self.settings, path)); diff --git a/xtask/codegen/src/generate_configuration.rs b/xtask/codegen/src/generate_configuration.rs index b94e51859a5e..d6198c8b4916 100644 --- a/xtask/codegen/src/generate_configuration.rs +++ b/xtask/codegen/src/generate_configuration.rs @@ -260,7 +260,6 @@ fn generate_for_groups( quote! { if let Some(group) = self.#group_ident.as_ref() { enabled_rules.extend(&group.get_enabled_rules()); - disabled_rules.extend(&group.get_disabled_rules()); } } }); @@ -418,10 +417,8 @@ fn generate_for_groups( /// The enabled rules are calculated from the difference with the disabled rules. pub fn as_enabled_rules(&self) -> FxHashSet> { let mut enabled_rules = FxHashSet::default(); - let mut disabled_rules = FxHashSet::default(); #( #group_as_default_rules )* - - enabled_rules.difference(&disabled_rules).copied().collect() + enabled_rules } } @@ -841,12 +838,6 @@ fn generate_group_struct( index_set } - pub(crate) fn get_disabled_rules(&self) -> FxHashSet> { - let mut index_set = FxHashSet::default(); - #( #rule_disabled_check_line )* - index_set - } - /// Checks if, given a rule name, matches one of the rules contained in this category pub(crate) fn has_rule(rule_name: &str) -> Option<&'static str> { Some(Self::GROUP_RULES[Self::GROUP_RULES.binary_search(&rule_name).ok()?])