diff --git a/crates/oxc_linter/src/lib.rs b/crates/oxc_linter/src/lib.rs index e20c71b88..93cc7ab34 100644 --- a/crates/oxc_linter/src/lib.rs +++ b/crates/oxc_linter/src/lib.rs @@ -15,7 +15,7 @@ use std::{fs, rc::Rc}; pub use fixer::{Fixer, Message}; pub(crate) use oxc_semantic::AstNode; use oxc_semantic::Semantic; -use rule::Rule; +use rule::{Rule, RuleCategory}; use crate::{ context::LintContext, @@ -33,19 +33,17 @@ impl Linter { #[must_use] #[allow(clippy::new_without_default)] pub fn new() -> Self { - let rules_config = Self::read_rules_configuration(); - let rules = rules_config.map_or_else( - || RULES.to_vec(), - |rules_config| { - RULES - .iter() - .map(|rule| { - let value = rules_config.get(rule.name()); - rule.read_json(value.cloned()) - }) - .collect() - }, - ); + // let rules_config = Self::read_rules_configuration(); + // let rules = rules_config.map_or_else( + // || RULES.to_vec(), + // |rules_config| { + let rules = RULES + .iter() + .cloned() + .filter(|rule| rule.category() == RuleCategory::Correctness) + .collect::>(); + // }, + // ); Self::from_rules(rules) } @@ -109,6 +107,7 @@ impl Linter { ctx.into_message() } + #[allow(unused)] fn read_rules_configuration() -> Option> { fs::read_to_string(".eslintrc.json") .ok() diff --git a/crates/oxc_linter/src/rule.rs b/crates/oxc_linter/src/rule.rs index eb276603f..d0f88b41b 100644 --- a/crates/oxc_linter/src/rule.rs +++ b/crates/oxc_linter/src/rule.rs @@ -2,6 +2,7 @@ use std::fmt::Debug; use crate::{context::LintContext, AstNode}; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum RuleCategory { Correctness, Nursery, diff --git a/crates/oxc_macros/src/declare_all_lint_rules.rs b/crates/oxc_macros/src/declare_all_lint_rules.rs index cb4f23258..1d5817298 100644 --- a/crates/oxc_macros/src/declare_all_lint_rules.rs +++ b/crates/oxc_macros/src/declare_all_lint_rules.rs @@ -71,6 +71,7 @@ impl Parse for AllLintRulesMeta { } } +#[allow(clippy::cognitive_complexity)] pub fn declare_all_lint_rules(metadata: AllLintRulesMeta) -> TokenStream { let AllLintRulesMeta { rules } = metadata; @@ -82,7 +83,7 @@ pub fn declare_all_lint_rules(metadata: AllLintRulesMeta) -> TokenStream { #(#mod_stmts)* #(#use_stmts)* - use crate::{context::LintContext, rule::Rule, rule::RuleMeta, AstNode}; + use crate::{context::LintContext, rule::{Rule, RuleCategory}, rule::RuleMeta, AstNode}; #[derive(Debug, Clone)] #[allow(clippy::enum_variant_names)] @@ -91,12 +92,18 @@ pub fn declare_all_lint_rules(metadata: AllLintRulesMeta) -> TokenStream { } impl RuleEnum { - pub const fn name(&self) -> &'static str { + pub fn name(&self) -> &'static str { match self { #(Self::#struct_names(_) => #struct_names::NAME),* } } + pub fn category(&self) -> RuleCategory { + match self { + #(Self::#struct_names(_) => #struct_names::CATEGORY),* + } + } + pub fn read_json(&self, maybe_value: Option) -> Self { match self { #(Self::#struct_names(_) => Self::#struct_names(