@@ -25,6 +25,20 @@ final class AlwaysUseLiteralForEmptyCollectionInitTests: LintOrFormatRuleTestCas
25
25
subscript(_: [A] = 7️⃣[A](), x: [(Int, B)] = 8️⃣[(Int, B)]()) {
26
26
}
27
27
}
28
+
29
+ // All of the examples in this block could be re-written to use leading-dot syntax: `.init(...)`
30
+ do {
31
+ let _ = [Int](repeating: 0, count: 10)
32
+ let _: [Int] = [Int](repeating: 0, count: 10)
33
+
34
+ func testDefault(_ x: [String] = [String](repeating: " a " , count: 42)) {
35
+ }
36
+
37
+ class TestSubscript {
38
+ subscript(_: Int = 42, x: [(Int, B)] = [(Int, B)](repeating: (0, B()), count: 1)) {
39
+ }
40
+ }
41
+ }
28
42
""" ,
29
43
expected: """
30
44
public struct Test {
@@ -45,6 +59,20 @@ final class AlwaysUseLiteralForEmptyCollectionInitTests: LintOrFormatRuleTestCas
45
59
subscript(_: [A] = [], x: [(Int, B)] = []) {
46
60
}
47
61
}
62
+
63
+ // All of the examples in this block could be re-written to use leading-dot syntax: `.init(...)`
64
+ do {
65
+ let _ = [Int](repeating: 0, count: 10)
66
+ let _: [Int] = [Int](repeating: 0, count: 10)
67
+
68
+ func testDefault(_ x: [String] = [String](repeating: " a " , count: 42)) {
69
+ }
70
+
71
+ class TestSubscript {
72
+ subscript(_: Int = 42, x: [(Int, B)] = [(Int, B)](repeating: (0, B()), count: 1)) {
73
+ }
74
+ }
75
+ }
48
76
""" ,
49
77
findings: [
50
78
FindingSpec ( " 1️⃣ " , message: " replace '[Int]()' with ': [Int] = []' " ) ,
@@ -81,6 +109,20 @@ final class AlwaysUseLiteralForEmptyCollectionInitTests: LintOrFormatRuleTestCas
81
109
subscript(_: [A: Int] = 7️⃣[A: Int](), x: [(Int, B): String] = 8️⃣[(Int, B): String]()) {
82
110
}
83
111
}
112
+
113
+ // All of the examples in this block could be re-written to use leading-dot syntax: `.init(...)`
114
+ do {
115
+ let _ = [String: Int](minimumCapacity: 42)
116
+ let _: [String: Int] = [String: Int](minimumCapacity: 42)
117
+
118
+ func testDefault(_ x: [Int: String] = [String](minimumCapacity: 1)) {
119
+ }
120
+
121
+ class TestSubscript {
122
+ subscript(_: Int = 42, x: [String: (Int, B)] = [String: (Int, B)](minimumCapacity: 2)) {
123
+ }
124
+ }
125
+ }
84
126
""" ,
85
127
expected: """
86
128
public struct Test {
@@ -101,6 +143,20 @@ final class AlwaysUseLiteralForEmptyCollectionInitTests: LintOrFormatRuleTestCas
101
143
subscript(_: [A: Int] = [:], x: [(Int, B): String] = [:]) {
102
144
}
103
145
}
146
+
147
+ // All of the examples in this block could be re-written to use leading-dot syntax: `.init(...)`
148
+ do {
149
+ let _ = [String: Int](minimumCapacity: 42)
150
+ let _: [String: Int] = [String: Int](minimumCapacity: 42)
151
+
152
+ func testDefault(_ x: [Int: String] = [String](minimumCapacity: 1)) {
153
+ }
154
+
155
+ class TestSubscript {
156
+ subscript(_: Int = 42, x: [String: (Int, B)] = [String: (Int, B)](minimumCapacity: 2)) {
157
+ }
158
+ }
159
+ }
104
160
""" ,
105
161
findings: [
106
162
FindingSpec ( " 1️⃣ " , message: " replace '[Int: String]()' with ': [Int: String] = [:]' " ) ,
0 commit comments