Skip to content

Commit c52a9ba

Browse files
committed
fix(linter): fix plugins inside overrides not being applied (#11057)
fixes #10394
1 parent d1b0c83 commit c52a9ba

File tree

6 files changed

+72
-4
lines changed

6 files changed

+72
-4
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"overrides": [
3+
{
4+
"files": ["*.test.ts"],
5+
"plugins": ["jest", "vitest"],
6+
"rules": {
7+
"jest/valid-title": "deny",
8+
"no-unused-vars": "off"
9+
}
10+
}
11+
]
12+
}
13+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
describe("", () => {
2+
//
3+
4+
it("", () => {});
5+
});
6+
7+
const foo = 123;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const foo = 123;

apps/oxlint/src/lint.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,4 +1165,10 @@ mod test {
11651165
let args = &["-c", ".oxlintrc.json"];
11661166
Tester::new().with_cwd("fixtures/issue_11054".into()).test_and_snapshot(args);
11671167
}
1168+
1169+
#[test]
1170+
fn test_plugins_in_overrides_enabled_correctly() {
1171+
let args = &["-c", ".oxlintrc.json"];
1172+
Tester::new().with_cwd("fixtures/overrides_with_plugin".into()).test_and_snapshot(args);
1173+
}
11681174
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: -c .oxlintrc.json
6+
working directory: fixtures/overrides_with_plugin
7+
----------
8+
9+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/jest/valid-title.html\eslint-plugin-jest(valid-title)]8;;\: "Should not have an empty title"
10+
,-[index.test.ts:1:10]
11+
1 | describe("", () => {
12+
: ^^
13+
2 | //
14+
`----
15+
help: "Write a meaningful title for your test"
16+
17+
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-vars.html\eslint(no-unused-vars)]8;;\: Variable 'foo' is declared but never used. Unused variables should start with a '_'.
18+
,-[index.ts:1:7]
19+
1 | const foo = 123;
20+
: ^|^
21+
: `-- 'foo' is declared here
22+
`----
23+
help: Consider removing this declaration.
24+
25+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/jest/valid-title.html\eslint-plugin-jest(valid-title)]8;;\: "Should not have an empty title"
26+
,-[index.test.ts:4:6]
27+
3 |
28+
4 | it("", () => {});
29+
: ^^
30+
5 | });
31+
`----
32+
help: "Write a meaningful title for your test"
33+
34+
Found 1 warning and 2 errors.
35+
Finished in <variable>ms on 2 files with 101 rules using 1 threads.
36+
----------
37+
CLI result: LintFoundErrors
38+
----------

crates/oxc_linter/src/config/config_store.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ impl Config {
8888
let mut env = self.base.config.env.clone();
8989
let mut globals = self.base.config.globals.clone();
9090
let mut plugins = self.base.config.plugins;
91+
92+
for override_config in overrides_to_apply.clone() {
93+
if let Some(override_plugins) = override_config.plugins {
94+
plugins |= override_plugins;
95+
}
96+
}
97+
9198
let mut rules = self
9299
.base
93100
.rules
@@ -107,10 +114,6 @@ impl Config {
107114
override_config.rules.override_rules(&mut rules, &all_rules);
108115
}
109116

110-
if let Some(override_plugins) = override_config.plugins {
111-
plugins |= override_plugins;
112-
}
113-
114117
if let Some(override_env) = &override_config.env {
115118
override_env.override_envs(&mut env);
116119
}

0 commit comments

Comments
 (0)