mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(linter): use only correctness rules for now
This commit is contained in:
parent
4585f11da3
commit
99dbf8e946
3 changed files with 23 additions and 16 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use std::fmt::Debug;
|
|||
|
||||
use crate::{context::LintContext, AstNode};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum RuleCategory {
|
||||
Correctness,
|
||||
Nursery,
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue