Skip to content

Commit

Permalink
fix(linter): detect vitest jest alias rules (#7567)
Browse files Browse the repository at this point in the history
closes #7240
  • Loading branch information
Sysix authored Dec 3, 2024
1 parent 33e5a49 commit 810671a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"plugins": ["jest"],
"categories": {
"correctness": "off"
},
"rules": {
"jest/no-identical-title": "error"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"plugins": ["vitest"],
"categories": {
"correctness": "off"
},
"rules": {
"vitest/no-identical-title": "error"
}
}
4 changes: 4 additions & 0 deletions apps/oxlint/fixtures/jest_and_vitest_alias_rules/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
describe("foo", () => {
it("works", () => {});
it("works", () => {});
});
23 changes: 23 additions & 0 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
9 changes: 8 additions & 1 deletion crates/oxc_linter/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down

0 comments on commit 810671a

Please sign in to comment.