diff --git a/crates/rome_analyze/CONTRIBUTING.md b/crates/rome_analyze/CONTRIBUTING.md index 7eab7219105..fb2b0772dcd 100644 --- a/crates/rome_analyze/CONTRIBUTING.md +++ b/crates/rome_analyze/CONTRIBUTING.md @@ -39,7 +39,7 @@ Let's say we want to create a new rule called `useAwesomeTricks`, which uses the 2. run the cargo alias `cargo codegen analyzer`, this command will update the file called `nursery.rs` inside the `semantic_analyzers` folder 3. from there, use the [`declare_rule`](#declare_rule) macro to create a new type - ```rust + ```rust,ignore use rome_analyze::declare_rule; declare_rule! { @@ -160,7 +160,7 @@ for more information about it; # Example The macro itself expect the following syntax: - ```rust + ```rust,ignore use rome_analyze::declare_rule; declare_rule! { @@ -185,7 +185,7 @@ use rome_analyze::declare_rule; blocks in Rust doc-comments are assumed to be written in Rust by default the language of the test must be explicitly specified, for instance: - ```rust + ```rust,ignore use rome_analyze::declare_rule; declare_rule! { /// Disallow the use of `var` @@ -206,7 +206,7 @@ declare_rule! { Additionally, it's possible to declare that a test should emit a diagnostic by adding `expect_diagnostic` to the language metadata: - ```rust + ```rust,ignore use rome_analyze::declare_rule; declare_rule! { /// Disallow the use of `var` @@ -235,7 +235,7 @@ use rome_analyze::declare_rule; In order to do, the macro allows to add additional field to add the reason for deprecation - ```rust + ```rust,ignore use rome_analyze::declare_rule; declare_rule! { diff --git a/crates/rome_analyze/src/lib.rs b/crates/rome_analyze/src/lib.rs index c2bf97c1286..68e4dbd01a9 100644 --- a/crates/rome_analyze/src/lib.rs +++ b/crates/rome_analyze/src/lib.rs @@ -26,7 +26,8 @@ pub use crate::registry::{ LanguageRoot, Phase, Phases, RegistryRuleMetadata, RuleRegistry, RuleSuppressions, }; pub use crate::rule::{ - GroupLanguage, Rule, RuleAction, RuleDiagnostic, RuleGroup, RuleMeta, RuleMetadata, + CategoryLanguage, GroupCategory, GroupLanguage, Rule, RuleAction, RuleDiagnostic, RuleGroup, + RuleMeta, RuleMetadata, }; pub use crate::services::{CannotCreateServicesError, FromServices, ServiceBag}; use crate::signals::DiagnosticSignal; @@ -524,15 +525,24 @@ pub enum RuleFilter<'a> { } impl RuleFilter<'_> { + /// Return `true` if the group `G` matches this filter + fn match_group(self) -> bool { + match self { + RuleFilter::Group(group) => group == G::NAME, + RuleFilter::Rule(group, _) => group == G::NAME, + } + } + /// Return `true` if the rule `R` matches this filter - pub fn match_rule(self) -> bool + fn match_rule(self) -> bool where - G: RuleGroup, R: Rule, { match self { - RuleFilter::Group(group) => group == G::NAME, - RuleFilter::Rule(group, rule) => group == G::NAME && rule == R::METADATA.name, + RuleFilter::Group(group) => group == ::NAME, + RuleFilter::Rule(group, rule) => { + group == ::NAME && rule == R::METADATA.name + } } } } @@ -552,22 +562,35 @@ pub struct AnalysisFilter<'a> { } impl<'analysis> AnalysisFilter<'analysis> { + /// Return `true` if the category `C` matches this filter + fn match_category(&self) -> bool { + self.categories.contains(C::CATEGORY.into()) + } + + /// Return `true` if the group `G` matches this filter + fn match_group(&self) -> bool { + self.match_category::() + && 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| filter.match_group::()) + }) + } + /// Return `true` if the rule `R` matches this filter - pub fn match_rule(&self) -> bool + fn match_rule(&self) -> bool where - G: RuleGroup, R: Rule, { - self.categories.contains(R::CATEGORY.into()) + self.match_group::() && self.enabled_rules.map_or(true, |enabled_rules| { - enabled_rules - .iter() - .any(|filter| filter.match_rule::()) + enabled_rules.iter().any(|filter| filter.match_rule::()) }) && self.disabled_rules.map_or(true, |disabled_rules| { - !disabled_rules - .iter() - .any(|filter| filter.match_rule::()) + !disabled_rules.iter().any(|filter| filter.match_rule::()) }) } diff --git a/crates/rome_analyze/src/matcher.rs b/crates/rome_analyze/src/matcher.rs index ed8b8ebf807..fa4a621b1c0 100644 --- a/crates/rome_analyze/src/matcher.rs +++ b/crates/rome_analyze/src/matcher.rs @@ -62,8 +62,8 @@ impl RuleKey { Self { group, rule } } - pub fn rule() -> Self { - Self::new(G::NAME, R::METADATA.name) + pub fn rule() -> Self { + Self::new(::NAME, R::METADATA.name) } } diff --git a/crates/rome_analyze/src/registry.rs b/crates/rome_analyze/src/registry.rs index 971423cc278..0dfd210167b 100644 --- a/crates/rome_analyze/src/registry.rs +++ b/crates/rome_analyze/src/registry.rs @@ -8,7 +8,8 @@ use crate::{ matcher::{GroupKey, MatchQueryParams}, query::{QueryKey, QueryMatch, Queryable}, signals::RuleSignal, - AnalysisFilter, QueryMatcher, Rule, RuleGroup, RuleKey, RuleMetadata, SignalEntry, + AnalysisFilter, GroupCategory, QueryMatcher, Rule, RuleGroup, RuleKey, RuleMetadata, + SignalEntry, }; /// Defines all the phases that the [RuleRegistry] supports. @@ -60,22 +61,33 @@ struct PhaseRules { } impl RuleRegistry { + pub fn push_category>(&mut self, filter: &AnalysisFilter) { + if filter.match_category::() { + C::push_groups(self, filter); + } + } + pub fn push_group>(&mut self, filter: &AnalysisFilter) { - G::push_rules(self, filter); + if filter.match_group::() { + G::push_rules(self, filter); + } } /// Add the rule `R` to the list of rules stores in this registry instance - pub fn push(&mut self) + pub fn push_rule(&mut self, filter: &AnalysisFilter) where - G: RuleGroup + 'static, R: Rule + 'static, R::Query: Queryable, ::Output: Clone, { + if !filter.match_rule::() { + return; + } + let phase = R::phase() as usize; let phase = &mut self.phase_rules[phase]; - let rule = RegistryRule::new::(phase.rule_states.len()); + let rule = RegistryRule::new::(phase.rule_states.len()); match ::KEY { QueryKey::Syntax(key) => { @@ -107,7 +119,7 @@ impl RuleRegistry { self.metadata.insert( MetadataKey { - inner: (G::NAME, R::METADATA.name), + inner: (::NAME, R::METADATA.name), }, R::METADATA, ); @@ -240,19 +252,17 @@ impl RuleSuppressions { type RuleExecutor = fn(&mut MatchQueryParams, &mut RuleState); impl RegistryRule { - fn new(state_index: usize) -> Self + fn new(state_index: usize) -> Self where - G: RuleGroup + 'static, R: Rule + 'static, R::Query: Queryable + 'static, ::Output: Clone, { /// Generic implementation of RuleExecutor for any rule type R - fn run( + fn run( params: &mut MatchQueryParams>, state: &mut RuleState>, ) where - G: RuleGroup + 'static, R: Rule + 'static, R::Query: 'static, ::Output: Clone, @@ -277,7 +287,7 @@ impl RegistryRule { R::suppressed_nodes(&ctx, &result, &mut state.suppressions); - let signal = Box::new(RuleSignal::::new( + let signal = Box::new(RuleSignal::::new( params.file_id, params.root, query_result.clone(), @@ -287,14 +297,14 @@ impl RegistryRule { params.signal_queue.push(SignalEntry { signal, - rule: RuleKey::rule::(), + rule: RuleKey::rule::(), text_range, }); } } Self { - run: run::, + run: run::, state_index, } } diff --git a/crates/rome_analyze/src/rule.rs b/crates/rome_analyze/src/rule.rs index bb621fab920..361ab1a84f7 100644 --- a/crates/rome_analyze/src/rule.rs +++ b/crates/rome_analyze/src/rule.rs @@ -46,6 +46,7 @@ impl RuleMetadata { } pub trait RuleMeta { + type Group: RuleGroup; const METADATA: RuleMetadata; } @@ -55,7 +56,7 @@ pub trait RuleMeta { /// /// The macro itself expect the following syntax: /// -/// ```rust +/// ```rust,ignore ///use rome_analyze::declare_rule; /// /// declare_rule! { @@ -81,6 +82,7 @@ macro_rules! declare_rule { $vis enum $id {} impl $crate::RuleMeta for $id { + type Group = super::Group; const METADATA: $crate::RuleMetadata = $crate::RuleMetadata::new($version, $name, concat!( $( $doc, "\n", )* )) $( .$key($value) )*; } @@ -102,9 +104,10 @@ macro_rules! declare_rule { /// disabled at once pub trait RuleGroup { type Language: Language; + type Category: GroupCategory; /// The name of this group, displayed in the diagnostics emitted by its rules const NAME: &'static str; - /// Register all the rules belonging to this group into `registry` if they match `filter` + /// Register all the rules belonging to this group into `registry` fn push_rules(registry: &mut RuleRegistry, filter: &AnalysisFilter); } @@ -117,14 +120,17 @@ macro_rules! declare_group { impl $crate::RuleGroup for $id { type Language = <( $( $( $rule )::* , )* ) as $crate::GroupLanguage>::Language; + type Category = super::Category; const NAME: &'static str = $name; fn push_rules(registry: &mut $crate::RuleRegistry, filter: &$crate::AnalysisFilter) { - $( if filter.match_rule::() { registry.push::(); } )* + $( registry.push_rule::<$( $rule )::*>(filter); )* } } + pub(self) use $id as Group; + // Declare a `group_category!` macro in the context of this module (and // all its children). This macro takes the name of a rule as a string // literal token and expands to the category of the lint rule with this @@ -142,7 +148,38 @@ macro_rules! declare_group { }; } -/// This trait is implemented for tuples of [Rule] types of size 1 to 20 if the +/// A group category is a collection of rule groups under a given category ID, +/// serving as a broad classification on the kind of diagnostic or code action +/// these rule emit, and allowing whole categories of rules to be disabled at +/// once depending on the kind of analysis being performed +pub trait GroupCategory { + type Language: Language; + /// The category ID used for all groups and rule belonging to this category + const CATEGORY: RuleCategory; + /// Register all the groups belonging to this category into `registry` + fn push_groups(registry: &mut RuleRegistry, filter: &AnalysisFilter); +} + +#[macro_export] +macro_rules! declare_category { + ( $vis:vis $id:ident { kind: $kind:ident, groups: [ $( $( $group:ident )::* , )* ] } ) => { + $vis enum $id {} + + impl $crate::GroupCategory for $id { + type Language = <( $( $( $group )::* , )* ) as $crate::CategoryLanguage>::Language; + + const CATEGORY: $crate::RuleCategory = $crate::RuleCategory::$kind; + + fn push_groups(registry: &mut $crate::RuleRegistry, filter: &$crate::AnalysisFilter) { + $( registry.push_group::<$( $group )::*>(filter); )* + } + } + + pub(self) use $id as Category; + }; +} + +/// This trait is implemented for tuples of [Rule] types of size 1 to 29 if the /// query type of all the rules in the tuple share the same associated /// [Language] (which is then aliased as the `Language` associated type on /// [GroupLanguage] itself). It is used to ensure all the rules in a given @@ -151,6 +188,15 @@ pub trait GroupLanguage { type Language: Language; } +/// This trait is implemented for tuples of [Rule] types of size 1 to 29 if the +/// language of all the groups in the tuple share the same associated +/// [Language] (which is then aliased as the `Language` associated type on +/// [CategoryLanguage] itself). It is used to ensure all the groups in a given +/// category are all querying the same underlying language +pub trait CategoryLanguage { + type Language: Language; +} + /// Helper macro for implementing [GroupLanguage] on a large number of tuple types at once macro_rules! impl_group_language { ( $head:ident $( , $rest:ident )* ) => { @@ -161,6 +207,13 @@ macro_rules! impl_group_language { type Language = RuleLanguage<$head>; } + impl<$head $( , $rest )*> CategoryLanguage for ($head, $( $rest ),*) + where + $head: RuleGroup $( , $rest: RuleGroup::Language> )* + { + type Language = <$head as RuleGroup>::Language; + } + impl_group_language!( $( $rest ),* ); }; @@ -176,10 +229,6 @@ impl_group_language!( /// and a callback function to be executed on all nodes matching the query to possibly /// raise an analysis event pub trait Rule: RuleMeta { - /// The category this rule belong to, this is used for broadly filtering - /// rules when running the analyzer - const CATEGORY: RuleCategory; - /// The type of AstNode this rule is interested in type Query: Queryable; /// A generic type that will be kept in memory between a call to `run` and diff --git a/crates/rome_analyze/src/signals.rs b/crates/rome_analyze/src/signals.rs index e3bac769adc..2d15662055f 100644 --- a/crates/rome_analyze/src/signals.rs +++ b/crates/rome_analyze/src/signals.rs @@ -11,7 +11,6 @@ use rome_diagnostics::{ Applicability, CodeSuggestion, }; use rome_rowan::{BatchMutation, Language}; -use std::marker::PhantomData; /// Event raised by the analyzer when a [Rule](crate::Rule) /// emits a diagnostic, a code action, or both @@ -85,16 +84,15 @@ where } /// Analyzer-internal implementation of [AnalyzerSignal] for a specific [Rule](crate::registry::Rule) -pub(crate) struct RuleSignal<'phase, G, R: Rule> { +pub(crate) struct RuleSignal<'phase, R: Rule> { file_id: FileId, root: &'phase RuleRoot, query_result: <::Query as Queryable>::Output, state: R::State, services: &'phase ServiceBag, - _rule: PhantomData<(G, R)>, } -impl<'phase, G, R> RuleSignal<'phase, G, R> +impl<'phase, R> RuleSignal<'phase, R> where R: Rule + 'static, { @@ -110,15 +108,13 @@ where root, query_result, state, - _rule: PhantomData, services, } } } -impl<'bag, G, R> AnalyzerSignal> for RuleSignal<'bag, G, R> +impl<'bag, R> AnalyzerSignal> for RuleSignal<'bag, R> where - G: RuleGroup, R: Rule, { fn diagnostic(&self) -> Option { @@ -130,7 +126,7 @@ where let ctx = RuleContext::new(&self.query_result, self.root, self.services).ok()?; R::action(&ctx, &self.state).map(|action| AnalyzerAction { - group_name: G::NAME, + group_name: ::NAME, rule_name: R::METADATA.name, file_id: self.file_id, category: action.category, diff --git a/crates/rome_js_analyze/src/analyzers.rs b/crates/rome_js_analyze/src/analyzers.rs index c87a5b299e7..2a9429f2bfa 100644 --- a/crates/rome_js_analyze/src/analyzers.rs +++ b/crates/rome_js_analyze/src/analyzers.rs @@ -1,8 +1,6 @@ //! Generated file, do not edit by hand, see `xtask/codegen` mod correctness; -pub(super) use self::correctness::Correctness; mod nursery; -pub(super) use self::nursery::Nursery; mod style; -pub(super) use self::style::Style; +::rome_analyze::declare_category! { pub (crate) Analyzers { kind : Lint , groups : [self :: correctness :: Correctness , self :: nursery :: Nursery , self :: style :: Style ,] } } diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_async_promise_executor.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_async_promise_executor.rs index 63fd8fa8135..14ff4bbf95e 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_async_promise_executor.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_async_promise_executor.rs @@ -1,4 +1,4 @@ -use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_syntax::{JsAnyExpression, JsAnyFunction, JsNewExpression, JsNewExpressionFields}; use rome_rowan::{AstNode, AstSeparatedList}; @@ -42,8 +42,6 @@ declare_rule! { } impl Rule for NoAsyncPromiseExecutor { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = JsAnyFunction; type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_comment_text.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_comment_text.rs index 7a206b025b5..e237f89e460 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_comment_text.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_comment_text.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -42,8 +40,6 @@ declare_rule! { } impl Rule for NoCommentText { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_compare_neg_zero.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_compare_neg_zero.rs index 66f19e38f6e..8bc0cbd38cc 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_compare_neg_zero.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_compare_neg_zero.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -41,8 +39,6 @@ declare_rule! { } impl Rule for NoCompareNegZero { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = NoCompareNegZeroState; type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_debugger.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_debugger.rs index 602425f473e..5d199303bce 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_debugger.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_debugger.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_syntax::JsDebuggerStatement; @@ -33,8 +31,6 @@ declare_rule! { } impl Rule for NoDebugger { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_delete.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_delete.rs index 8d34b3a688e..7bc3df823a2 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_delete.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_delete.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -44,8 +42,6 @@ declare_rule! { } impl Rule for NoDelete { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = MemberExpression; type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_double_equals.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_double_equals.rs index de3864d71dc..21e761993d4 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_double_equals.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_double_equals.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -54,8 +52,6 @@ declare_rule! { } impl Rule for NoDoubleEquals { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = JsSyntaxToken; type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_empty_pattern.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_empty_pattern.rs index 34e4c71f07a..f139bedc96b 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_empty_pattern.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_empty_pattern.rs @@ -1,4 +1,4 @@ -use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_syntax::{JsArrayBindingPattern, JsObjectBindingPattern}; use rome_rowan::{declare_node_union, AstNode, AstSeparatedList}; @@ -40,8 +40,6 @@ declare_rule! { } impl Rule for NoEmptyPattern { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_extra_boolean_cast.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_extra_boolean_cast.rs index 178067f9b2b..ef7e6138483 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_extra_boolean_cast.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_extra_boolean_cast.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_syntax::{ @@ -146,8 +144,6 @@ fn is_negation(node: &JsSyntaxNode) -> Option { } impl Rule for NoExtraBooleanCast { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (JsAnyExpression, ExtraBooleanCastType); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_implicit_boolean.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_implicit_boolean.rs index 63d8e0f2b3e..a48c73147d2 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_implicit_boolean.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_implicit_boolean.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -51,8 +49,6 @@ declare_rule! { } impl Rule for NoImplicitBoolean { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_multiple_spaces_in_regular_expression_literals.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_multiple_spaces_in_regular_expression_literals.rs index 0c1406d1d37..c163ddd0f51 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_multiple_spaces_in_regular_expression_literals.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_multiple_spaces_in_regular_expression_literals.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_syntax::{JsRegexLiteralExpression, JsSyntaxKind, JsSyntaxToken, TextRange, TextSize}; @@ -65,8 +63,6 @@ declare_rule! { } impl Rule for NoMultipleSpacesInRegularExpressionLiterals { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = Vec<(usize, usize)>; type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_shadow_restricted_names.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_shadow_restricted_names.rs index 1c0c0dba80b..444a19f597c 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_shadow_restricted_names.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_shadow_restricted_names.rs @@ -1,5 +1,5 @@ use crate::globals::runtime::BUILTIN; -use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_syntax::JsIdentifierBinding; use rome_rowan::AstNode; @@ -42,8 +42,6 @@ pub struct State { } impl Rule for NoShadowRestrictedNames { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = State; type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_sparse_array.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_sparse_array.rs index 2f22769b32b..8a0098e5cc5 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_sparse_array.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_sparse_array.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -27,8 +25,6 @@ declare_rule! { } impl Rule for NoSparseArray { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_unnecessary_continue.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_unnecessary_continue.rs index b0ceb39b16f..a401aa71903 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_unnecessary_continue.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_unnecessary_continue.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_syntax::{JsContinueStatement, JsLabeledStatement, JsSyntaxKind, JsSyntaxNode}; @@ -80,8 +78,6 @@ declare_rule! { } impl Rule for NoUnnecessaryContinue { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_unsafe_negation.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_unsafe_negation.rs index 2873db12817..f51dcc219f1 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_unsafe_negation.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_unsafe_negation.rs @@ -1,7 +1,5 @@ use crate::JsRuleAction; -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -40,8 +38,6 @@ declare_rule! { } impl Rule for NoUnsafeNegation { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/no_unused_template_literal.rs b/crates/rome_js_analyze/src/analyzers/correctness/no_unused_template_literal.rs index cd9b9920cc0..da16d8120a0 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/no_unused_template_literal.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/no_unused_template_literal.rs @@ -1,6 +1,6 @@ use crate::JsRuleAction; use rome_analyze::context::RuleContext; -use rome_analyze::{declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -44,8 +44,6 @@ declare_rule! { } impl Rule for NoUnusedTemplateLiteral { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/use_block_statements.rs b/crates/rome_js_analyze/src/analyzers/correctness/use_block_statements.rs index 6d72f0c19d3..289cf702033 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/use_block_statements.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/use_block_statements.rs @@ -1,9 +1,7 @@ use std::iter; use rome_analyze::context::RuleContext; -use rome_analyze::{ - declare_rule, ActionCategory, Ast, Rule, RuleAction, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{declare_rule, ActionCategory, Ast, Rule, RuleAction, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -78,8 +76,6 @@ declare_node_union! { } impl Rule for UseBlockStatements { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = UseBlockStatementsOperationType; type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/use_simplified_logic_expression.rs b/crates/rome_js_analyze/src/analyzers/correctness/use_simplified_logic_expression.rs index 3490e8ae4d7..3ffe0f9bd68 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/use_simplified_logic_expression.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/use_simplified_logic_expression.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -57,8 +55,6 @@ declare_rule! { } impl Rule for UseSimplifiedLogicExpression { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; /// First element of tuple is if the expression is simplified by [De Morgan's Law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws) rule, the second element is the expression to replace. type State = (bool, JsAnyExpression); diff --git a/crates/rome_js_analyze/src/analyzers/correctness/use_single_case_statement.rs b/crates/rome_js_analyze/src/analyzers/correctness/use_single_case_statement.rs index 70b149a19d3..1617cbdea2e 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/use_single_case_statement.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/use_single_case_statement.rs @@ -1,8 +1,6 @@ use std::iter; -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -49,8 +47,6 @@ declare_rule! { } impl Rule for UseSingleCaseStatement { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/use_single_var_declarator.rs b/crates/rome_js_analyze/src/analyzers/correctness/use_single_var_declarator.rs index 93d5ad18bb8..92a1c3d5374 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/use_single_var_declarator.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/use_single_var_declarator.rs @@ -1,8 +1,6 @@ use std::iter; -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -39,8 +37,6 @@ declare_rule! { } impl Rule for UseSingleVarDeclarator { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = ( JsSyntaxToken, diff --git a/crates/rome_js_analyze/src/analyzers/correctness/use_template.rs b/crates/rome_js_analyze/src/analyzers/correctness/use_template.rs index 74f318e0a8a..01d74f5de3b 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/use_template.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/use_template.rs @@ -1,7 +1,5 @@ use rome_analyze::RuleSuppressions; -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -55,8 +53,6 @@ declare_rule! { } impl Rule for UseTemplate { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = Vec; type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/use_valid_typeof.rs b/crates/rome_js_analyze/src/analyzers/correctness/use_valid_typeof.rs index e1d1944387b..3b649dcff2e 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/use_valid_typeof.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/use_valid_typeof.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -78,8 +76,6 @@ declare_rule! { } impl Rule for UseValidTypeof { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (TypeofError, Option<(JsAnyExpression, JsTypeName)>); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/correctness/use_while.rs b/crates/rome_js_analyze/src/analyzers/correctness/use_while.rs index f4ae803e842..65a9033bcc8 100644 --- a/crates/rome_js_analyze/src/analyzers/correctness/use_while.rs +++ b/crates/rome_js_analyze/src/analyzers/correctness/use_while.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -30,8 +28,6 @@ declare_rule! { } impl Rule for UseWhile { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/nursery/no_new_symbol.rs b/crates/rome_js_analyze/src/analyzers/nursery/no_new_symbol.rs index 76e36c8fc63..aa66dc41c58 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery/no_new_symbol.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery/no_new_symbol.rs @@ -1,7 +1,5 @@ use crate::{semantic_services::Semantic, JsRuleAction}; -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -36,8 +34,6 @@ declare_rule! { } impl Rule for NoNewSymbol { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Semantic; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/nursery/no_unreachable.rs b/crates/rome_js_analyze/src/analyzers/nursery/no_unreachable.rs index d84fd20a468..874b578eed0 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery/no_unreachable.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery/no_unreachable.rs @@ -1,7 +1,7 @@ use std::{cmp::Ordering, collections::VecDeque, num::NonZeroU32, vec::IntoIter}; use roaring::bitmap::RoaringBitmap; -use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_control_flow::{builder::BlockId, ExceptionHandler, Instruction, InstructionKind}; use rome_js_syntax::{JsLanguage, JsReturnStatement, JsSyntaxElement, JsSyntaxKind, TextRange}; @@ -48,8 +48,6 @@ declare_rule! { } impl Rule for NoUnreachable { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = ControlFlowGraph; type State = UnreachableRange; type Signals = UnreachableRanges; diff --git a/crates/rome_js_analyze/src/analyzers/nursery/use_optional_chain.rs b/crates/rome_js_analyze/src/analyzers/nursery/use_optional_chain.rs index e040e47f58f..94a0f20cf9b 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery/use_optional_chain.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery/use_optional_chain.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -85,8 +83,6 @@ pub(crate) enum UseOptionalChainState { } impl Rule for UseOptionalChain { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = UseOptionalChainState; type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/style/no_negation_else.rs b/crates/rome_js_analyze/src/analyzers/style/no_negation_else.rs index a00092aefa5..26d922cacfd 100644 --- a/crates/rome_js_analyze/src/analyzers/style/no_negation_else.rs +++ b/crates/rome_js_analyze/src/analyzers/style/no_negation_else.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -44,8 +42,6 @@ declare_rule! { } impl Rule for NoNegationElse { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = JsUnaryExpression; type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/style/use_self_closing_elements.rs b/crates/rome_js_analyze/src/analyzers/style/use_self_closing_elements.rs index 4204fb4d929..f1bd524be27 100644 --- a/crates/rome_js_analyze/src/analyzers/style/use_self_closing_elements.rs +++ b/crates/rome_js_analyze/src/analyzers/style/use_self_closing_elements.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -61,8 +59,6 @@ declare_rule! { } impl Rule for UseSelfClosingElements { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs b/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs index a6bf1d78eb2..d4989cfc7fe 100644 --- a/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs +++ b/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs @@ -1,6 +1,4 @@ -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -50,8 +48,6 @@ declare_rule! { } impl Rule for UseShorthandArrayType { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = TsType; type Signals = Option; diff --git a/crates/rome_js_analyze/src/assists.rs b/crates/rome_js_analyze/src/assists.rs index 6d85f87d1a4..19fda5f0b56 100644 --- a/crates/rome_js_analyze/src/assists.rs +++ b/crates/rome_js_analyze/src/assists.rs @@ -1,4 +1,4 @@ //! Generated file, do not edit by hand, see `xtask/codegen` mod correctness; -pub(super) use self::correctness::Correctness; +::rome_analyze::declare_category! { pub (crate) Assists { kind : Action , groups : [self :: correctness :: Correctness ,] } } diff --git a/crates/rome_js_analyze/src/assists/correctness/flip_bin_exp.rs b/crates/rome_js_analyze/src/assists/correctness/flip_bin_exp.rs index f4b3eb39009..c7e222617d8 100644 --- a/crates/rome_js_analyze/src/assists/correctness/flip_bin_exp.rs +++ b/crates/rome_js_analyze/src/assists/correctness/flip_bin_exp.rs @@ -1,4 +1,4 @@ -use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleCategory}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; @@ -25,8 +25,6 @@ declare_rule! { } impl Rule for FlipBinExp { - const CATEGORY: RuleCategory = RuleCategory::Action; - type Query = Ast; type State = JsSyntaxKind; type Signals = Option; diff --git a/crates/rome_js_analyze/src/assists/correctness/inline_variable.rs b/crates/rome_js_analyze/src/assists/correctness/inline_variable.rs index 456b60ab044..00c90b6e631 100644 --- a/crates/rome_js_analyze/src/assists/correctness/inline_variable.rs +++ b/crates/rome_js_analyze/src/assists/correctness/inline_variable.rs @@ -1,4 +1,4 @@ -use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Rule, RuleCategory}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Rule}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_semantic::{AllReferencesExtensions, Reference}; @@ -35,8 +35,6 @@ pub(crate) struct State { } impl Rule for InlineVariable { - const CATEGORY: RuleCategory = RuleCategory::Action; - type Query = Semantic; type State = State; type Signals = Option; diff --git a/crates/rome_js_analyze/src/registry.rs b/crates/rome_js_analyze/src/registry.rs index 0f7e3ffa637..eb1a6d46e16 100644 --- a/crates/rome_js_analyze/src/registry.rs +++ b/crates/rome_js_analyze/src/registry.rs @@ -4,12 +4,8 @@ use rome_analyze::{AnalysisFilter, RuleRegistry}; use rome_js_syntax::JsLanguage; pub(crate) fn build_registry(filter: &AnalysisFilter) -> RuleRegistry { let mut registry = RuleRegistry::default(); - registry.push_group::(filter); - registry.push_group::(filter); - registry.push_group::(filter); - registry.push_group::(filter); - registry.push_group::(filter); - registry.push_group::(filter); - registry.push_group::(filter); + registry.push_category::(filter); + registry.push_category::(filter); + registry.push_category::(filter); registry } diff --git a/crates/rome_js_analyze/src/semantic_analyzers.rs b/crates/rome_js_analyze/src/semantic_analyzers.rs index c87a5b299e7..e75ba2dc410 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers.rs @@ -1,8 +1,6 @@ //! Generated file, do not edit by hand, see `xtask/codegen` mod correctness; -pub(super) use self::correctness::Correctness; mod nursery; -pub(super) use self::nursery::Nursery; mod style; -pub(super) use self::style::Style; +::rome_analyze::declare_category! { pub (crate) SemanticAnalyzers { kind : Lint , groups : [self :: correctness :: Correctness , self :: nursery :: Nursery , self :: style :: Style ,] } } diff --git a/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_arguments.rs b/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_arguments.rs index acb7e665c91..c1ea69d67d7 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_arguments.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_arguments.rs @@ -1,5 +1,5 @@ use crate::{semantic_services::Semantic, JsRuleAction}; -use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_syntax::JsReferenceIdentifier; use rome_rowan::AstNode; @@ -33,8 +33,6 @@ declare_rule! { } impl Rule for NoArguments { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Semantic; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_catch_assign.rs b/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_catch_assign.rs index 1770c86a4bc..a13aefdb98d 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_catch_assign.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_catch_assign.rs @@ -1,5 +1,5 @@ use crate::{semantic_services::Semantic, JsRuleAction}; -use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_syntax::{JsCatchClause, JsSyntaxNode}; use rome_rowan::AstNode; @@ -38,8 +38,6 @@ declare_rule! { } impl Rule for NoCatchAssign { - const CATEGORY: RuleCategory = RuleCategory::Lint; - /// Why use [JsCatchClause] instead of [JsIdentifierAssignment] ? Because this could reduce search range. /// We only compare the declaration of [JsCatchClause] with all descent [JsIdentifierAssignment] of its body. type Query = Semantic; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_dupe_args.rs b/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_dupe_args.rs index 70f79276347..bae6e2a7449 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_dupe_args.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_dupe_args.rs @@ -1,4 +1,4 @@ -use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_syntax::{ JsAnyArrayBindingPatternElement, JsAnyBinding, JsAnyBindingPattern, JsAnyFormalParameter, @@ -41,8 +41,6 @@ declare_rule! { } impl Rule for NoDupeArgs { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Ast; type State = JsIdentifierBinding; type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_function_assign.rs b/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_function_assign.rs index 16763743397..49aa4ffd287 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_function_assign.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_function_assign.rs @@ -1,5 +1,5 @@ use crate::semantic_services::Semantic; -use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_semantic::{AllReferencesExtensions, Reference}; use rome_js_syntax::{JsFunctionDeclaration, JsIdentifierBinding}; @@ -106,8 +106,6 @@ pub struct State { } impl Rule for NoFunctionAssign { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Semantic; type State = State; type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_import_assign.rs b/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_import_assign.rs index d09ca8d962b..68a7cc7e6cf 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_import_assign.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_import_assign.rs @@ -1,5 +1,5 @@ use crate::semantic_services::Semantic; -use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_syntax::{ JsDefaultImportSpecifier, JsIdentifierAssignment, JsIdentifierBinding, JsImportDefaultClause, @@ -56,8 +56,6 @@ declare_rule! { } impl Rule for NoImportAssign { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Semantic; /// The first element of the tuple is the invalid `JsIdentifierAssignment`, the second element of the tuple is the imported `JsIdentifierBinding`. type State = (JsIdentifierAssignment, JsIdentifierBinding); diff --git a/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_label_var.rs b/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_label_var.rs index 8e41e7b859c..aac29aed36f 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_label_var.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_label_var.rs @@ -1,5 +1,5 @@ use crate::{semantic_services::Semantic, JsRuleAction}; -use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_syntax::{JsLabeledStatement, JsSyntaxNode, JsSyntaxToken}; use rome_rowan::AstNode; @@ -30,8 +30,6 @@ declare_rule! { } impl Rule for NoLabelVar { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Semantic; /// The first element of the tuple is the name of the binding, the second element of the tuple is the label name type State = (JsSyntaxNode, JsSyntaxToken); diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_array_index_key.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_array_index_key.rs index c91dbb8878f..7b08acd7641 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_array_index_key.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_array_index_key.rs @@ -1,7 +1,7 @@ use crate::react::{is_react_call_api, ReactApiCall, ReactCloneElementCall}; use crate::semantic_services::Semantic; use rome_analyze::context::RuleContext; -use rome_analyze::{declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_semantic::SemanticModel; use rome_js_syntax::{ @@ -120,7 +120,6 @@ pub(crate) struct NoArrayIndexKeyState { } impl Rule for NoArrayIndexKey { - const CATEGORY: RuleCategory = RuleCategory::Lint; type Query = Semantic; type State = NoArrayIndexKeyState; type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_children_prop.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_children_prop.rs index b19e6082e55..54a7892c6ff 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_children_prop.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_children_prop.rs @@ -1,7 +1,7 @@ use crate::react::{ReactApiCall, ReactCreateElementCall}; use crate::semantic_services::Semantic; use rome_analyze::context::RuleContext; -use rome_analyze::{declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_syntax::{JsCallExpression, JsPropertyObjectMember, JsxAttribute, JsxName}; use rome_rowan::{declare_node_union, AstNode}; @@ -39,7 +39,6 @@ pub(crate) enum NoChildrenPropState { } impl Rule for NoChildrenProp { - const CATEGORY: RuleCategory = RuleCategory::Syntax; type Query = Semantic; type State = NoChildrenPropState; type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_dangerously_set_inner_html.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_dangerously_set_inner_html.rs index f5a834b488e..0001ba756fc 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_dangerously_set_inner_html.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_dangerously_set_inner_html.rs @@ -1,7 +1,7 @@ use crate::react::ReactCreateElementCall; use crate::semantic_services::Semantic; use rome_analyze::context::RuleContext; -use rome_analyze::{declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Severity; use rome_js_syntax::{JsCallExpression, JsLiteralMemberName, JsxAnyAttributeName, JsxAttribute}; @@ -43,8 +43,6 @@ pub(crate) enum NoDangerState { } impl Rule for NoDangerouslySetInnerHtml { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Semantic; type State = NoDangerState; type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_dangerously_set_inner_html_with_children.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_dangerously_set_inner_html_with_children.rs index 5a8cba87353..13d366f10d2 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_dangerously_set_inner_html_with_children.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_dangerously_set_inner_html_with_children.rs @@ -1,7 +1,7 @@ use crate::react::{ReactApiCall, ReactCreateElementCall}; use crate::semantic_services::Semantic; use rome_analyze::context::RuleContext; -use rome_analyze::{declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_semantic::SemanticModel; use rome_js_syntax::{ @@ -153,7 +153,6 @@ impl JsAnyCreateElement { } impl Rule for NoDangerouslySetInnerHtmlWithChildren { - const CATEGORY: RuleCategory = RuleCategory::Lint; type Query = Semantic; type State = RuleState; type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_render_return_value.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_render_return_value.rs index 3fe9eb4297e..1271c2a43db 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_render_return_value.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_render_return_value.rs @@ -1,6 +1,6 @@ use crate::semantic_services::Semantic; use rome_analyze::context::RuleContext; -use rome_analyze::{declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_semantic::SemanticModel; use rome_js_syntax::JsSyntaxKind::JS_IMPORT; @@ -41,8 +41,6 @@ declare_rule! { } impl Rule for NoRenderReturnValue { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Semantic; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_undeclared_variables.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_undeclared_variables.rs index eb627d169c5..75e85e0e0b7 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_undeclared_variables.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_undeclared_variables.rs @@ -4,7 +4,7 @@ use crate::globals::runtime::ES_2021; use crate::globals::typescript::TYPESCRIPT_BUILTIN; use crate::semantic_services::Semantic; use rome_analyze::context::RuleContext; -use rome_analyze::{declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_semantic::Scope; use rome_js_syntax::{JsReferenceIdentifier, JsxReferenceIdentifier}; @@ -32,7 +32,6 @@ declare_node_union! { } impl Rule for NoUndeclaredVariables { - const CATEGORY: RuleCategory = RuleCategory::Lint; type Query = Semantic; type State = String; type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_unused_variables.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_unused_variables.rs index 8779244135c..0e58735e997 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_unused_variables.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_unused_variables.rs @@ -1,5 +1,5 @@ use crate::semantic_services::Semantic; -use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_js_semantic::{AllReferencesExtensions, SemanticScopeExtensions}; use rome_js_syntax::{ @@ -165,8 +165,6 @@ fn is_typescript_unused_ok(binding: &JsIdentifierBinding) -> Option<()> { } impl Rule for NoUnusedVariables { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Semantic; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_useless_fragments.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_useless_fragments.rs index 4cc87984988..c65a8829f77 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_useless_fragments.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_useless_fragments.rs @@ -2,7 +2,7 @@ use crate::react::{jsx_member_name_is_react_fragment, jsx_reference_identifier_i use crate::semantic_services::Semantic; use crate::JsRuleAction; use rome_analyze::context::RuleContext; -use rome_analyze::{declare_rule, ActionCategory, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{declare_rule, ActionCategory, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make::{ @@ -96,8 +96,6 @@ impl NoUselessFragmentsQuery { } impl Rule for NoUselessFragments { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Semantic; type State = NoUselessFragmentsState; type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_void_elements_with_children.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_void_elements_with_children.rs index bc64eda6fb1..1e1b472d112 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_void_elements_with_children.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_void_elements_with_children.rs @@ -2,7 +2,7 @@ use crate::react::{ReactApiCall, ReactCreateElementCall}; use crate::semantic_services::Semantic; use crate::JsRuleAction; use rome_analyze::context::RuleContext; -use rome_analyze::{declare_rule, ActionCategory, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{declare_rule, ActionCategory, Rule, RuleDiagnostic}; use rome_console::{markup, MarkupBuf}; use rome_diagnostics::Applicability; use rome_js_factory::make::{jsx_attribute_list, jsx_self_closing_element}; @@ -191,7 +191,6 @@ impl NoVoidElementsWithChildrenState { } impl Rule for NoVoidElementsWithChildren { - const CATEGORY: RuleCategory = RuleCategory::Lint; type Query = Semantic; type State = NoVoidElementsWithChildrenState; type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_button_type.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_button_type.rs index 17f01147adf..7b8d0c312f6 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_button_type.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_button_type.rs @@ -1,6 +1,6 @@ use crate::react::{ReactApiCall, ReactCreateElementCall}; use crate::semantic_services::Semantic; -use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Severity; use rome_js_syntax::{ @@ -59,8 +59,6 @@ pub(crate) struct UseButtonTypeState { } impl Rule for UseButtonType { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Semantic; type State = UseButtonTypeState; type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_camel_case.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_camel_case.rs index 5ca5e548436..aa09b53b7a1 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_camel_case.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_camel_case.rs @@ -3,9 +3,7 @@ use crate::{ utils::{rename::RenameSymbolExtensions, ToCamelCase}, JsRuleAction, }; -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_semantic::{AllReferencesExtensions, IsExportedCanBeQueried, SemanticModel}; @@ -97,8 +95,6 @@ fn is_non_camel_ok(binding: &JsIdentifierBinding, model: &SemanticModel) -> Opti } impl Rule for UseCamelCase { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Semantic; type State = State; type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_fragment_syntax.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_fragment_syntax.rs index ac2ac1a1463..eef42f65e91 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_fragment_syntax.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_fragment_syntax.rs @@ -2,7 +2,7 @@ use crate::react::{jsx_member_name_is_react_fragment, jsx_reference_identifier_i use crate::semantic_services::Semantic; use crate::JsRuleAction; use rome_analyze::context::RuleContext; -use rome_analyze::{declare_rule, ActionCategory, Rule, RuleCategory, RuleDiagnostic}; +use rome_analyze::{declare_rule, ActionCategory, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make::{ @@ -35,7 +35,6 @@ declare_rule! { } impl Rule for UseFragmentSyntax { - const CATEGORY: RuleCategory = RuleCategory::Lint; type Query = Semantic; type State = (); type Signals = Option; diff --git a/crates/rome_js_analyze/src/semantic_analyzers/style/no_shouty_constants.rs b/crates/rome_js_analyze/src/semantic_analyzers/style/no_shouty_constants.rs index 699acce53fe..27a17e6664c 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/style/no_shouty_constants.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/style/no_shouty_constants.rs @@ -1,7 +1,5 @@ use crate::{semantic_services::Semantic, utils::batch::JsBatchMutation, JsRuleAction}; -use rome_analyze::{ - context::RuleContext, declare_rule, ActionCategory, Rule, RuleCategory, RuleDiagnostic, -}; +use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_semantic::{AllReferencesExtensions, Reference}; @@ -84,8 +82,6 @@ pub struct State { } impl Rule for NoShoutyConstants { - const CATEGORY: RuleCategory = RuleCategory::Lint; - type Query = Semantic; type State = State; type Signals = Option; diff --git a/crates/rome_service/src/configuration/linter/rules.rs b/crates/rome_service/src/configuration/linter/rules.rs index 6fdb9ac73c3..d0f06f32261 100644 --- a/crates/rome_service/src/configuration/linter/rules.rs +++ b/crates/rome_service/src/configuration/linter/rules.rs @@ -387,6 +387,7 @@ pub struct Nursery { #[doc = r" A list of rules that belong to this group"] struct NurserySchema { no_array_index_key: Option, + no_children_prop: Option, no_dangerously_set_inner_html: Option, no_dangerously_set_inner_html_with_children: Option, no_new_symbol: Option, @@ -403,8 +404,9 @@ struct NurserySchema { } impl Nursery { const CATEGORY_NAME: &'static str = "nursery"; - pub(crate) const CATEGORY_RULES: [&'static str; 14] = [ + pub(crate) const CATEGORY_RULES: [&'static str; 15] = [ "noArrayIndexKey", + "noChildrenProp", "noDangerouslySetInnerHtml", "noDangerouslySetInnerHtmlWithChildren", "noNewSymbol", diff --git a/editors/vscode/configuration_schema.json b/editors/vscode/configuration_schema.json index ea9ec48d48d..8fff96fec86 100644 --- a/editors/vscode/configuration_schema.json +++ b/editors/vscode/configuration_schema.json @@ -491,6 +491,16 @@ } ] }, + "noChildrenProp": { + "anyOf": [ + { + "$ref": "#/definitions/RuleConfiguration" + }, + { + "type": "null" + } + ] + }, "noDangerouslySetInnerHtml": { "anyOf": [ { diff --git a/npm/backend-jsonrpc/src/workspace.ts b/npm/backend-jsonrpc/src/workspace.ts index b37bc95145b..a16ea5ff4f3 100644 --- a/npm/backend-jsonrpc/src/workspace.ts +++ b/npm/backend-jsonrpc/src/workspace.ts @@ -156,6 +156,7 @@ export interface Correctness { */ export interface Nursery { noArrayIndexKey?: RuleConfiguration; + noChildrenProp?: RuleConfiguration; noDangerouslySetInnerHtml?: RuleConfiguration; noDangerouslySetInnerHtmlWithChildren?: RuleConfiguration; noNewSymbol?: RuleConfiguration; diff --git a/website/src/docs/lint/rules/index.md b/website/src/docs/lint/rules/index.md index 621ad79d57c..e113fbb5aee 100644 --- a/website/src/docs/lint/rules/index.md +++ b/website/src/docs/lint/rules/index.md @@ -260,6 +260,13 @@ to promote these rules into a more appropriate category. Discourage the usage of Array index in keys.
+

+ noChildrenProp (since v0.10.0) + +

+Prevent passing of children as props. +
+

noDangerouslySetInnerHtml (since v0.10.0) diff --git a/website/src/docs/lint/rules/noChildrenProp.md b/website/src/docs/lint/rules/noChildrenProp.md new file mode 100644 index 00000000000..a0be573e6d3 --- /dev/null +++ b/website/src/docs/lint/rules/noChildrenProp.md @@ -0,0 +1,48 @@ +--- +title: Lint Rule noChildrenProp +layout: layouts/rule.liquid +--- + +# noChildrenProp (since v0.10.0) + +Prevent passing of **children** as props. + +When using JSX, the children should be nested between the opening and closing tags. +When not using JSX, the children should be passed as additional arguments to `React.createElement`. + +## Examples + +### Invalid + +```jsx + +``` + +{% raw %}
nursery/noChildrenProp.js:1:17 lint/nursery/noChildrenProp ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Avoid passing children using a prop
+  
+  > 1 │ <FirstComponent children={'foo'} />
+                   ^^^^^^^^
+    2 │ 
+  
+   The canonical way to pass children in React is to use JSX elements
+  
+
{% endraw %} + +```jsx +React.createElement('div', { children: 'foo' }); +``` + +{% raw %}
nursery/noChildrenProp.js:1:30 lint/nursery/noChildrenProp ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Avoid passing children using a prop
+  
+  > 1 │ React.createElement('div', { children: 'foo' });
+                                ^^^^^^^^
+    2 │ 
+  
+   The canonical way to pass children in React is to use additional arguments to React.createElement
+  
+
{% endraw %} + diff --git a/xtask/codegen/src/generate_analyzer.rs b/xtask/codegen/src/generate_analyzer.rs index 92441e7a317..0755897cfcc 100644 --- a/xtask/codegen/src/generate_analyzer.rs +++ b/xtask/codegen/src/generate_analyzer.rs @@ -21,7 +21,7 @@ pub fn generate_analyzer() -> Result<()> { fn generate_category( name: &'static str, - entries: &mut BTreeMap, + entries: &mut BTreeMap<&'static str, TokenStream>, ) -> Result<()> { let path = project_root().join("crates/rome_js_analyze/src").join(name); @@ -41,29 +41,53 @@ fn generate_category( generate_group(name, file_name)?; - let category_name = format_ident!("{}", name); let module_name = format_ident!("{}", file_name); let group_name = format_ident!("{}", to_camel_case(file_name)?); - entries.insert( - file_name.to_string(), - quote! { - registry.push_group::(filter); - }, - ); - groups.insert( file_name.to_string(), - quote! { - mod #module_name; - pub(super) use self::#module_name::#group_name; - }, + ( + quote! { + mod #module_name; + }, + quote! { + self::#module_name::#group_name + }, + ), ); } - let groups = groups.into_iter().map(|(_, tokens)| tokens); + let key = name; + let module_name = format_ident!("{name}"); + + let category_name = to_camel_case(name).unwrap(); + let category_name = format_ident!("{category_name}"); + + let kind = match name { + "syntax" => format_ident!("Syntax"), + "analyzers" | "semantic_analyzers" => format_ident!("Lint"), + "assists" => format_ident!("Action"), + _ => panic!("unimplemented analyzer category {name:?}"), + }; + + entries.insert( + key, + quote! { + registry.push_category::(filter); + }, + ); + + let (modules, paths): (Vec<_>, Vec<_>) = groups.into_iter().map(|(_, tokens)| tokens).unzip(); let tokens = xtask::reformat(quote! { - #( #groups )* + #( #modules )* + ::rome_analyze::declare_category! { + pub(crate) #category_name { + kind: #kind, + groups: [ + #( #paths, )* + ] + } + } })?; fs2::write( @@ -162,9 +186,9 @@ fn to_camel_case(input: &str) -> Result { } fn update_registry_builder( - analyzers: BTreeMap, - semantic_analyzers: BTreeMap, - assists: BTreeMap, + analyzers: BTreeMap<&'static str, TokenStream>, + semantic_analyzers: BTreeMap<&'static str, TokenStream>, + assists: BTreeMap<&'static str, TokenStream>, ) -> Result<()> { let path = project_root().join("crates/rome_js_analyze/src/registry.rs");