-
-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathmod.rs
56 lines (51 loc) · 1.71 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
mod config;
mod express;
mod jest;
mod jsdoc;
mod nextjs;
mod promise;
mod react;
mod react_perf;
mod unicorn;
mod vitest;
use std::{io, path::Path};
pub use self::{
config::*, express::*, jest::*, jsdoc::*, nextjs::*, promise::*, react::*, react_perf::*,
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 {
VITEST_COMPATIBLE_JEST_RULES.contains(rule_name)
}
pub fn read_to_string(path: &Path) -> io::Result<String> {
// `simdutf8` is faster than `std::str::from_utf8` which `fs::read_to_string` uses internally
let bytes = std::fs::read(path)?;
if simdutf8::basic::from_utf8(&bytes).is_err() {
// Same error as `fs::read_to_string` produces (`io::Error::INVALID_UTF8`)
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"stream did not contain valid UTF-8",
));
}
// SAFETY: `simdutf8` has ensured it's a valid UTF-8 string
Ok(unsafe { String::from_utf8_unchecked(bytes) })
}