feat(linter): use only correctness rules for now

This commit is contained in:
Boshen 2023-03-11 22:36:58 +08:00
parent 4585f11da3
commit 99dbf8e946
No known key found for this signature in database
GPG key ID: 6AC90C77AAAA6ABC
3 changed files with 23 additions and 16 deletions

View file

@ -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::<Vec<_>>();
// },
// );
Self::from_rules(rules)
}
@ -109,6 +107,7 @@ impl Linter {
ctx.into_message()
}
#[allow(unused)]
fn read_rules_configuration() -> Option<serde_json::Map<String, serde_json::Value>> {
fs::read_to_string(".eslintrc.json")
.ok()

View file

@ -2,6 +2,7 @@ use std::fmt::Debug;
use crate::{context::LintContext, AstNode};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RuleCategory {
Correctness,
Nursery,

View file

@ -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<serde_json::Value>) -> Self {
match self {
#(Self::#struct_names(_) => Self::#struct_names(