Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crates/oxc_linter/src/context/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'a> ContextHost<'a> {
/// Creates a new [`LintContext`] for a specific rule.
pub fn spawn(self: Rc<Self>, rule: &RuleWithSeverity) -> LintContext<'a> {
let rule_name = rule.name();
let plugin_name = self.map_jest(rule.plugin_name(), rule_name);
let plugin_name = self.map_jest_rule_to_vitest(rule);

LintContext {
parent: self,
Expand Down Expand Up @@ -176,10 +176,11 @@ impl<'a> ContextHost<'a> {
///
/// Many Vitest rules are essentially ports of the Jest plugin rules with minor modifications.
/// For these rules, we use the corresponding jest rules with some adjustments for compatibility.
fn map_jest(&self, plugin_name: &'static str, rule_name: &str) -> &'static str {
fn map_jest_rule_to_vitest(&self, rule: &RuleWithSeverity) -> &'static str {
let plugin_name = rule.plugin_name();
if self.plugins.has_vitest()
&& plugin_name == "jest"
&& utils::is_jest_rule_adapted_to_vitest(rule_name)
&& utils::is_jest_rule_adapted_to_vitest(rule.name())
{
"vitest"
} else {
Expand Down
37 changes: 19 additions & 18 deletions crates/oxc_linter/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,29 @@ pub use self::{
tree_shaking::*, unicorn::*, vitest::*,
};

/// List of Jest rules that have Vitest equivalents.
const VITEST_COMPATIBLE_JEST_RULES: phf::Set<&'static str> = phf::phf_set! {
"consistent-test-it",
"expect-expect",
"no-alias-methods",
"no-conditional-expect",
"no-conditional-in-test",
"no-commented-out-tests",
"no-disabled-tests",
"no-focused-tests",
"no-identical-title",
"no-restricted-jest-methods",
"no-test-prefixes",
"prefer-hooks-in-order",
"valid-describe-callback",
"valid-expect",
};

/// Check if the Jest rule is adapted to Vitest.
/// Many Vitest rule are essentially ports of Jest plugin rules with minor modifications.
/// For these rules, we use the corresponding jest rules with some adjustments for compatibility.
pub fn is_jest_rule_adapted_to_vitest(rule_name: &str) -> bool {
let jest_rules: &[&str] = &[
"consistent-test-it",
"expect-expect",
"no-alias-methods",
"no-conditional-expect",
"no-conditional-in-test",
"no-commented-out-tests",
"no-disabled-tests",
"no-focused-tests",
"no-identical-title",
"no-restricted-jest-methods",
"no-test-prefixes",
"prefer-hooks-in-order",
"valid-describe-callback",
"valid-expect",
];

jest_rules.contains(&rule_name)
VITEST_COMPATIBLE_JEST_RULES.contains(rule_name)
}

pub fn read_to_string(path: &Path) -> io::Result<String> {
Expand Down