Skip to content

Commit 8c98e69

Browse files
JoviDeCroockSysix
andauthored
fix(linter): vitest/prefer-describe-function-title: Check earlier to avoid false positive (#18177)
This moves the check up to avoid the issue reported in #18039 Fixes #18039 Co-authored-by: Alexander S. <sysix@sysix-coding.de>
1 parent 9b3780e commit 8c98e69

1 file changed

Lines changed: 35 additions & 10 deletions

File tree

crates/oxc_linter/src/rules/vitest/prefer_describe_function_title.rs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ impl PreferDescribeFunctionTitle {
8484
return;
8585
}
8686

87+
let Some(test_vitest_fn) = parse_general_jest_fn_call(call_expr, possible_jest_node, ctx)
88+
else {
89+
return;
90+
};
91+
92+
if test_vitest_fn.kind != JestFnKind::General(JestGeneralFnKind::Describe) {
93+
return;
94+
}
95+
8796
let mut imported_entries =
8897
ctx.module_record().import_entries.iter().map(|entry| entry.local_name.name.as_ref());
8998

@@ -113,16 +122,6 @@ impl PreferDescribeFunctionTitle {
113122
);
114123
}
115124
Argument::StringLiteral(string_title) => {
116-
let Some(test_vitest_fn) =
117-
parse_general_jest_fn_call(call_expr, possible_jest_node, ctx)
118-
else {
119-
return;
120-
};
121-
122-
if test_vitest_fn.kind != JestFnKind::General(JestGeneralFnKind::Describe) {
123-
return;
124-
}
125-
126125
if !imported_entries.contains(string_title.value.as_ref()) {
127126
return;
128127
}
@@ -263,6 +262,32 @@ fn test() {
263262
Some(serde_json::json!({ "settings": { "vitest": { "typecheck": true, }, } })),
264263
Some(PathBuf::from("myFunction.test.ts")),
265264
),
265+
(
266+
r#"
267+
import { DocumentBuilder } from "./DocumentBuilder"
268+
describe("Swagger Helper", () => {
269+
beforeEach(() => {
270+
vi.spyOn(DocumentBuilder.prototype, "setTitle")
271+
})
272+
})
273+
"#,
274+
None,
275+
None,
276+
Some(PathBuf::from("swagger.helpers.spec.ts")),
277+
),
278+
(
279+
r#"
280+
import { myFunction } from "./myFunction"
281+
describe("Test Suite", () => {
282+
beforeEach(() => {
283+
vi.spyOn(myFunction, "name")
284+
})
285+
})
286+
"#,
287+
None,
288+
None,
289+
Some(PathBuf::from("myFunction.test.ts")),
290+
),
266291
];
267292

268293
let fail = vec![

0 commit comments

Comments
 (0)