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
43 changes: 43 additions & 0 deletions crates/oxc_linter/data/vitest_compatible_jest_rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[
"consistent-test-it",
"expect-expect",
"max-expects",
"max-nested-describe",
"no-alias-methods",
"no-commented-out-tests",
"no-conditional-expect",
"no-conditional-in-test",
"no-disabled-tests",
"no-duplicate-hooks",
"no-focused-tests",
"no-hooks",
"no-identical-title",
"no-interpolation-in-snapshots",
"no-large-snapshots",
"no-mocks-import",
"no-restricted-jest-methods",
"no-restricted-matchers",
"no-standalone-expect",
"no-test-prefixes",
"no-test-return-statement",
"prefer-called-with",
"prefer-comparison-matcher",
"prefer-each",
"prefer-equality-matcher",
"prefer-expect-resolves",
"prefer-hooks-in-order",
"prefer-hooks-on-top",
"prefer-lowercase-title",
"prefer-mock-promise-shorthand",
"prefer-spy-on",
"prefer-strict-equal",
"prefer-to-be",
"prefer-to-contain",
"prefer-to-have-length",
"prefer-todo",
"require-hook",
"require-to-throw-message",
"require-top-level-describe",
"valid-describe-callback",
"valid-expect"
]
31 changes: 28 additions & 3 deletions crates/oxc_linter/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ pub use self::{
};

/// List of Jest rules that have Vitest equivalents.
// When adding a new rule to this list, please ensure oxlint-migrate is also updated.
// See https://github.com/oxc-project/oxlint-migrate/blob/2c336c67d75adb09a402ae66fb3099f1dedbe516/scripts/constants.ts
// When adding a new rule to this list, please ensure that
// the crates/oxc_linter/data/vitest_compatible_jest_rules.json
// file is also updated. The JSON file is used by the oxlint-migrate
// and eslint-plugin-oxlint repos to keep everything synced.
const VITEST_COMPATIBLE_JEST_RULES: [&str; 41] = [
"consistent-test-it",
"expect-expect",
Expand Down Expand Up @@ -273,7 +275,11 @@ fn read_to_arena_bytes_unknown_size(mut file: File, allocator: &Allocator) -> io

#[cfg(test)]
mod test {
use crate::utils::{TYPESCRIPT_COMPATIBLE_ESLINT_RULES, VITEST_COMPATIBLE_JEST_RULES};
use crate::utils::{
TYPESCRIPT_COMPATIBLE_ESLINT_RULES, VITEST_COMPATIBLE_JEST_RULES, read_to_string,
};
use serde_json::from_str;
use std::path::Path;

#[test]
fn test_typescript_rules_list_is_alphabetized() {
Expand All @@ -284,4 +290,23 @@ mod test {
fn test_vitest_rules_list_is_alphabetized() {
assert!(VITEST_COMPATIBLE_JEST_RULES.is_sorted());
}

#[test]
fn test_vitest_rules_list_matches_json() {
let json_path =
Path::new(env!("CARGO_MANIFEST_DIR")).join("data/vitest_compatible_jest_rules.json");
let json = read_to_string(&json_path).expect("Failed to read vitest rules JSON file");
let json_rules: Vec<String> =
from_str(&json).expect("Failed to parse vitest rules JSON file");
assert!(json_rules.is_sorted(), "vitest JSON list must be alphabetized");
let rust_rules: Vec<&str> = VITEST_COMPATIBLE_JEST_RULES.to_vec();
assert_eq!(
json_rules.len(),
rust_rules.len(),
"Rule counts differ between Rust constant and JSON, please ensure both are updated"
);
for (json_rule, rust_rule) in json_rules.iter().zip(rust_rules.iter()) {
assert_eq!(json_rule, rust_rule, "Mismatch for rule: {json_rule}");
}
}
}
Loading