You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Variable shadowing is an anti-pattern because it makes code harder to understand. It is a compiler error in many languages. I think it would be great to warn against it in SwiftLint. Here is an example:
var b: String? = "thank"
test(a:"you")
func test(a: String?) {
if let b = a {
print("b:\(b)")
let b = "wow"
print("b:\(b)")
}
}
The line if let b = a { shadows the above variable b
The line let b = "wow" redeclares b as a new variable
In my opinion both of these should be covered by SwiftLint.
Reacted by Aidan Waite, Danny Mösch, Graham Burgsma and scottmarchant
Activity