1
+ import _SwiftFormatTestSupport
2
+
1
3
@_spi ( Rules) import SwiftFormat
2
4
3
5
final class OmitReturnsTests : LintOrFormatRuleTestCase {
4
6
func testOmitReturnInFunction( ) {
5
- XCTAssertFormatting (
7
+ assertFormatting (
6
8
OmitReturns . self,
7
9
input: """
8
10
func test() -> Bool {
9
- return false
11
+ 1️⃣return false
10
12
}
11
- """ ,
13
+ """ ,
12
14
expected: """
13
15
func test() -> Bool {
14
16
false
15
17
}
16
- """ )
18
+ """ ,
19
+ findings: [
20
+ FindingSpec ( " 1️⃣ " , message: " `return` can be omitted because body consists of a single expression " )
21
+ ] )
17
22
}
18
23
19
24
func testOmitReturnInClosure( ) {
20
- XCTAssertFormatting (
25
+ assertFormatting (
21
26
OmitReturns . self,
22
27
input: """
23
28
vals.filter {
24
- return $0.count == 1
29
+ 1️⃣return $0.count == 1
25
30
}
26
- """ ,
31
+ """ ,
27
32
expected: """
28
33
vals.filter {
29
34
$0.count == 1
30
35
}
31
- """ )
36
+ """ ,
37
+ findings: [
38
+ FindingSpec ( " 1️⃣ " , message: " `return` can be omitted because body consists of a single expression " )
39
+ ] )
32
40
}
33
41
34
42
func testOmitReturnInSubscript( ) {
35
- XCTAssertFormatting (
36
- OmitReturns . self,
37
- input: """
38
- struct Test {
39
- subscript(x: Int) -> Bool {
40
- return false
41
- }
42
- }
43
- """ ,
44
- expected: """
45
- struct Test {
46
- subscript(x: Int) -> Bool {
47
- false
48
- }
43
+ assertFormatting (
44
+ OmitReturns . self,
45
+ input: """
46
+ struct Test {
47
+ subscript(x: Int) -> Bool {
48
+ 1️⃣return false
49
49
}
50
- """ )
50
+ }
51
51
52
- XCTAssertFormatting (
53
- OmitReturns . self,
54
- input: """
55
- struct Test {
56
- subscript(x: Int) -> Bool {
57
- get {
58
- return false
59
- }
60
- set { }
52
+ struct Test {
53
+ subscript(x: Int) -> Bool {
54
+ get {
55
+ 2️⃣return false
61
56
}
57
+ set { }
58
+ }
59
+ }
60
+ """ ,
61
+ expected: """
62
+ struct Test {
63
+ subscript(x: Int) -> Bool {
64
+ false
62
65
}
63
- """ ,
64
- expected: """
65
- struct Test {
66
- subscript(x: Int) -> Bool {
67
- get {
68
- false
69
- }
70
- set { }
66
+ }
67
+
68
+ struct Test {
69
+ subscript(x: Int) -> Bool {
70
+ get {
71
+ false
71
72
}
73
+ set { }
72
74
}
73
- """ )
75
+ }
76
+ """ ,
77
+ findings: [
78
+ FindingSpec ( " 1️⃣ " , message: " `return` can be omitted because body consists of a single expression " ) ,
79
+ FindingSpec ( " 2️⃣ " , message: " `return` can be omitted because body consists of a single expression " )
80
+ ] )
74
81
}
75
82
76
83
func testOmitReturnInComputedVars( ) {
77
- XCTAssertFormatting (
84
+ assertFormatting (
78
85
OmitReturns . self,
79
86
input: """
80
87
var x: Int {
81
- return 42
82
- }
83
- """ ,
84
- expected: """
85
- var x: Int {
86
- 42
88
+ 1️⃣return 42
87
89
}
88
- """ )
89
90
90
- XCTAssertFormatting (
91
- OmitReturns . self,
92
- input: """
93
91
struct Test {
94
92
var x: Int {
95
93
get {
96
- return 42
94
+ 2️⃣return 42
97
95
}
98
96
set { }
99
97
}
100
98
}
101
- """ ,
99
+ """ ,
102
100
expected: """
101
+ var x: Int {
102
+ 42
103
+ }
104
+
103
105
struct Test {
104
106
var x: Int {
105
107
get {
@@ -108,6 +110,10 @@ final class OmitReturnsTests: LintOrFormatRuleTestCase {
108
110
set { }
109
111
}
110
112
}
111
- """ )
113
+ """ ,
114
+ findings: [
115
+ FindingSpec ( " 1️⃣ " , message: " `return` can be omitted because body consists of a single expression " ) ,
116
+ FindingSpec ( " 2️⃣ " , message: " `return` can be omitted because body consists of a single expression " )
117
+ ] )
112
118
}
113
119
}
0 commit comments