Skip to content

Commit 5f8a7c2

Browse files
authored
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?
1 parent 5d0fb97 commit 5f8a7c2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

crates/oxc_linter/src/config/rules.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use serde::{
88
Deserialize,
99
};
1010

11-
use crate::AllowWarnDeny;
11+
use crate::{
12+
rules::{RuleEnum, RULES},
13+
AllowWarnDeny,
14+
};
1215

1316
// TS type is `Record<string, RuleConf>`
1417
// - type SeverityConf = 0 | 1 | 2 | "off" | "warn" | "error";
@@ -92,7 +95,14 @@ impl<'de> Deserialize<'de> for OxlintRules {
9295

9396
fn parse_rule_key(name: &str) -> (String, String) {
9497
let Some((plugin_name, rule_name)) = name.split_once('/') else {
95-
return ("eslint".to_string(), name.to_string());
98+
return (
99+
RULES
100+
.iter()
101+
.find(|r| r.name() == name)
102+
.map_or("unknown_plugin", RuleEnum::plugin_name)
103+
.to_string(),
104+
name.to_string(),
105+
);
96106
};
97107

98108
let (oxlint_plugin_name, rule_name) = match plugin_name {
@@ -193,7 +203,7 @@ mod test {
193203

194204
let r3 = rules.next().unwrap();
195205
assert_eq!(r3.rule_name, "dummy");
196-
assert_eq!(r3.plugin_name, "eslint");
206+
assert_eq!(r3.plugin_name, "unknown_plugin");
197207
assert!(r3.severity.is_warn_deny());
198208
assert_eq!(r3.config, Some(serde_json::json!(["arg1", "args2"])));
199209

0 commit comments

Comments
 (0)