Skip to content

Commit dfa3334

Browse files
committed
Updated Examples
1 parent 60a3bef commit dfa3334

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Source/SwiftLintBuiltInRules/Rules/Lint/VariableShadowingRule.swift

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,52 @@ struct VariableShadowingRule: Rule {
5656
}
5757
}
5858
"""),
59+
Example("""
60+
var outer: String = "hello"
61+
if let inner = Optional(outer) {
62+
print(inner)
63+
}
64+
"""),
65+
Example("""
66+
var a: String = "outer"
67+
let (b, c) = ("first", "second")
68+
print(a, b, c)
69+
"""),
70+
Example("""
71+
class Test {
72+
var property: String = "class property"
73+
func test() {
74+
var localVar = "local"
75+
print(property, localVar)
76+
}
77+
}
78+
"""),
79+
Example("""
80+
func outer() {
81+
func inner() {
82+
print("no shadowing")
83+
}
84+
}
85+
"""),
86+
Example("""
87+
var result: String?
88+
if let unwrappedResult = result {
89+
print(unwrappedResult)
90+
}
91+
"""),
92+
Example("""
93+
var value: Int? = 10
94+
guard let safeValue = value else {
95+
return
96+
}
97+
print(safeValue)
98+
"""),
99+
Example("""
100+
var data: [Int?] = [1, nil, 3]
101+
for case let item? in data {
102+
print(item)
103+
}
104+
"""),
59105
],
60106
triggeringExamples: [
61107
Example("""
@@ -65,6 +111,38 @@ struct VariableShadowingRule: Rule {
65111
print(outer)
66112
}
67113
"""),
114+
Example("""
115+
var x = 1
116+
do {
117+
let ↓x = 2
118+
print(x)
119+
}
120+
"""),
121+
Example("""
122+
var counter = 0
123+
func incrementCounter() {
124+
var ↓counter = 1
125+
counter += 1
126+
}
127+
"""),
128+
Example("""
129+
func outer() {
130+
var value = 10
131+
do {
132+
let ↓value = 20
133+
print(value)
134+
}
135+
}
136+
"""),
137+
Example("""
138+
var globalName = "global"
139+
func test() {
140+
for item in [1, 2, 3] {
141+
var ↓globalName = "local"
142+
print(globalName)
143+
}
144+
}
145+
"""),
68146
]
69147
)
70148
}

0 commit comments

Comments
 (0)