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
26 changes: 15 additions & 11 deletions crates/oxc_linter/src/rules/jest/no_large_snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn no_snapshot(line_count: usize, span: Span) -> OxcDiagnostic {
fn too_long_snapshot(line_limit: usize, line_count: usize, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Snapshot is too long.")
.with_help(format!(
"Expected Jest snapshot to be smaller than {line_limit} lines but was {line_count} lines long"
"Expected Jest snapshot to be no longer than {line_limit} lines but it was {line_count} lines long"
))
.with_label(span)
}
Expand Down Expand Up @@ -193,21 +193,21 @@ impl NoLargeSnapshots {
return;
};

if !jest_fn_call.args.is_empty()
&& jest_fn_call.members.iter().any(|member| {
if !jest_fn_call.args.is_empty() {
let Some(snapshot_matcher) = jest_fn_call.members.iter().find(|member| {
member.is_name_equal("toMatchInlineSnapshot")
|| member.is_name_equal("toThrowErrorMatchingInlineSnapshot")
})
{
}) else {
return;
};
let Some(first_arg) = jest_fn_call.args.first() else {
return;
};
let Some(first_arg_expr) = first_arg.as_expression() else {
return;
};

let span = first_arg_expr.span();
self.report_in_span(span, ctx);
self.report_in_span(snapshot_matcher.span, first_arg_expr.span(), ctx);
}
}

Expand Down Expand Up @@ -244,14 +244,18 @@ impl NoLargeSnapshots {
}
}

fn report_in_span(&self, span: Span, ctx: &LintContext) {
let line_count = Self::get_line_count(span, ctx);
fn report_in_span(&self, snapshot_matcher_span: Span, first_arg_span: Span, ctx: &LintContext) {
let line_count = Self::get_line_count(first_arg_span, ctx);

if line_count > self.inline_max_size {
if self.inline_max_size == 0 {
ctx.diagnostic(no_snapshot(line_count, span));
ctx.diagnostic(no_snapshot(line_count, snapshot_matcher_span));
} else {
ctx.diagnostic(too_long_snapshot(self.inline_max_size, line_count, span));
ctx.diagnostic(too_long_snapshot(
self.inline_max_size,
line_count,
snapshot_matcher_span,
));
}
}
}
Expand Down
242 changes: 23 additions & 219 deletions crates/oxc_linter/src/snapshots/jest_no_large_snapshots.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,229 +2,33 @@
source: crates/oxc_linter/src/tester.rs
---
⚠ eslint-plugin-jest(no-large-snapshots): Snapshot is too long.
╭─[no_large_snapshots.tsx:1:41]
1 │ ╭─▶ expect(something).toMatchInlineSnapshot(`
2 │ │ line
3 │ │ line
4 │ │ line
5 │ │ line
6 │ │ line
7 │ │ line
8 │ │ line
9 │ │ line
10 │ │ line
11 │ │ line
12 │ │ line
13 │ │ line
14 │ │ line
15 │ │ line
16 │ │ line
17 │ │ line
18 │ │ line
19 │ │ line
20 │ │ line
21 │ │ line
22 │ │ line
23 │ │ line
24 │ │ line
25 │ │ line
26 │ │ line
27 │ │ line
28 │ │ line
29 │ │ line
30 │ │ line
31 │ │ line
32 │ │ line
33 │ │ line
34 │ │ line
35 │ │ line
36 │ │ line
37 │ │ line
38 │ │ line
39 │ │ line
40 │ │ line
41 │ │ line
42 │ │ line
43 │ │ line
44 │ │ line
45 │ │ line
46 │ │ line
47 │ │ line
48 │ │ line
49 │ │ line
50 │ │ line
51 │ │ line
52 │ ╰─▶ `);
╰────
help: Expected Jest snapshot to be smaller than 50 lines but was 51 lines long
╭─[no_large_snapshots.tsx:1:19]
1 │ expect(something).toMatchInlineSnapshot(`
· ─────────────────────
2 │ line
╰────
help: Expected Jest snapshot to be no longer than 50 lines but it was 51 lines long

⚠ eslint-plugin-jest(no-large-snapshots): Snapshot is too long.
╭─[no_large_snapshots.tsx:1:54]
1 │ ╭─▶ expect(something).toThrowErrorMatchingInlineSnapshot(`
2 │ │ line
3 │ │ line
4 │ │ line
5 │ │ line
6 │ │ line
7 │ │ line
8 │ │ line
9 │ │ line
10 │ │ line
11 │ │ line
12 │ │ line
13 │ │ line
14 │ │ line
15 │ │ line
16 │ │ line
17 │ │ line
18 │ │ line
19 │ │ line
20 │ │ line
21 │ │ line
22 │ │ line
23 │ │ line
24 │ │ line
25 │ │ line
26 │ │ line
27 │ │ line
28 │ │ line
29 │ │ line
30 │ │ line
31 │ │ line
32 │ │ line
33 │ │ line
34 │ │ line
35 │ │ line
36 │ │ line
37 │ │ line
38 │ │ line
39 │ │ line
40 │ │ line
41 │ │ line
42 │ │ line
43 │ │ line
44 │ │ line
45 │ │ line
46 │ │ line
47 │ │ line
48 │ │ line
49 │ │ line
50 │ │ line
51 │ │ line
52 │ ╰─▶ `);
╰────
help: Expected Jest snapshot to be smaller than 50 lines but was 51 lines long
╭─[no_large_snapshots.tsx:1:19]
1 │ expect(something).toThrowErrorMatchingInlineSnapshot(`
· ──────────────────────────────────
2 │ line
╰────
help: Expected Jest snapshot to be no longer than 50 lines but it was 51 lines long

⚠ eslint-plugin-jest(no-large-snapshots): Snapshot is too long.
╭─[no_large_snapshots.tsx:1:54]
1 │ ╭─▶ expect(something).toThrowErrorMatchingInlineSnapshot(`
2 │ │ line
3 │ │ line
4 │ │ line
5 │ │ line
6 │ │ line
7 │ │ line
8 │ │ line
9 │ │ line
10 │ │ line
11 │ │ line
12 │ │ line
13 │ │ line
14 │ │ line
15 │ │ line
16 │ │ line
17 │ │ line
18 │ │ line
19 │ │ line
20 │ │ line
21 │ │ line
22 │ │ line
23 │ │ line
24 │ │ line
25 │ │ line
26 │ │ line
27 │ │ line
28 │ │ line
29 │ │ line
30 │ │ line
31 │ │ line
32 │ │ line
33 │ │ line
34 │ │ line
35 │ │ line
36 │ │ line
37 │ │ line
38 │ │ line
39 │ │ line
40 │ │ line
41 │ │ line
42 │ │ line
43 │ │ line
44 │ │ line
45 │ │ line
46 │ │ line
47 │ │ line
48 │ │ line
49 │ │ line
50 │ │ line
51 │ │ line
52 │ ╰─▶ `);
╰────
help: Expected Jest snapshot to be smaller than 50 lines but was 51 lines long
╭─[no_large_snapshots.tsx:1:19]
1 │ expect(something).toThrowErrorMatchingInlineSnapshot(`
· ──────────────────────────────────
2 │ line
╰────
help: Expected Jest snapshot to be no longer than 50 lines but it was 51 lines long

⚠ eslint-plugin-jest(no-large-snapshots): Snapshot is too long.
╭─[no_large_snapshots.tsx:1:54]
1 │ ╭─▶ expect(something).toThrowErrorMatchingInlineSnapshot(`
2 │ │ line
3 │ │ line
4 │ │ line
5 │ │ line
6 │ │ line
7 │ │ line
8 │ │ line
9 │ │ line
10 │ │ line
11 │ │ line
12 │ │ line
13 │ │ line
14 │ │ line
15 │ │ line
16 │ │ line
17 │ │ line
18 │ │ line
19 │ │ line
20 │ │ line
21 │ │ line
22 │ │ line
23 │ │ line
24 │ │ line
25 │ │ line
26 │ │ line
27 │ │ line
28 │ │ line
29 │ │ line
30 │ │ line
31 │ │ line
32 │ │ line
33 │ │ line
34 │ │ line
35 │ │ line
36 │ │ line
37 │ │ line
38 │ │ line
39 │ │ line
40 │ │ line
41 │ │ line
42 │ │ line
43 │ │ line
44 │ │ line
45 │ │ line
46 │ │ line
47 │ │ line
48 │ │ line
49 │ │ line
50 │ │ line
51 │ │ line
52 │ ╰─▶ `);
╰────
╭─[no_large_snapshots.tsx:1:19]
1 │ expect(something).toThrowErrorMatchingInlineSnapshot(`
· ──────────────────────────────────
2 │ line
╰────
help: Expected to not encounter a Jest snapshot but one was found that is 51 lines long
Loading