@@ -10,22 +10,27 @@ final class AlwaysUseLiteralForEmptyCollectionInitTests: LintOrFormatRuleTestCas
10
10
public struct Test {
11
11
var value1 = 1️⃣[Int]()
12
12
13
- func test(v: [Double] = [Double]()) {
14
- let _ = 2️⃣ [String]()
13
+ func test(v: [Double] = 2️⃣ [Double]()) {
14
+ let _ = 3️⃣ [String]()
15
15
}
16
16
}
17
17
18
- var _: [Category<Int>] = 3️⃣ [Category<Int>]()
19
- let _ = 4️⃣ [(Int, Array<String>)]()
20
- let _: [(String, Int, Float)] = 5️⃣ [(String, Int, Float)]()
18
+ var _: [Category<Int>] = 4️⃣ [Category<Int>]()
19
+ let _ = 5️⃣ [(Int, Array<String>)]()
20
+ let _: [(String, Int, Float)] = 6️⃣ [(String, Int, Float)]()
21
21
22
22
let _ = [(1, 2, String)]()
23
+
24
+ class TestSubscript {
25
+ subscript(_: [A] = 7️⃣[A](), x: [(Int, B)] = 8️⃣[(Int, B)]()) {
26
+ }
27
+ }
23
28
""" ,
24
29
expected: """
25
30
public struct Test {
26
31
var value1: [Int] = []
27
32
28
- func test(v: [Double] = [Double]() ) {
33
+ func test(v: [Double] = [] ) {
29
34
let _: [String] = []
30
35
}
31
36
}
@@ -35,13 +40,21 @@ final class AlwaysUseLiteralForEmptyCollectionInitTests: LintOrFormatRuleTestCas
35
40
let _: [(String, Int, Float)] = []
36
41
37
42
let _ = [(1, 2, String)]()
43
+
44
+ class TestSubscript {
45
+ subscript(_: [A] = [], x: [(Int, B)] = []) {
46
+ }
47
+ }
38
48
""" ,
39
49
findings: [
40
50
FindingSpec ( " 1️⃣ " , message: " replace '[Int]()' with ': [Int] = []' " ) ,
41
- FindingSpec ( " 2️⃣ " , message: " replace '[String]()' with ': [String] = []' " ) ,
42
- FindingSpec ( " 3️⃣ " , message: " replace '[Category<Int>]()' with '[]' " ) ,
43
- FindingSpec ( " 4️⃣ " , message: " replace '[(Int, Array<String>)]()' with ': [(Int, Array<String>)] = []' " ) ,
44
- FindingSpec ( " 5️⃣ " , message: " replace '[(String, Int, Float)]()' with '[]' " ) ,
51
+ FindingSpec ( " 2️⃣ " , message: " replace '[Double]()' with '[]' " ) ,
52
+ FindingSpec ( " 3️⃣ " , message: " replace '[String]()' with ': [String] = []' " ) ,
53
+ FindingSpec ( " 4️⃣ " , message: " replace '[Category<Int>]()' with '[]' " ) ,
54
+ FindingSpec ( " 5️⃣ " , message: " replace '[(Int, Array<String>)]()' with ': [(Int, Array<String>)] = []' " ) ,
55
+ FindingSpec ( " 6️⃣ " , message: " replace '[(String, Int, Float)]()' with '[]' " ) ,
56
+ FindingSpec ( " 7️⃣ " , message: " replace '[A]()' with '[]' " ) ,
57
+ FindingSpec ( " 8️⃣ " , message: " replace '[(Int, B)]()' with '[]' " ) ,
45
58
]
46
59
)
47
60
}
@@ -53,22 +66,27 @@ final class AlwaysUseLiteralForEmptyCollectionInitTests: LintOrFormatRuleTestCas
53
66
public struct Test {
54
67
var value1 = 1️⃣[Int: String]()
55
68
56
- func test(v: [Double: Int] = [Double: Int]()) {
57
- let _ = 2️⃣ [String: Int]()
69
+ func test(v: [Double: Int] = 2️⃣ [Double: Int]()) {
70
+ let _ = 3️⃣ [String: Int]()
58
71
}
59
72
}
60
73
61
- var _: [Category<Int>: String] = 3️⃣ [Category<Int>: String]()
62
- let _ = 4️⃣ [(Int, Array<String>): Int]()
63
- let _: [String: (String, Int, Float)] = 5️⃣ [String: (String, Int, Float)]()
74
+ var _: [Category<Int>: String] = 4️⃣ [Category<Int>: String]()
75
+ let _ = 5️⃣ [(Int, Array<String>): Int]()
76
+ let _: [String: (String, Int, Float)] = 6️⃣ [String: (String, Int, Float)]()
64
77
65
78
let _ = [String: (1, 2, String)]()
79
+
80
+ class TestSubscript {
81
+ subscript(_: [A: Int] = 7️⃣[A: Int](), x: [(Int, B): String] = 8️⃣[(Int, B): String]()) {
82
+ }
83
+ }
66
84
""" ,
67
85
expected: """
68
86
public struct Test {
69
87
var value1: [Int: String] = [:]
70
88
71
- func test(v: [Double: Int] = [Double: Int]() ) {
89
+ func test(v: [Double: Int] = [:] ) {
72
90
let _: [String: Int] = [:]
73
91
}
74
92
}
@@ -78,13 +96,21 @@ final class AlwaysUseLiteralForEmptyCollectionInitTests: LintOrFormatRuleTestCas
78
96
let _: [String: (String, Int, Float)] = [:]
79
97
80
98
let _ = [String: (1, 2, String)]()
99
+
100
+ class TestSubscript {
101
+ subscript(_: [A: Int] = [:], x: [(Int, B): String] = [:]) {
102
+ }
103
+ }
81
104
""" ,
82
105
findings: [
83
106
FindingSpec ( " 1️⃣ " , message: " replace '[Int: String]()' with ': [Int: String] = [:]' " ) ,
84
- FindingSpec ( " 2️⃣ " , message: " replace '[String: Int]()' with ': [String: Int] = [:]' " ) ,
85
- FindingSpec ( " 3️⃣ " , message: " replace '[Category<Int>: String]()' with '[:]' " ) ,
86
- FindingSpec ( " 4️⃣ " , message: " replace '[(Int, Array<String>): Int]()' with ': [(Int, Array<String>): Int] = [:]' " ) ,
87
- FindingSpec ( " 5️⃣ " , message: " replace '[String: (String, Int, Float)]()' with '[:]' " ) ,
107
+ FindingSpec ( " 2️⃣ " , message: " replace '[Double: Int]()' with '[:]' " ) ,
108
+ FindingSpec ( " 3️⃣ " , message: " replace '[String: Int]()' with ': [String: Int] = [:]' " ) ,
109
+ FindingSpec ( " 4️⃣ " , message: " replace '[Category<Int>: String]()' with '[:]' " ) ,
110
+ FindingSpec ( " 5️⃣ " , message: " replace '[(Int, Array<String>): Int]()' with ': [(Int, Array<String>): Int] = [:]' " ) ,
111
+ FindingSpec ( " 6️⃣ " , message: " replace '[String: (String, Int, Float)]()' with '[:]' " ) ,
112
+ FindingSpec ( " 7️⃣ " , message: " replace '[A: Int]()' with '[:]' " ) ,
113
+ FindingSpec ( " 8️⃣ " , message: " replace '[(Int, B): String]()' with '[:]' " ) ,
88
114
]
89
115
)
90
116
}
0 commit comments