Skip to content

Commit

Permalink
fix(oxlint): rules in the configuration file are not being correctly … (
Browse files Browse the repository at this point in the history
#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?
  • Loading branch information
shulaoda committed Aug 18, 2024
1 parent 5d0fb97 commit 5f8a7c2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions crates/oxc_linter/src/config/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"])));

Expand Down

0 comments on commit 5f8a7c2

Please sign in to comment.