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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use crate::{
};

fn no_conditional_in_test(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Avoid having conditionals in tests.").with_label(span)
OxcDiagnostic::warn("Avoid having conditionals in tests.")
.with_help("Replace conditionals with separate test cases for each branch to keep tests deterministic and easy to understand.")
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/rules/jest/no_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use crate::{
};

fn unexpected_hook_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Do not use setup or teardown hooks.").with_label(span)
OxcDiagnostic::warn("Do not use setup or teardown hooks.")
.with_help("Inline the setup or teardown logic directly in each test for better readability and isolation.")
.with_label(span)
}

#[derive(Debug, Default, Clone, Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use crate::{
};

fn no_test_return_statement_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Jest tests should not return a value").with_label(span)
OxcDiagnostic::warn("Jest tests should not return a value")
.with_help("Use `await` for async assertions or remove the return statement.")
.with_note("Jest ignores returned values from tests.")
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down
6 changes: 5 additions & 1 deletion crates/oxc_linter/src/rules/promise/avoid_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ use oxc_span::Span;
use crate::{AstNode, context::LintContext, rule::Rule};

fn avoid_new_promise_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Avoid creating new promises").with_label(span)
OxcDiagnostic::warn("Avoid creating new promises")
.with_help(
"Use `async`/`await` instead, or return an existing promise from a library function.",
)
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use oxc_span::{GetSpan, Span};
use crate::{AstNode, context::LintContext, rule::Rule};

fn prefer_await_to_callbacks(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Prefer `async`/`await` to the callback pattern").with_label(span)
OxcDiagnostic::warn("Prefer `async`/`await` to the callback pattern")
.with_help("Refactor to use an `async` function with `await` instead of passing callbacks for cleaner error handling and control flow.")
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use schemars::JsonSchema;
use serde::Deserialize;

fn prefer_wait_to_then_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Prefer await to then()/catch()/finally()").with_label(span)
OxcDiagnostic::warn("Prefer await to then()/catch()/finally()")
.with_help("Use `await` with `try`/`catch` instead of promise chaining for more readable and maintainable async code.")
.with_label(span)
}

use crate::{
Expand Down

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions crates/oxc_linter/src/snapshots/jest_no_hooks.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,35 @@ source: crates/oxc_linter/src/tester.rs
1 │ beforeAll(() => {})
· ─────────
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:1:1]
1 │ beforeEach(() => {})
· ──────────
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:1:1]
1 │ afterAll(() => {})
· ────────
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:1:1]
1 │ afterEach(() => {})
· ─────────
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:1:1]
1 │ beforeEach(() => {}); afterEach(() => { jest.resetModules() });
· ──────────
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:5:17]
Expand All @@ -39,48 +44,56 @@ source: crates/oxc_linter/src/tester.rs
· ──────────
6 │
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:1:1]
1 │ beforeAll(() => {})
· ─────────
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:1:1]
1 │ beforeEach(() => {})
· ──────────
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:1:1]
1 │ afterAll(() => {})
· ────────
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:1:1]
1 │ afterEach(() => {})
· ─────────
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:1:1]
1 │ afterEach(() => {})
· ─────────
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:1:1]
1 │ afterEach(() => {})
· ─────────
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:1:1]
1 │ beforeEach(() => {}); afterEach(() => { vi.resetModules() });
· ──────────
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.

⚠ eslint-plugin-jest(no-hooks): Do not use setup or teardown hooks.
╭─[no_hooks.tsx:4:8]
Expand All @@ -89,3 +102,4 @@ source: crates/oxc_linter/src/tester.rs
· ──────────
5 │
╰────
help: Inline the setup or teardown logic directly in each test for better readability and isolation.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:3:21]
Expand All @@ -17,6 +19,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:3:21]
Expand All @@ -25,6 +29,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:3:21]
Expand All @@ -33,6 +39,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:3:21]
Expand All @@ -41,6 +49,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:3:21]
Expand All @@ -49,6 +59,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:3:21]
Expand All @@ -57,6 +69,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:3:21]
Expand All @@ -65,6 +79,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:3:21]
Expand All @@ -73,6 +89,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:3:21]
Expand All @@ -81,6 +99,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:3:21]
Expand All @@ -89,6 +109,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:3:21]
Expand All @@ -97,6 +119,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:3:21]
Expand All @@ -105,6 +129,8 @@ source: crates/oxc_linter/src/tester.rs
· ──────
4 │ });
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.

⚠ eslint-plugin-jest(no-test-return-statement): Jest tests should not return a value
╭─[no_test_return_statement.tsx:4:21]
Expand All @@ -113,3 +139,5 @@ source: crates/oxc_linter/src/tester.rs
· ──────
5 │ }
╰────
help: Use `await` for async assertions or remove the return statement.
note: Jest ignores returned values from tests.
3 changes: 3 additions & 0 deletions crates/oxc_linter/src/snapshots/promise_avoid_new.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ source: crates/oxc_linter/src/tester.rs
1 │ var x = new Promise(function (x, y) {})
· ───────────────────────────────
╰────
help: Use `async`/`await` instead, or return an existing promise from a library function.

⚠ eslint-plugin-promise(avoid-new): Avoid creating new promises
╭─[avoid_new.tsx:1:1]
1 │ new Promise()
· ─────────────
╰────
help: Use `async`/`await` instead, or return an existing promise from a library function.

⚠ eslint-plugin-promise(avoid-new): Avoid creating new promises
╭─[avoid_new.tsx:1:7]
1 │ Thing(new Promise(() => {}))
· ─────────────────────
╰────
help: Use `async`/`await` instead, or return an existing promise from a library function.
Loading
Loading