You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OxcDiagnostic::warn(format!("Require a message for {matcher_name:?}."))
14
-
.with_help(format!("Add an error message to {matcher_name:?}"))
15
-
.with_label(span)
16
-
}
17
-
18
10
#[derive(Debug,Default,Clone)]
19
11
pubstructRequireToThrowMessage;
20
12
21
13
declare_oxc_lint!(
22
-
/// ### What it does
23
-
///
24
-
/// This rule triggers a warning if `toThrow()` or `toThrowError()` is used without an error message.
25
-
///
26
-
/// ### Why is this bad?
27
-
///
28
-
/// Using `toThrow()` or `toThrowError()` without specifying an expected error message
29
-
/// makes tests less specific and harder to debug. When a test only checks that an
30
-
/// error was thrown but not what kind of error, it can pass even when the wrong
31
-
/// error is thrown, potentially hiding bugs. Providing an expected error message
32
-
/// or error type makes tests more precise and helps catch regressions more effectively.
33
-
///
34
-
/// ### Examples
35
-
///
36
-
/// Examples of **incorrect** code for this rule:
37
-
/// ```javascript
38
-
/// test('all the things', async () => {
39
-
/// expect(() => a()).toThrow();
40
-
/// expect(() => a()).toThrowError();
41
-
/// await expect(a()).rejects.toThrow();
42
-
/// await expect(a()).rejects.toThrowError();
43
-
/// });
44
-
/// ```
45
-
///
46
-
/// Examples of **correct** code for this rule:
47
-
/// ```javascript
48
-
/// test('all the things', async () => {
49
-
/// expect(() => a()).toThrow('a');
50
-
/// expect(() => a()).toThrowError('a');
51
-
/// await expect(a()).rejects.toThrow('a');
52
-
/// await expect(a()).rejects.toThrowError('a');
53
-
/// });
54
-
/// ```
55
-
///
56
-
/// This rule is compatible with [eslint-plugin-vitest](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/require-to-throw-message.md),
57
-
/// to use it, add the following configuration to your `.oxlintrc.json`:
58
-
///
59
-
/// ```json
60
-
/// {
61
-
/// "rules": {
62
-
/// "vitest/require-to-throw-message": "error"
63
-
/// }
64
-
/// }
65
-
/// ```
66
14
RequireToThrowMessage,
67
15
jest,
68
16
correctness,
17
+
docs = DOCUMENTATION,
69
18
version = "0.2.9",
70
19
);
71
20
@@ -75,47 +24,14 @@ impl Rule for RequireToThrowMessage {
0 commit comments