feat(linter): add suspicious and pedantic categories

This commit is contained in:
Boshen 2023-06-21 11:08:26 +08:00
parent 66d1c7b1de
commit 42b97fc270
14 changed files with 22 additions and 12 deletions

View file

@ -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<Self> {
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"),
}

View file

@ -41,7 +41,7 @@ declare_oxc_lint!(
/// }
/// ```
ConstructorSuper,
nursery
correctness
);
impl Rule for ConstructorSuper {

View file

@ -31,7 +31,7 @@ declare_oxc_lint!(
/// a == b
/// ```
EqEqEq,
nursery
pedantic
);
fn to_strict_operator(operator: BinaryOperator) -> BinaryOperator {

View file

@ -29,7 +29,7 @@ declare_oxc_lint!(
/// let arr = new Array();
/// ```
NoArrayConstructor,
nursery
pedantic
);
impl Rule for NoArrayConstructor {

View file

@ -39,7 +39,7 @@ declare_oxc_lint!(
/// var x = y | z;
/// ```
NoBitwise,
nursery
restriction
);
impl Rule for NoBitwise {

View file

@ -35,7 +35,7 @@ declare_oxc_lint!(
/// }
/// ```
NoConstantCondition,
nursery
correctness
);
impl Rule for NoConstantCondition {

View file

@ -33,7 +33,7 @@ declare_oxc_lint!(
/// }
/// ```
NoEmpty,
nursery,
restriction,
);
impl Rule for NoEmpty {

View file

@ -71,7 +71,7 @@ declare_oxc_lint!(
/// ```
///
NoEmptyPattern,
nursery,
suspicious,
);
impl Rule for NoEmptyPattern {

View file

@ -49,7 +49,7 @@ declare_oxc_lint!(
/// eval(someString);
/// ```
NoEval,
nursery
correctness
);
impl Rule for NoEval {

View file

@ -35,7 +35,7 @@ declare_oxc_lint!(
/// foo = bar;
/// ```
NoFunctionAssign,
nursery
correctness
);
impl Rule for NoFunctionAssign {

View file

@ -52,7 +52,7 @@ declare_oxc_lint! {
/// var foo = a && (b || c || d); /*GOOD*/
/// ```
NoMixedOperators,
nursery,
pedantic,
}
impl Rule for NoMixedOperators {

View file

@ -74,7 +74,7 @@ declare_oxc_lint!(
/// foo > NaN;
/// ```
UseIsnan,
nursery,
correctness,
);
impl Rule for UseIsnan {

View file

@ -45,7 +45,7 @@ declare_oxc_lint!(
/// typeof foo === baz
/// ```
ValidTypeof,
nursery,
correctness,
);
impl Rule for ValidTypeof {

View file

@ -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"),