@@ -16,17 +16,18 @@ use crate::{
16
16
utils:: { PossibleJestNode , iter_possible_jest_call_node, parse_expect_jest_fn_call} ,
17
17
} ;
18
18
19
- // TODO: re-word diagnostic messages
20
- fn no_snapshot ( x0 : usize , span : Span ) -> OxcDiagnostic {
21
- OxcDiagnostic :: warn ( "Disallow large snapshots." )
22
- . with_help ( format ! ( "`{x0:?}`s should begin with lowercase" ) )
19
+ fn no_snapshot ( line_count : usize , span : Span ) -> OxcDiagnostic {
20
+ OxcDiagnostic :: warn ( "Snapshot is too long." )
21
+ . with_help ( format ! (
22
+ "Expected to not encounter a Jest snapshot but one was found that is {line_count} lines long"
23
+ ) )
23
24
. with_label ( span)
24
25
}
25
26
26
- fn too_long_snapshots ( x0 : usize , x1 : usize , span : Span ) -> OxcDiagnostic {
27
- OxcDiagnostic :: warn ( "Disallow large snapshots ." )
27
+ fn too_long_snapshot ( line_limit : usize , line_count : usize , span : Span ) -> OxcDiagnostic {
28
+ OxcDiagnostic :: warn ( "Snapshot is too long ." )
28
29
. with_help ( format ! (
29
- "Expected Jest snapshot to be smaller than {x0:? } lines but was {x1:? } lines long"
30
+ "Expected Jest snapshot to be smaller than {line_limit } lines but was {line_count } lines long"
30
31
) )
31
32
. with_label ( span)
32
33
}
@@ -64,7 +65,6 @@ declare_oxc_lint!(
64
65
///
65
66
/// ### Example
66
67
///
67
- ///
68
68
/// Examples of **incorrect** code for this rule:
69
69
/// ```javascript
70
70
/// exports[`a large snapshot 1`] = `
@@ -121,6 +121,7 @@ declare_oxc_lint!(
121
121
/// line 51
122
122
/// `;
123
123
/// ```
124
+ ///
124
125
/// Examples of **incorrect** code for this rule:
125
126
/// ```js
126
127
/// exports[`a more manageable and readable snapshot 1`] = `
@@ -143,13 +144,15 @@ impl Rule for NoLargeSnapshots {
143
144
. and_then ( |c| c. get ( "maxSize" ) )
144
145
. and_then ( serde_json:: Value :: as_number)
145
146
. and_then ( serde_json:: Number :: as_u64)
146
- . map_or ( 50 , |v| usize:: try_from ( v) . unwrap_or ( 50 ) ) ;
147
+ . and_then ( |v| usize:: try_from ( v) . ok ( ) )
148
+ . unwrap_or ( 50 ) ;
147
149
148
150
let inline_max_size = config
149
151
. and_then ( |c| c. get ( "inlineMaxSize" ) )
150
152
. and_then ( serde_json:: Value :: as_number)
151
153
. and_then ( serde_json:: Number :: as_u64)
152
- . map_or ( max_size, |v| usize:: try_from ( v) . unwrap_or ( max_size) ) ;
154
+ . and_then ( |v| usize:: try_from ( v) . ok ( ) )
155
+ . unwrap_or ( max_size) ;
153
156
154
157
let allowed_snapshots = config
155
158
. and_then ( |c| c. get ( "allowedSnapshots" ) )
@@ -236,7 +239,7 @@ impl NoLargeSnapshots {
236
239
if line_count == 0 {
237
240
ctx. diagnostic ( no_snapshot ( line_count, expr_stmt. span ) ) ;
238
241
} else {
239
- ctx. diagnostic ( too_long_snapshots ( self . max_size , line_count, expr_stmt. span ) ) ;
242
+ ctx. diagnostic ( too_long_snapshot ( self . max_size , line_count, expr_stmt. span ) ) ;
240
243
}
241
244
}
242
245
}
@@ -248,7 +251,7 @@ impl NoLargeSnapshots {
248
251
if self . inline_max_size == 0 {
249
252
ctx. diagnostic ( no_snapshot ( line_count, span) ) ;
250
253
} else {
251
- ctx. diagnostic ( too_long_snapshots ( self . inline_max_size , line_count, span) ) ;
254
+ ctx. diagnostic ( too_long_snapshot ( self . inline_max_size , line_count, span) ) ;
252
255
}
253
256
}
254
257
}
@@ -341,7 +344,7 @@ fn test() {
341
344
// #[cfg(not(target_os = "windows"))]
342
345
// let another_snap_path = "/another-mock-component.jsx.snap";
343
346
344
- let tow_match_inline_cases = generate_match_inline_snapshot ( 2 ) ;
347
+ let two_match_inline_cases = generate_match_inline_snapshot ( 2 ) ;
345
348
let two_throw_error_match_cases = generate_throw_error_matching_inline_snapshot ( 2 ) ;
346
349
let twenty_match_inline_cases = generate_match_inline_snapshot ( 20 ) ;
347
350
let sixty_match_inline_cases = generate_match_inline_snapshot ( 60 ) ;
@@ -365,7 +368,7 @@ fn test() {
365
368
( "expect(something).toBe(1)" , None , None , None ) ,
366
369
( "expect(something).toMatchInlineSnapshot" , None , None , None ) ,
367
370
( "expect(something).toMatchInlineSnapshot()" , None , None , None ) ,
368
- ( tow_match_inline_cases . as_str( ) , None , None , None ) ,
371
+ ( two_match_inline_cases . as_str( ) , None , None , None ) ,
369
372
( two_throw_error_match_cases. as_str( ) , None , None , None ) ,
370
373
(
371
374
twenty_match_inline_cases. as_str( ) ,
@@ -424,6 +427,12 @@ fn test() {
424
427
None ,
425
428
None ,
426
429
) ,
430
+ (
431
+ fifty_throw_error_match_cases. as_str( ) ,
432
+ Some ( serde_json:: json!( [ { "maxSize" : 0 } ] ) ) ,
433
+ None ,
434
+ None ,
435
+ ) ,
427
436
// '/mock-component.jsx.snap'
428
437
// (fifty_two_exports_snapshot.as_str(), None, None, Some(PathBuf::from(snap_path))),
429
438
// '/mock-component.jsx.snap'
0 commit comments