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
1 change: 1 addition & 0 deletions crates/oxc_linter/data/vitest_compatible_jest_rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"no-standalone-expect",
"no-test-prefixes",
"no-test-return-statement",
"no-unneeded-async-expect-function",
"prefer-called-with",
"prefer-comparison-matcher",
"prefer-each",
Expand Down
14 changes: 7 additions & 7 deletions crates/oxc_linter/src/generated/rule_runner_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,13 @@ impl RuleRunner for crate::rules::jest::no_test_return_statement::NoTestReturnSt
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
}

impl RuleRunner
for crate::rules::jest::no_unneeded_async_expect_function::NoUnneededAsyncExpectFunction
{
const NODE_TYPES: Option<&AstTypesBitset> = None;
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::RunOnJestNode;
}

impl RuleRunner for crate::rules::jest::no_untyped_mock_factory::NoUntypedMockFactory {
const NODE_TYPES: Option<&AstTypesBitset> = None;
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::RunOnJestNode;
Expand Down Expand Up @@ -4054,13 +4061,6 @@ impl RuleRunner for crate::rules::vitest::no_import_node_test::NoImportNodeTest
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::RunOnce;
}

impl RuleRunner
for crate::rules::vitest::no_unneeded_async_expect_function::NoUnneededAsyncExpectFunction
{
const NODE_TYPES: Option<&AstTypesBitset> = None;
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::RunOnJestNode;
}

impl RuleRunner for crate::rules::vitest::prefer_called_once::PreferCalledOnce {
const NODE_TYPES: Option<&AstTypesBitset> = None;
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::RunOnJestNode;
Expand Down
712 changes: 352 additions & 360 deletions crates/oxc_linter/src/generated/rules_enum.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ pub(crate) mod jest {
pub mod no_standalone_expect;
pub mod no_test_prefixes;
pub mod no_test_return_statement;
pub mod no_unneeded_async_expect_function;
pub mod no_untyped_mock_factory;
pub mod padding_around_test_blocks;
pub mod prefer_called_with;
Expand Down Expand Up @@ -676,7 +677,6 @@ pub(crate) mod vitest {
pub mod hoisted_apis_on_top;
pub mod no_conditional_tests;
pub mod no_import_node_test;
pub mod no_unneeded_async_expect_function;
pub mod prefer_called_once;
pub mod prefer_called_times;
pub mod prefer_describe_function_title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,19 @@ declare_oxc_lint!(
/// ```js
/// await expect(doSomethingAsync()).rejects.toThrow();
/// ```
///
/// This rule is compatible with [eslint-plugin-vitest](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-unneeded-async-expect-function.md),
/// to use it, add the following configuration to your `.oxlintrc.json`:
///
/// ```json
/// {
/// "rules": {
/// "vitest/no-unneeded-async-expect-function": "error"
/// }
/// }
/// ```
NoUnneededAsyncExpectFunction,
vitest,
jest,
style,
fix
);
Expand Down Expand Up @@ -154,7 +165,7 @@ fn get_awaited_call_span_from_block(body: &oxc_ast::ast::FunctionBody) -> Option
fn test() {
use crate::tester::Tester;

let pass = vec![
let mut pass = vec![
"expect.hasAssertions()",
"
it('pass', async () => {
Expand All @@ -179,12 +190,6 @@ fn test() {
}).rejects.toThrow();
})
",
"
import { expect as pleaseExpect } from 'vitest';
it('pass', async () => {
await pleaseExpect(doSomethingAsync()).rejects.toThrow();
})
",
"
it('pass', async () => {
await expect(async () => {
Expand Down Expand Up @@ -237,6 +242,11 @@ fn test() {
await expect(async() => [await Promise.reject(2)]).rejects.toThrow(2);
})
",
"
import { expect as pleaseExpect } from '@jest/globals';
it('pass', async () => {
await pleaseExpect(doSomethingAsync()).rejects.toThrow();
})",
];

let fail = vec![
Expand Down Expand Up @@ -369,12 +379,25 @@ fn test() {
})
", None)
];

let pass_vitest = vec![
"
import { expect as pleaseExpect } from 'vitest';
it('pass', async () => {
await pleaseExpect(doSomethingAsync()).rejects.toThrow();
})
",
];

pass.extend(pass_vitest);

Tester::new(
NoUnneededAsyncExpectFunction::NAME,
NoUnneededAsyncExpectFunction::PLUGIN,
pass,
fail,
)
.with_jest_plugin(true)
.with_vitest_plugin(true)
.expect_fix(fix)
.test_and_snapshot();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/oxc_linter/src/tester.rs
---
⚠ eslint-plugin-vitest(no-unneeded-async-expect-function): Unnecessary async function wrapper
⚠ eslint-plugin-jest(no-unneeded-async-expect-function): Unnecessary async function wrapper
╭─[no_unneeded_async_expect_function.tsx:3:25]
2 │ it('should be fixed', async () => {
3 │ ╭─▶ await expect(async () => {
Expand All @@ -11,7 +11,7 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Remove the async wrapper and pass the promise directly to expect

⚠ eslint-plugin-vitest(no-unneeded-async-expect-function): Unnecessary async function wrapper
⚠ eslint-plugin-jest(no-unneeded-async-expect-function): Unnecessary async function wrapper
╭─[no_unneeded_async_expect_function.tsx:3:25]
2 │ it('should be fixed', async () => {
3 │ await expect(async () => await doSomethingAsync()).rejects.toThrow();
Expand All @@ -20,7 +20,7 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Remove the async wrapper and pass the promise directly to expect

⚠ eslint-plugin-vitest(no-unneeded-async-expect-function): Unnecessary async function wrapper
⚠ eslint-plugin-jest(no-unneeded-async-expect-function): Unnecessary async function wrapper
╭─[no_unneeded_async_expect_function.tsx:3:25]
2 │ it('should be fixed', async () => {
3 │ ╭─▶ await expect(async function () {
Expand All @@ -30,7 +30,7 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Remove the async wrapper and pass the promise directly to expect

⚠ eslint-plugin-vitest(no-unneeded-async-expect-function): Unnecessary async function wrapper
⚠ eslint-plugin-jest(no-unneeded-async-expect-function): Unnecessary async function wrapper
╭─[no_unneeded_async_expect_function.tsx:3:27]
2 │ it('should be fixed for async arrow function', async () => {
3 │ ╭─▶ await expect(async () => {
Expand All @@ -40,7 +40,7 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Remove the async wrapper and pass the promise directly to expect

⚠ eslint-plugin-vitest(no-unneeded-async-expect-function): Unnecessary async function wrapper
⚠ eslint-plugin-jest(no-unneeded-async-expect-function): Unnecessary async function wrapper
╭─[no_unneeded_async_expect_function.tsx:3:27]
2 │ it('should be fixed for async normal function', async () => {
3 │ ╭─▶ await expect(async function () {
Expand All @@ -50,7 +50,7 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Remove the async wrapper and pass the promise directly to expect

⚠ eslint-plugin-vitest(no-unneeded-async-expect-function): Unnecessary async function wrapper
⚠ eslint-plugin-jest(no-unneeded-async-expect-function): Unnecessary async function wrapper
╭─[no_unneeded_async_expect_function.tsx:3:27]
2 │ it('should be fixed for Promise.all', async () => {
3 │ ╭─▶ await expect(async function () {
Expand All @@ -60,7 +60,7 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Remove the async wrapper and pass the promise directly to expect

⚠ eslint-plugin-vitest(no-unneeded-async-expect-function): Unnecessary async function wrapper
⚠ eslint-plugin-jest(no-unneeded-async-expect-function): Unnecessary async function wrapper
╭─[no_unneeded_async_expect_function.tsx:4:27]
3 │ const a = async () => { await doSomethingAsync() };
4 │ ╭─▶ await expect(async () => {
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub use self::{
// 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] = [
const VITEST_COMPATIBLE_JEST_RULES: [&str; 42] = [
"consistent-test-it",
"expect-expect",
"max-expects",
Expand All @@ -58,6 +58,7 @@ const VITEST_COMPATIBLE_JEST_RULES: [&str; 41] = [
"no-standalone-expect",
"no-test-prefixes",
"no-test-return-statement",
"no-unneeded-async-expect-function",
"prefer-called-with",
"prefer-comparison-matcher",
"prefer-each",
Expand Down
Loading