Skip to content

Commit 11a4e67

Browse files
authored
fix(linter): Comptibles rules need to be disabled in jest and vitest at same time (#21982)
Fix #21853
1 parent 9593ec8 commit 11a4e67

4 files changed

Lines changed: 6 additions & 65 deletions

File tree

crates/oxc_linter/src/config/config_builder.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ impl ConfigStoreBuilder {
418418
}
419419

420420
fn get_all_rules_for_plugins(&self, override_plugins: Option<LintPlugins>) -> Vec<RuleEnum> {
421-
let mut builtin_plugins = if let Some(override_plugins) = override_plugins {
421+
let builtin_plugins = if let Some(override_plugins) = override_plugins {
422422
self.config.plugins | override_plugins
423423
} else {
424424
self.config.plugins
@@ -427,11 +427,6 @@ impl ConfigStoreBuilder {
427427
if builtin_plugins.is_all() {
428428
RULES.clone()
429429
} else {
430-
// we need to include some jest rules when vitest is enabled, see [`VITEST_COMPATIBLE_JEST_RULES`]
431-
if builtin_plugins.contains(LintPlugins::VITEST) {
432-
builtin_plugins |= LintPlugins::JEST;
433-
}
434-
435430
RULES
436431
.iter()
437432
.filter(|rule| {
@@ -475,12 +470,7 @@ impl ConfigStoreBuilder {
475470
// When a plugin gets disabled before build(), rules for that plugin aren't removed until
476471
// with_filters() gets called. If the user never calls it, those now-undesired rules need
477472
// to be taken out.
478-
let mut plugins = self.plugins();
479-
480-
// Apply the same Vitest->Jest logic as in get_all_rules()
481-
if plugins.contains(LintPlugins::VITEST) {
482-
plugins |= LintPlugins::JEST;
483-
}
473+
let plugins = self.plugins();
484474

485475
let overrides = std::mem::take(&mut self.overrides);
486476
let resolved_overrides = self.resolve_overrides(overrides, external_plugin_store)?;
@@ -552,10 +542,7 @@ impl ConfigStoreBuilder {
552542
}
553543

554544
/// Warn for all correctness rules in the given set of plugins.
555-
fn warn_correctness(mut plugins: LintPlugins) -> FxHashMap<RuleEnum, AllowWarnDeny> {
556-
if plugins.contains(LintPlugins::VITEST) {
557-
plugins |= LintPlugins::JEST;
558-
}
545+
fn warn_correctness(plugins: LintPlugins) -> FxHashMap<RuleEnum, AllowWarnDeny> {
559546
RULES
560547
.iter()
561548
.filter(|rule| {

crates/oxc_linter/src/config/config_store.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ pub struct Config {
7878
}
7979

8080
impl Config {
81-
fn builtin_rule_plugins(mut plugins: LintPlugins) -> LintPlugins {
82-
if plugins.contains(LintPlugins::VITEST) {
83-
plugins |= LintPlugins::JEST;
84-
}
81+
fn builtin_rule_plugins(plugins: LintPlugins) -> LintPlugins {
8582
plugins
8683
}
8784

crates/oxc_linter/src/config/rules.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::{
2020
AllowWarnDeny, ExternalPluginStore, LintPlugins,
2121
external_plugin_store::{ExternalOptionsId, ExternalRuleId, ExternalRuleLookupError},
2222
rules::{RULES, RuleEnum},
23-
utils::{is_eslint_rule_adapted_to_typescript, is_jest_rule_adapted_to_vitest},
23+
utils::is_eslint_rule_adapted_to_typescript,
2424
};
2525

2626
/// Errors that can occur when overriding rules
@@ -235,7 +235,6 @@ fn transform_rule_and_plugin_name<'a>(
235235
plugin_name: &'a str,
236236
) -> (&'a str, &'a str) {
237237
let plugin_name = match plugin_name {
238-
"vitest" if is_jest_rule_adapted_to_vitest(rule_name) => "jest",
239238
"unicorn" if rule_name == "no-negated-condition" => "eslint",
240239
"typescript" if is_eslint_rule_adapted_to_typescript(rule_name) => "eslint",
241240
_ => plugin_name,

crates/oxc_linter/src/utils/mod.rs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ pub use self::{
3232
react_perf::*, regex::*, typescript::*, unicorn::*, url::*, vitest::*, vue::*,
3333
};
3434

35-
/// List of Jest rules that have Vitest equivalents.
36-
// When adding a new rule to this list, please ensure that
37-
// the crates/oxc_linter/data/vitest_compatible_jest_rules.json
38-
// file is also updated. The JSON file is used by the oxlint-migrate
39-
// and eslint-plugin-oxlint repos to keep everything synced.
40-
const VITEST_COMPATIBLE_JEST_RULES: [&str; 0] = [];
41-
4235
/// List of Eslint rules that have TypeScript equivalents.
4336
// When adding a new rule to this list, please ensure oxlint-migrate is also updated.
4437
// See https://github.com/oxc-project/oxlint-migrate/blob/659b461eaf5b2f8a7283822ae84a5e619c86fca3/src/constants.ts#L24
@@ -84,13 +77,6 @@ const TYPESCRIPT_COMPATIBLE_ESLINT_RULES: [&str; 18] = [
8477
// "space-infix-ops"
8578
];
8679

87-
/// Check if the Jest rule is adapted to Vitest.
88-
/// Many Vitest rule are essentially ports of Jest plugin rules with minor modifications.
89-
/// For these rules, we use the corresponding jest rules with some adjustments for compatibility.
90-
pub fn is_jest_rule_adapted_to_vitest(rule_name: &str) -> bool {
91-
VITEST_COMPATIBLE_JEST_RULES.binary_search(&rule_name).is_ok()
92-
}
93-
9480
/// Check if the Eslint rule is adapted to Typescript.
9581
/// Many Typescript rule are essentially ports of Eslint plugin rules with minor modifications.
9682
/// For these rules, we use the corresponding eslint rules with some adjustments for compatibility.
@@ -259,38 +245,10 @@ fn read_to_arena_bytes_unknown_size(mut file: File, allocator: &Allocator) -> io
259245

260246
#[cfg(test)]
261247
mod test {
262-
use crate::utils::{
263-
TYPESCRIPT_COMPATIBLE_ESLINT_RULES, VITEST_COMPATIBLE_JEST_RULES, read_to_string,
264-
};
265-
use serde_json::from_str;
266-
use std::path::Path;
248+
use crate::utils::TYPESCRIPT_COMPATIBLE_ESLINT_RULES;
267249

268250
#[test]
269251
fn test_typescript_rules_list_is_alphabetized() {
270252
assert!(TYPESCRIPT_COMPATIBLE_ESLINT_RULES.is_sorted());
271253
}
272-
273-
#[test]
274-
fn test_vitest_rules_list_is_alphabetized() {
275-
assert!(VITEST_COMPATIBLE_JEST_RULES.is_sorted());
276-
}
277-
278-
#[test]
279-
fn test_vitest_rules_list_matches_json() {
280-
let json_path =
281-
Path::new(env!("CARGO_MANIFEST_DIR")).join("data/vitest_compatible_jest_rules.json");
282-
let json = read_to_string(&json_path).expect("Failed to read vitest rules JSON file");
283-
let json_rules: Vec<String> =
284-
from_str(&json).expect("Failed to parse vitest rules JSON file");
285-
assert!(json_rules.is_sorted(), "vitest JSON list must be alphabetized");
286-
let rust_rules: Vec<&str> = VITEST_COMPATIBLE_JEST_RULES.to_vec();
287-
assert_eq!(
288-
json_rules.len(),
289-
rust_rules.len(),
290-
"Rule counts differ between Rust constant and JSON, please ensure both are updated"
291-
);
292-
for (json_rule, rust_rule) in json_rules.iter().zip(rust_rules.iter()) {
293-
assert_eq!(json_rule, rust_rule, "Mismatch for rule: {json_rule}");
294-
}
295-
}
296254
}

0 commit comments

Comments
 (0)