From 5f8a7c22e4027f63b2c1474870b2eeccb9d190c0 Mon Sep 17 00:00:00 2001 From: dalaoshu Date: Sun, 18 Aug 2024 14:16:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(oxlint):=20rules=20in=20the=20configuration?= =?UTF-8?q?=20file=20are=20not=20being=20correctly=20=E2=80=A6=20(#4949)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #4701 BTW, which one should have higher priority between the rules in the command line and those in the configuration file? Is the current design reasonable? --- crates/oxc_linter/src/config/rules.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/oxc_linter/src/config/rules.rs b/crates/oxc_linter/src/config/rules.rs index 67570f3c1d99b..0e78d9a5a1702 100644 --- a/crates/oxc_linter/src/config/rules.rs +++ b/crates/oxc_linter/src/config/rules.rs @@ -8,7 +8,10 @@ use serde::{ Deserialize, }; -use crate::AllowWarnDeny; +use crate::{ + rules::{RuleEnum, RULES}, + AllowWarnDeny, +}; // TS type is `Record` // - type SeverityConf = 0 | 1 | 2 | "off" | "warn" | "error"; @@ -92,7 +95,14 @@ impl<'de> Deserialize<'de> for OxlintRules { fn parse_rule_key(name: &str) -> (String, String) { let Some((plugin_name, rule_name)) = name.split_once('/') else { - return ("eslint".to_string(), name.to_string()); + return ( + RULES + .iter() + .find(|r| r.name() == name) + .map_or("unknown_plugin", RuleEnum::plugin_name) + .to_string(), + name.to_string(), + ); }; let (oxlint_plugin_name, rule_name) = match plugin_name { @@ -193,7 +203,7 @@ mod test { let r3 = rules.next().unwrap(); assert_eq!(r3.rule_name, "dummy"); - assert_eq!(r3.plugin_name, "eslint"); + assert_eq!(r3.plugin_name, "unknown_plugin"); assert!(r3.severity.is_warn_deny()); assert_eq!(r3.config, Some(serde_json::json!(["arg1", "args2"])));