diff --git a/apps/oxlint/fixtures/jest_and_vitest_alias_rules/oxlint-jest.json b/apps/oxlint/fixtures/jest_and_vitest_alias_rules/oxlint-jest.json new file mode 100644 index 0000000000000..6dff5e39f22ce --- /dev/null +++ b/apps/oxlint/fixtures/jest_and_vitest_alias_rules/oxlint-jest.json @@ -0,0 +1,9 @@ +{ + "plugins": ["jest"], + "categories": { + "correctness": "off" + }, + "rules": { + "jest/no-identical-title": "error" + } +} \ No newline at end of file diff --git a/apps/oxlint/fixtures/jest_and_vitest_alias_rules/oxlint-vitest.json b/apps/oxlint/fixtures/jest_and_vitest_alias_rules/oxlint-vitest.json new file mode 100644 index 0000000000000..92931d01fd36e --- /dev/null +++ b/apps/oxlint/fixtures/jest_and_vitest_alias_rules/oxlint-vitest.json @@ -0,0 +1,9 @@ +{ + "plugins": ["vitest"], + "categories": { + "correctness": "off" + }, + "rules": { + "vitest/no-identical-title": "error" + } +} \ No newline at end of file diff --git a/apps/oxlint/fixtures/jest_and_vitest_alias_rules/test.js b/apps/oxlint/fixtures/jest_and_vitest_alias_rules/test.js new file mode 100644 index 0000000000000..082fddde68dc3 --- /dev/null +++ b/apps/oxlint/fixtures/jest_and_vitest_alias_rules/test.js @@ -0,0 +1,4 @@ +describe("foo", () => { + it("works", () => {}); + it("works", () => {}); +}); diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index 70d3f70b41779..b81846ff7fa3e 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -796,4 +796,27 @@ mod test { assert_eq!(result.number_of_warnings, 0); assert_eq!(result.number_of_errors, 0); } + + #[test] + fn test_jest_and_vitest_alias_rules() { + let args = &[ + "-c", + "fixtures/jest_and_vitest_alias_rules/oxlint-jest.json", + "fixtures/jest_and_vitest_alias_rules/test.js", + ]; + let result = test(args); + assert_eq!(result.number_of_files, 1); + assert_eq!(result.number_of_warnings, 0); + assert_eq!(result.number_of_errors, 1); + + let args = &[ + "-c", + "fixtures/jest_and_vitest_alias_rules/oxlint-vitest.json", + "fixtures/jest_and_vitest_alias_rules/test.js", + ]; + let result = test(args); + assert_eq!(result.number_of_files, 1); + assert_eq!(result.number_of_warnings, 0); + assert_eq!(result.number_of_errors, 1); + } } diff --git a/crates/oxc_linter/src/builder.rs b/crates/oxc_linter/src/builder.rs index 4586034d87b60..92ca3410e459c 100644 --- a/crates/oxc_linter/src/builder.rs +++ b/crates/oxc_linter/src/builder.rs @@ -421,9 +421,16 @@ impl RulesCache { let mut all_rules: Vec<_> = if self.plugins.is_all() { RULES.clone() } else { + let mut plugins = self.plugins; + + // we need to include some jest rules when vitest is enabled, see [`VITEST_COMPATIBLE_JEST_RULES`] + if plugins.contains(LintPlugins::VITEST) { + plugins = plugins.union(LintPlugins::JEST); + } + RULES .iter() - .filter(|rule| self.plugins.contains(LintPlugins::from(rule.plugin_name()))) + .filter(|rule| plugins.contains(LintPlugins::from(rule.plugin_name()))) .cloned() .collect() };