Skip to content

Commit da395e9

Browse files
committed
u
framwork flags can sometime be unreliable, so merge the two help messages into one, and update the help text
1 parent 51019f0 commit da395e9

File tree

2 files changed

+18
-40
lines changed

2 files changed

+18
-40
lines changed

crates/oxc_linter/src/rules/jest/no_mocks_import.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@ use oxc_span::Span;
77

88
use crate::{context::LintContext, rule::Rule};
99

10-
fn no_mocks_jest_import_diagnostic(span: Span) -> OxcDiagnostic {
10+
fn no_mocks_import_diagnostic(span: Span) -> OxcDiagnostic {
1111
OxcDiagnostic::warn("Mocks should not be manually imported from a `__mocks__` directory.")
12-
.with_help("Instead use `jest.mock` and import from the original module path.")
13-
.with_label(span)
14-
}
15-
16-
fn no_mocks_vitest_import_diagnostic(span: Span) -> OxcDiagnostic {
17-
OxcDiagnostic::warn("Mocks should not be manually imported from a `__mocks__` directory.")
18-
.with_help("Instead use `vi.mock` and import from the original module path.")
12+
.with_help("Instead use `jest.mock` or `vi.mock` and import from the original module path.")
1913
.with_label(span)
2014
}
2115

@@ -72,17 +66,7 @@ impl Rule for NoMocksImport {
7266
for import_entry in &module_records.import_entries {
7367
let module_specifier = import_entry.module_request.name();
7468
if contains_mocks_dir(module_specifier) {
75-
if ctx.frameworks().is_vitest() {
76-
ctx.diagnostic(no_mocks_vitest_import_diagnostic(
77-
import_entry.module_request.span,
78-
));
79-
}
80-
81-
if ctx.frameworks().is_jest() {
82-
ctx.diagnostic(no_mocks_jest_import_diagnostic(
83-
import_entry.module_request.span,
84-
));
85-
}
69+
ctx.diagnostic(no_mocks_import_diagnostic(import_entry.module_request.span));
8670
}
8771
}
8872

@@ -103,13 +87,7 @@ impl Rule for NoMocksImport {
10387
};
10488

10589
if contains_mocks_dir(&string_literal.value) {
106-
if ctx.frameworks().is_vitest() {
107-
ctx.diagnostic(no_mocks_vitest_import_diagnostic(string_literal.span));
108-
}
109-
110-
if ctx.frameworks().is_jest() {
111-
ctx.diagnostic(no_mocks_jest_import_diagnostic(string_literal.span));
112-
}
90+
ctx.diagnostic(no_mocks_import_diagnostic(string_literal.span));
11391
}
11492
}
11593
}

crates/oxc_linter/src/snapshots/jest_no_mocks_import.snap

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,95 +6,95 @@ source: crates/oxc_linter/src/tester.rs
66
1require('./__mocks__')
77
· ─────────────
88
╰────
9-
help: Instead use `jest.mock` and import from the original module path.
9+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
1010

1111
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
1212
╭─[no_mocks_import.tsx:1:9]
1313
1require('./__mocks__/')
1414
· ──────────────
1515
╰────
16-
help: Instead use `jest.mock` and import from the original module path.
16+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
1717

1818
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
1919
╭─[no_mocks_import.tsx:1:9]
2020
1require('./__mocks__/index')
2121
· ───────────────────
2222
╰────
23-
help: Instead use `jest.mock` and import from the original module path.
23+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
2424

2525
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
2626
╭─[no_mocks_import.tsx:1:9]
2727
1require('__mocks__')
2828
· ───────────
2929
╰────
30-
help: Instead use `jest.mock` and import from the original module path.
30+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
3131

3232
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
3333
╭─[no_mocks_import.tsx:1:9]
3434
1require('__mocks__/')
3535
· ────────────
3636
╰────
37-
help: Instead use `jest.mock` and import from the original module path.
37+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
3838

3939
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
4040
╭─[no_mocks_import.tsx:1:9]
4141
1require('__mocks__/index')
4242
· ─────────────────
4343
╰────
44-
help: Instead use `jest.mock` and import from the original module path.
44+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
4545

4646
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
4747
╭─[no_mocks_import.tsx:1:19]
4848
1import thing from './__mocks__/index'
4949
· ───────────────────
5050
╰────
51-
help: Instead use `jest.mock` and import from the original module path.
51+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
5252

5353
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
5454
╭─[no_mocks_import.tsx:1:9]
5555
1require('./__mocks__')
5656
· ─────────────
5757
╰────
58-
help: Instead use `jest.mock` and import from the original module path.
58+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
5959

6060
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
6161
╭─[no_mocks_import.tsx:1:9]
6262
1require('./__mocks__/')
6363
· ──────────────
6464
╰────
65-
help: Instead use `jest.mock` and import from the original module path.
65+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
6666

6767
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
6868
╭─[no_mocks_import.tsx:1:9]
6969
1require('./__mocks__/index')
7070
· ───────────────────
7171
╰────
72-
help: Instead use `jest.mock` and import from the original module path.
72+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
7373

7474
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
7575
╭─[no_mocks_import.tsx:1:9]
7676
1require('__mocks__')
7777
· ───────────
7878
╰────
79-
help: Instead use `jest.mock` and import from the original module path.
79+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
8080

8181
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
8282
╭─[no_mocks_import.tsx:1:9]
8383
1require('__mocks__/')
8484
· ────────────
8585
╰────
86-
help: Instead use `jest.mock` and import from the original module path.
86+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
8787

8888
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
8989
╭─[no_mocks_import.tsx:1:9]
9090
1require('__mocks__/index')
9191
· ─────────────────
9292
╰────
93-
help: Instead use `jest.mock` and import from the original module path.
93+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.
9494

9595
eslint-plugin-jest(no-mocks-import): Mocks should not be manually imported from a `__mocks__` directory.
9696
╭─[no_mocks_import.tsx:1:19]
9797
1import thing from './__mocks__/index'
9898
· ───────────────────
9999
╰────
100-
help: Instead use `jest.mock` and import from the original module path.
100+
help: Instead use `jest.mock` or `vi.mock` and import from the original module path.

0 commit comments

Comments
 (0)