mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(linter): add suspicious and pedantic categories
This commit is contained in:
parent
66d1c7b1de
commit
42b97fc270
14 changed files with 22 additions and 12 deletions
|
|
@ -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"),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ declare_oxc_lint!(
|
|||
/// }
|
||||
/// ```
|
||||
ConstructorSuper,
|
||||
nursery
|
||||
correctness
|
||||
);
|
||||
|
||||
impl Rule for ConstructorSuper {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ declare_oxc_lint!(
|
|||
/// a == b
|
||||
/// ```
|
||||
EqEqEq,
|
||||
nursery
|
||||
pedantic
|
||||
);
|
||||
|
||||
fn to_strict_operator(operator: BinaryOperator) -> BinaryOperator {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ declare_oxc_lint!(
|
|||
/// let arr = new Array();
|
||||
/// ```
|
||||
NoArrayConstructor,
|
||||
nursery
|
||||
pedantic
|
||||
);
|
||||
|
||||
impl Rule for NoArrayConstructor {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ declare_oxc_lint!(
|
|||
/// var x = y | z;
|
||||
/// ```
|
||||
NoBitwise,
|
||||
nursery
|
||||
restriction
|
||||
);
|
||||
|
||||
impl Rule for NoBitwise {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ declare_oxc_lint!(
|
|||
/// }
|
||||
/// ```
|
||||
NoConstantCondition,
|
||||
nursery
|
||||
correctness
|
||||
);
|
||||
|
||||
impl Rule for NoConstantCondition {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ declare_oxc_lint!(
|
|||
/// }
|
||||
/// ```
|
||||
NoEmpty,
|
||||
nursery,
|
||||
restriction,
|
||||
);
|
||||
|
||||
impl Rule for NoEmpty {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ declare_oxc_lint!(
|
|||
/// ```
|
||||
///
|
||||
NoEmptyPattern,
|
||||
nursery,
|
||||
suspicious,
|
||||
);
|
||||
|
||||
impl Rule for NoEmptyPattern {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ declare_oxc_lint!(
|
|||
/// eval(someString);
|
||||
/// ```
|
||||
NoEval,
|
||||
nursery
|
||||
correctness
|
||||
);
|
||||
|
||||
impl Rule for NoEval {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ declare_oxc_lint!(
|
|||
/// foo = bar;
|
||||
/// ```
|
||||
NoFunctionAssign,
|
||||
nursery
|
||||
correctness
|
||||
);
|
||||
|
||||
impl Rule for NoFunctionAssign {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ declare_oxc_lint! {
|
|||
/// var foo = a && (b || c || d); /*GOOD*/
|
||||
/// ```
|
||||
NoMixedOperators,
|
||||
nursery,
|
||||
pedantic,
|
||||
}
|
||||
|
||||
impl Rule for NoMixedOperators {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ declare_oxc_lint!(
|
|||
/// foo > NaN;
|
||||
/// ```
|
||||
UseIsnan,
|
||||
nursery,
|
||||
correctness,
|
||||
);
|
||||
|
||||
impl Rule for UseIsnan {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ declare_oxc_lint!(
|
|||
/// typeof foo === baz
|
||||
/// ```
|
||||
ValidTypeof,
|
||||
nursery,
|
||||
correctness,
|
||||
);
|
||||
|
||||
impl Rule for ValidTypeof {
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
|
|
|
|||
Loading…
Reference in a new issue