fix(oxlint): rules in the configuration file are not being correctly … (#4949)

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?
This commit is contained in:
dalaoshu 2024-08-18 14:16:43 +08:00 committed by GitHub
parent 5d0fb979cb
commit 5f8a7c22e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,7 +8,10 @@ use serde::{
Deserialize,
};
use crate::AllowWarnDeny;
use crate::{
rules::{RuleEnum, RULES},
AllowWarnDeny,
};
// TS type is `Record<string, RuleConf>`
// - 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"])));