Skip to content

Commit 810671a

Browse files
authored
fix(linter): detect vitest jest alias rules (#7567)
closes #7240
1 parent 33e5a49 commit 810671a

5 files changed

Lines changed: 53 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"plugins": ["jest"],
3+
"categories": {
4+
"correctness": "off"
5+
},
6+
"rules": {
7+
"jest/no-identical-title": "error"
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"plugins": ["vitest"],
3+
"categories": {
4+
"correctness": "off"
5+
},
6+
"rules": {
7+
"vitest/no-identical-title": "error"
8+
}
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
describe("foo", () => {
2+
it("works", () => {});
3+
it("works", () => {});
4+
});

apps/oxlint/src/lint.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,4 +796,27 @@ mod test {
796796
assert_eq!(result.number_of_warnings, 0);
797797
assert_eq!(result.number_of_errors, 0);
798798
}
799+
800+
#[test]
801+
fn test_jest_and_vitest_alias_rules() {
802+
let args = &[
803+
"-c",
804+
"fixtures/jest_and_vitest_alias_rules/oxlint-jest.json",
805+
"fixtures/jest_and_vitest_alias_rules/test.js",
806+
];
807+
let result = test(args);
808+
assert_eq!(result.number_of_files, 1);
809+
assert_eq!(result.number_of_warnings, 0);
810+
assert_eq!(result.number_of_errors, 1);
811+
812+
let args = &[
813+
"-c",
814+
"fixtures/jest_and_vitest_alias_rules/oxlint-vitest.json",
815+
"fixtures/jest_and_vitest_alias_rules/test.js",
816+
];
817+
let result = test(args);
818+
assert_eq!(result.number_of_files, 1);
819+
assert_eq!(result.number_of_warnings, 0);
820+
assert_eq!(result.number_of_errors, 1);
821+
}
799822
}

crates/oxc_linter/src/builder.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,16 @@ impl RulesCache {
421421
let mut all_rules: Vec<_> = if self.plugins.is_all() {
422422
RULES.clone()
423423
} else {
424+
let mut plugins = self.plugins;
425+
426+
// we need to include some jest rules when vitest is enabled, see [`VITEST_COMPATIBLE_JEST_RULES`]
427+
if plugins.contains(LintPlugins::VITEST) {
428+
plugins = plugins.union(LintPlugins::JEST);
429+
}
430+
424431
RULES
425432
.iter()
426-
.filter(|rule| self.plugins.contains(LintPlugins::from(rule.plugin_name())))
433+
.filter(|rule| plugins.contains(LintPlugins::from(rule.plugin_name())))
427434
.cloned()
428435
.collect()
429436
};

0 commit comments

Comments
 (0)