From 42b97fc270e2e1601d8f1c93379cda712cd94255 Mon Sep 17 00:00:00 2001 From: Boshen Date: Wed, 21 Jun 2023 11:08:26 +0800 Subject: [PATCH] feat(linter): add suspicious and pedantic categories --- crates/oxc_linter/src/rule.rs | 8 ++++++++ crates/oxc_linter/src/rules/constructor_super.rs | 2 +- crates/oxc_linter/src/rules/eq_eq_eq.rs | 2 +- crates/oxc_linter/src/rules/no_array_constructor.rs | 2 +- crates/oxc_linter/src/rules/no_bitwise.rs | 2 +- crates/oxc_linter/src/rules/no_constant_condition.rs | 2 +- crates/oxc_linter/src/rules/no_empty.rs | 2 +- crates/oxc_linter/src/rules/no_empty_pattern.rs | 2 +- crates/oxc_linter/src/rules/no_eval.rs | 2 +- crates/oxc_linter/src/rules/no_function_assign.rs | 2 +- crates/oxc_linter/src/rules/no_mixed_operators.rs | 2 +- crates/oxc_linter/src/rules/use_isnan.rs | 2 +- crates/oxc_linter/src/rules/valid_typeof.rs | 2 +- crates/oxc_macros/src/declare_oxc_lint.rs | 2 ++ 14 files changed, 22 insertions(+), 12 deletions(-) diff --git a/crates/oxc_linter/src/rule.rs b/crates/oxc_linter/src/rule.rs index 023edab27..90d8639a5 100644 --- a/crates/oxc_linter/src/rule.rs +++ b/crates/oxc_linter/src/rule.rs @@ -30,6 +30,10 @@ pub trait RuleMeta { pub enum RuleCategory { /// Code that is outright wrong or useless Correctness, + /// + Suspicious, + /// Pedantic + Pedantic, /// Lints which prevent the use of language and library features /// The restriction category should, emphatically, not be enabled as a whole. /// The contained lints may lint against perfectly reasonable code, may not have an alternative suggestion, @@ -44,6 +48,8 @@ impl RuleCategory { pub fn from(input: &str) -> Option { match input { "correctness" => Some(Self::Correctness), + "suspicious" => Some(Self::Suspicious), + "pedantic" => Some(Self::Pedantic), "restriction" => Some(Self::Restriction), "nursery" => Some(Self::Nursery), _ => None, @@ -55,6 +61,8 @@ impl fmt::Display for RuleCategory { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Correctness => write!(f, "Correctness"), + Self::Suspicious => write!(f, "Suspicious"), + Self::Pedantic => write!(f, "Pedantic"), Self::Restriction => write!(f, "Restriction"), Self::Nursery => write!(f, "Nursery"), } diff --git a/crates/oxc_linter/src/rules/constructor_super.rs b/crates/oxc_linter/src/rules/constructor_super.rs index 25218fbf4..8976b4eef 100644 --- a/crates/oxc_linter/src/rules/constructor_super.rs +++ b/crates/oxc_linter/src/rules/constructor_super.rs @@ -41,7 +41,7 @@ declare_oxc_lint!( /// } /// ``` ConstructorSuper, - nursery + correctness ); impl Rule for ConstructorSuper { diff --git a/crates/oxc_linter/src/rules/eq_eq_eq.rs b/crates/oxc_linter/src/rules/eq_eq_eq.rs index 9feb64079..a8c7193df 100644 --- a/crates/oxc_linter/src/rules/eq_eq_eq.rs +++ b/crates/oxc_linter/src/rules/eq_eq_eq.rs @@ -31,7 +31,7 @@ declare_oxc_lint!( /// a == b /// ``` EqEqEq, - nursery + pedantic ); fn to_strict_operator(operator: BinaryOperator) -> BinaryOperator { diff --git a/crates/oxc_linter/src/rules/no_array_constructor.rs b/crates/oxc_linter/src/rules/no_array_constructor.rs index a45031085..c28227fe3 100644 --- a/crates/oxc_linter/src/rules/no_array_constructor.rs +++ b/crates/oxc_linter/src/rules/no_array_constructor.rs @@ -29,7 +29,7 @@ declare_oxc_lint!( /// let arr = new Array(); /// ``` NoArrayConstructor, - nursery + pedantic ); impl Rule for NoArrayConstructor { diff --git a/crates/oxc_linter/src/rules/no_bitwise.rs b/crates/oxc_linter/src/rules/no_bitwise.rs index cb6d4d537..619e8116a 100644 --- a/crates/oxc_linter/src/rules/no_bitwise.rs +++ b/crates/oxc_linter/src/rules/no_bitwise.rs @@ -39,7 +39,7 @@ declare_oxc_lint!( /// var x = y | z; /// ``` NoBitwise, - nursery + restriction ); impl Rule for NoBitwise { diff --git a/crates/oxc_linter/src/rules/no_constant_condition.rs b/crates/oxc_linter/src/rules/no_constant_condition.rs index 62e460001..b17d21335 100644 --- a/crates/oxc_linter/src/rules/no_constant_condition.rs +++ b/crates/oxc_linter/src/rules/no_constant_condition.rs @@ -35,7 +35,7 @@ declare_oxc_lint!( /// } /// ``` NoConstantCondition, - nursery + correctness ); impl Rule for NoConstantCondition { diff --git a/crates/oxc_linter/src/rules/no_empty.rs b/crates/oxc_linter/src/rules/no_empty.rs index acad2e6ab..d382c1e55 100644 --- a/crates/oxc_linter/src/rules/no_empty.rs +++ b/crates/oxc_linter/src/rules/no_empty.rs @@ -33,7 +33,7 @@ declare_oxc_lint!( /// } /// ``` NoEmpty, - nursery, + restriction, ); impl Rule for NoEmpty { diff --git a/crates/oxc_linter/src/rules/no_empty_pattern.rs b/crates/oxc_linter/src/rules/no_empty_pattern.rs index 32263a3c8..8893a59f8 100644 --- a/crates/oxc_linter/src/rules/no_empty_pattern.rs +++ b/crates/oxc_linter/src/rules/no_empty_pattern.rs @@ -71,7 +71,7 @@ declare_oxc_lint!( /// ``` /// NoEmptyPattern, - nursery, + suspicious, ); impl Rule for NoEmptyPattern { diff --git a/crates/oxc_linter/src/rules/no_eval.rs b/crates/oxc_linter/src/rules/no_eval.rs index b236028e9..1ad15bb61 100644 --- a/crates/oxc_linter/src/rules/no_eval.rs +++ b/crates/oxc_linter/src/rules/no_eval.rs @@ -49,7 +49,7 @@ declare_oxc_lint!( /// eval(someString); /// ``` NoEval, - nursery + correctness ); impl Rule for NoEval { diff --git a/crates/oxc_linter/src/rules/no_function_assign.rs b/crates/oxc_linter/src/rules/no_function_assign.rs index d1015d1ef..db206998e 100644 --- a/crates/oxc_linter/src/rules/no_function_assign.rs +++ b/crates/oxc_linter/src/rules/no_function_assign.rs @@ -35,7 +35,7 @@ declare_oxc_lint!( /// foo = bar; /// ``` NoFunctionAssign, - nursery + correctness ); impl Rule for NoFunctionAssign { diff --git a/crates/oxc_linter/src/rules/no_mixed_operators.rs b/crates/oxc_linter/src/rules/no_mixed_operators.rs index 461a236d6..bde348f33 100644 --- a/crates/oxc_linter/src/rules/no_mixed_operators.rs +++ b/crates/oxc_linter/src/rules/no_mixed_operators.rs @@ -52,7 +52,7 @@ declare_oxc_lint! { /// var foo = a && (b || c || d); /*GOOD*/ /// ``` NoMixedOperators, - nursery, + pedantic, } impl Rule for NoMixedOperators { diff --git a/crates/oxc_linter/src/rules/use_isnan.rs b/crates/oxc_linter/src/rules/use_isnan.rs index e249ec266..aeeaa4bf6 100644 --- a/crates/oxc_linter/src/rules/use_isnan.rs +++ b/crates/oxc_linter/src/rules/use_isnan.rs @@ -74,7 +74,7 @@ declare_oxc_lint!( /// foo > NaN; /// ``` UseIsnan, - nursery, + correctness, ); impl Rule for UseIsnan { diff --git a/crates/oxc_linter/src/rules/valid_typeof.rs b/crates/oxc_linter/src/rules/valid_typeof.rs index 6bbc50f11..80a58c0cb 100644 --- a/crates/oxc_linter/src/rules/valid_typeof.rs +++ b/crates/oxc_linter/src/rules/valid_typeof.rs @@ -45,7 +45,7 @@ declare_oxc_lint!( /// typeof foo === baz /// ``` ValidTypeof, - nursery, + correctness, ); impl Rule for ValidTypeof { diff --git a/crates/oxc_macros/src/declare_oxc_lint.rs b/crates/oxc_macros/src/declare_oxc_lint.rs index 65e6bc3e7..c42517676 100644 --- a/crates/oxc_macros/src/declare_oxc_lint.rs +++ b/crates/oxc_macros/src/declare_oxc_lint.rs @@ -60,6 +60,8 @@ pub fn declare_oxc_lint(metadata: LintRuleMeta) -> TokenStream { let canonical_name = name.to_string().to_case(Case::Kebab); let category = match category.to_string().as_str() { "correctness" => quote! { RuleCategory::Correctness }, + "suspicious" => quote! { RuleCategory::Suspicious }, + "pedantic" => quote! { RuleCategory::Pedantic }, "restriction" => quote! { RuleCategory::Restriction }, "nursery" => quote! { RuleCategory::Nursery }, _ => panic!("invalid rule category"),