Skip to content

Commit c69201c

Browse files
authored
fix(linter): copy over js plugins when applying overrides (#14542)
- quick fix. closes #14504 - added repro as test - [x] fails without the fix - [x] passes with it - Direct edits from maintainers welcome. --------- Signed-off-by: Arsh <emmagoldmanvevo+github@pm.me>
1 parent 26c5f5a commit c69201c

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

crates/oxc_linter/src/config/config_store.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ impl Config {
183183
.cloned()
184184
.collect::<Vec<_>>();
185185

186-
let mut external_rules = FxHashMap::default();
186+
let mut external_rules =
187+
self.base.external_rules.iter().copied().collect::<FxHashMap<_, _>>();
187188

188189
// Track which plugins have already had their category rules applied.
189190
// Start with the root plugins since they already have categories applied in base_rules.
@@ -685,6 +686,49 @@ mod test {
685686
assert!(app.globals.is_enabled("Secret"));
686687
}
687688

689+
#[test]
690+
fn test_external_rules_preserved_with_overrides() {
691+
// reproduction for https://github.com/oxc-project/oxc/issues/14504
692+
// the bug occurred due to a simple omission and the fix was simple.
693+
// this test is just to communicate what was going wrong and to avoid a regression.
694+
// i noticed js plugins aren't considered stable yet, so feel free to edit or remove this test
695+
696+
let mut external_plugin_store = ExternalPluginStore::default();
697+
external_plugin_store.register_plugin(
698+
"./plugin.js".into(),
699+
"custom".into(),
700+
0,
701+
vec!["no-debugger".into()],
702+
);
703+
704+
let rule_id = external_plugin_store.lookup_rule_id("custom", "no-debugger").unwrap();
705+
706+
let overrides = ResolvedOxlintOverrides::new(vec![ResolvedOxlintOverride {
707+
files: GlobSet::new(vec!["*.ts"]),
708+
env: None,
709+
plugins: None,
710+
globals: None,
711+
rules: ResolvedOxlintOverrideRules { builtin_rules: vec![], external_rules: vec![] },
712+
}]);
713+
714+
let store = ConfigStore::new(
715+
Config::new(
716+
vec![],
717+
vec![(rule_id, AllowWarnDeny::Deny)],
718+
OxlintCategories::default(),
719+
LintConfig::default(),
720+
overrides,
721+
),
722+
FxHashMap::default(),
723+
external_plugin_store,
724+
);
725+
726+
// Bug: external rules were lost when overrides matched
727+
let resolved = store.resolve("foo.ts".as_ref());
728+
assert_eq!(resolved.external_rules.len(), 1);
729+
assert_eq!(resolved.external_rules[0].0, rule_id);
730+
}
731+
688732
#[test]
689733
fn test_replace_globals() {
690734
let base_config = LintConfig {

0 commit comments

Comments
 (0)