11// swiftlint:disable file_length
22// swiftlint:disable:next type_body_length
33internal struct ExplicitReturnRuleExamples {
4+ private static let closureConfig : [ String : any Sendable ] = [
5+ " included " : [ " closure " , " function " , " getter " , " subscript " , " initializer " ] ,
6+ ]
7+
48 internal struct ClosureExamples {
59 static let nonTriggeringExamples = [
610 Example ( """
711 foo.map {
812 return $0 + 1
913 }
10- """ ) ,
14+ """ , configuration : closureConfig ) ,
1115 Example ( """
1216 foo.map({
1317 return $0 + 1
1418 })
15- """ ) ,
19+ """ , configuration : closureConfig ) ,
1620 Example ( """
1721 foo.map { value in
1822 return value + 1
1923 }
20- """ ) ,
24+ """ , configuration : closureConfig ) ,
2125 Example ( """
2226 [1, 2].first(where: {
2327 return true
2428 })
25- """ ) ,
29+ """ , configuration : closureConfig ) ,
2630 Example ( """
2731 [1, 2].first(where: {
2832 bar($0)
2933 return true
3034 })
31- """ ) ,
35+ """ , configuration: closureConfig) ,
36+ Example ( """
37+ runOn(.main, {
38+ controller?.present(alert, animated: true, completion: nil)
39+ })
40+ """ , configuration: closureConfig) ,
41+ Example ( """
42+ foo.bar(failure: { error in
43+ cont.resume(throwing: error)
44+ })
45+ """ , configuration: closureConfig) ,
46+ Example ( """
47+ foo.map {
48+ someFunc($0)
49+ }
50+ """ , configuration: closureConfig) ,
51+ Example ( """
52+ foo.map {
53+ try someFunc($0)
54+ }
55+ """ , configuration: closureConfig) ,
56+ Example ( """
57+ foo.map {
58+ await someFunc($0)
59+ }
60+ """ , configuration: closureConfig) ,
3261 ]
3362
3463 static let triggeringExamples = [
3564 Example ( """
3665 foo.map { value in
3766 ↓value + 1
3867 }
39- """ ) ,
68+ """ , configuration : closureConfig ) ,
4069 Example ( """
4170 foo.map {
4271 ↓$0 + 1
4372 }
44- """ ) ,
45- Example ( " foo.map({ ↓$0 + 1 }) " ) ,
73+ """ , configuration : closureConfig ) ,
74+ Example ( " foo.map({ ↓$0 + 1 }) " , configuration : closureConfig ) ,
4675 Example ( """
4776 [1, 2].first(where: {
4877 ↓true
4978 })
50- """ ) ,
79+ """ , configuration : closureConfig ) ,
5180 ]
5281
53- static let corrections = [
82+ static let corrections : [ Example : Example ] = [
5483 Example ( """
5584 foo.map { value in
5685 // Important comment
5786 value + 1
5887 }
59- """ ) : Example ( """
88+ """ , configuration : closureConfig ) : Example ( """
6089 foo.map { value in
6190 // Important comment
6291 return value + 1
@@ -66,17 +95,18 @@ internal struct ExplicitReturnRuleExamples {
6695 foo.map {
6796 $0 + 1
6897 }
69- """ ) : Example ( """
98+ """ , configuration : closureConfig ) : Example ( """
7099 foo.map {
71100 return $0 + 1
72101 }
73102 """ ) ,
74- Example ( " foo.map({ $0 + 1 }) " ) : Example ( " foo.map({ return $0 + 1 }) " ) ,
103+ Example ( " foo.map({ $0 + 1 }) " , configuration: closureConfig) :
104+ Example ( " foo.map({ return $0 + 1 }) " ) ,
75105 Example ( """
76106 [1, 2].first(where: {
77107 true
78108 })
79- """ ) : Example ( """
109+ """ , configuration : closureConfig ) : Example ( """
80110 [1, 2].first(where: {
81111 return true
82112 })
@@ -422,20 +452,33 @@ internal struct ExplicitReturnRuleExamples {
422452 }
423453
424454 struct MixedExamples {
425- static let corrections = [
455+ static let corrections : [ Example : Example ] = [
426456 Example ( """
427457 func foo() -> Int {
428458 ↓[1, 2].first(where: {
429459 ↓true
430460 })!
431461 }
432- """ ) : Example ( """
462+ """ , configuration : closureConfig ) : Example ( """
433463 func foo() -> Int {
434464 return [1, 2].first(where: {
435465 return true
436466 })!
437467 }
438468 """ ) ,
469+ Example ( """
470+ func foo() -> Int {
471+ ↓[1, 2].first(where: {
472+ true
473+ })!
474+ }
475+ """ ) : Example ( """
476+ func foo() -> Int {
477+ return [1, 2].first(where: {
478+ true
479+ })!
480+ }
481+ """ ) ,
439482 ]
440483 }
441484
0 commit comments