From b5f4f1eb68ec9d740fa818335827944e8bf674d7 Mon Sep 17 00:00:00 2001 From: Hao Cheng Date: Wed, 10 Jan 2024 04:46:56 +0100 Subject: [PATCH] fix(linter): fix plugin name parsing when reading config file (#1972) This PR fixes the plugin parsing logic when reading a config file. Specifically, the plugin names defined in `RuleEnum`s use snake-case ("jsx_a11y") while in the config file they are written as "jsx-a11y". This inconsistency causes some rules to be filtered out. I tested the change with the config json file provided in #1969. - Before the change: `Finished in 21ms on 1 file with 157 rules using 8 threads.` - After the change: `Finished in 23ms on 1 file with 178 rules using 8 threads.` Related issue: #1969 --- crates/oxc_linter/fixtures/eslint_config.json | 4 +++- crates/oxc_linter/src/config/mod.rs | 4 +++- .../oxc_linter__config__test__parse_rules.snap | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/oxc_linter/fixtures/eslint_config.json b/crates/oxc_linter/fixtures/eslint_config.json index b82b77dfeabba..d0a50c01018f4 100644 --- a/crates/oxc_linter/fixtures/eslint_config.json +++ b/crates/oxc_linter/fixtures/eslint_config.json @@ -15,6 +15,8 @@ { "null": "ignore" } - ] + ], + "@typescript-eslint/ban-types": "error", + "jsx-a11y/alt-text": "warn" } } diff --git a/crates/oxc_linter/src/config/mod.rs b/crates/oxc_linter/src/config/mod.rs index acbc7e498f52b..9b6053502a483 100644 --- a/crates/oxc_linter/src/config/mod.rs +++ b/crates/oxc_linter/src/config/mod.rs @@ -211,9 +211,11 @@ fn parse_rule_name(name: &str) -> (&str, &str) { if let Some((category, name)) = name.split_once('/') { let category = category.trim_start_matches('@'); - // if it matches typescript-eslint, map it to typescript let category = match category { + // if it matches typescript-eslint, map it to typescript "typescript-eslint" => "typescript", + // plugin name in RuleEnum is in snake_case + "jsx-a11y" => "jsx_a11y", _ => category, }; diff --git a/crates/oxc_linter/src/config/snapshots/oxc_linter__config__test__parse_rules.snap b/crates/oxc_linter/src/config/snapshots/oxc_linter__config__test__parse_rules.snap index e9e088e190e1a..83f244a81ef6f 100644 --- a/crates/oxc_linter/src/config/snapshots/oxc_linter__config__test__parse_rules.snap +++ b/crates/oxc_linter/src/config/snapshots/oxc_linter__config__test__parse_rules.snap @@ -36,4 +36,16 @@ expression: rules ], ), ), + ( + "typescript", + "ban-types", + Deny, + None, + ), + ( + "jsx_a11y", + "alt-text", + Warn, + None, + ), ]