Skip to content

Commit

Permalink
remove vitest util, update var name to possible_jest_node
Browse files Browse the repository at this point in the history
  • Loading branch information
taearls committed Dec 28, 2024
1 parent 146d6fb commit 6fb1084
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
15 changes: 8 additions & 7 deletions crates/oxc_linter/src/rules/jest/prefer_lowercase_title/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod tests;
use crate::{
context::LintContext,
rule::Rule,
utils::{parse_vitest_fn_call, JestFnKind, JestGeneralFnKind, PossibleJestNode},
utils::{parse_jest_fn_call, JestFnKind, JestGeneralFnKind, ParsedJestFnCallNew, PossibleJestNode},
};

fn prefer_lowercase_title_diagnostic(title: &str, span: Span) -> OxcDiagnostic {
Expand Down Expand Up @@ -194,14 +194,15 @@ impl Rule for PreferLowercaseTitle {

fn run_on_jest_node<'a, 'c>(
&self,
possible_vitest_node: &PossibleJestNode<'a, 'c>,
possible_jest_node: &PossibleJestNode<'a, 'c>,
ctx: &'c LintContext<'a>,
) {
let node = possible_vitest_node.node;
let node = possible_jest_node.node;
let AstKind::CallExpression(call_expr) = node.kind() else {
return;
};
let Some(vitest_fn_call) = parse_vitest_fn_call(call_expr, possible_vitest_node, ctx)
let Some(ParsedJestFnCallNew::GeneralJest(jest_fn_call)) =
parse_jest_fn_call(call_expr, possible_jest_node, ctx)
else {
return;
};
Expand All @@ -210,16 +211,16 @@ impl Rule for PreferLowercaseTitle {

let ignores = Self::populate_ignores(&self.ignore);

if ignores.contains(&vitest_fn_call.name.as_ref()) {
if ignores.contains(&jest_fn_call.name.as_ref()) {
return;
}

if matches!(vitest_fn_call.kind, JestFnKind::General(JestGeneralFnKind::Describe)) {
if matches!(jest_fn_call.kind, JestFnKind::General(JestGeneralFnKind::Describe)) {
if self.ignore_top_level_describe && scopes.get_flags(node.scope_id()).is_top() {
return;
}
} else if !matches!(
vitest_fn_call.kind,
jest_fn_call.kind,
JestFnKind::General(JestGeneralFnKind::Test | JestGeneralFnKind::Bench)
) {
return;
Expand Down
20 changes: 2 additions & 18 deletions crates/oxc_linter/src/utils/vitest.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use oxc_ast::ast::CallExpression;

use super::{
parse_jest_fn_call, ParsedExpectFnCall, ParsedGeneralJestFnCall, ParsedJestFnCallNew,
parse_jest_fn_call, ParsedExpectFnCall, ParsedJestFnCallNew,
PossibleJestNode,
};
use crate::{utils::JestFnKind, LintContext};
use crate::LintContext;

mod valid_vitest_fn;
pub use crate::utils::vitest::valid_vitest_fn::VALID_VITEST_FN_CALL_CHAINS;
Expand All @@ -22,19 +22,3 @@ pub fn parse_expect_and_typeof_vitest_fn_call<'a>(
ParsedJestFnCallNew::GeneralJest(_) => None,
}
}

pub fn parse_vitest_fn_call<'a>(
call_expr: &'a CallExpression<'a>,
possible_jest_node: &PossibleJestNode<'a, '_>,
ctx: &LintContext<'a>,
) -> Option<ParsedGeneralJestFnCall<'a>> {
let jest_fn_call = parse_jest_fn_call(call_expr, possible_jest_node, ctx)?;

match jest_fn_call {
ParsedJestFnCallNew::GeneralJest(jest_fn_call) => match jest_fn_call.kind {
JestFnKind::General(_) => Some(jest_fn_call),
_ => None,
},
_ => None,
}
}

0 comments on commit 6fb1084

Please sign in to comment.