Redundant Type Annotation
Variables should not have redundant type annotation
- Identifier: redundant_type_annotation
- Enabled by default: No
- Supports autocorrection: Yes
- Kind: idiomatic
- Analyzer rule: No
- Minimum Swift compiler version: 5.0.0
- Default configuration:
Key Value severity warning
Non Triggering Examples
var url = URL()
var url: CustomStringConvertible = URL()
@IBInspectable var color: UIColor = UIColor.white
enum Direction {
case up
case down
}
var direction: Direction = .up
enum Direction {
case up
case down
}
var direction = Direction.up
Triggering Examples
var url↓:URL=URL()
var url↓:URL = URL(string: "")
var url↓: URL = URL()
let url↓: URL = URL()
lazy var url↓: URL = URL()
let alphanumerics↓: CharacterSet = CharacterSet.alphanumerics
class ViewController: UIViewController {
func someMethod() {
let myVar↓: Int = Int(5)
}
}
var isEnabled↓: Bool = true
enum Direction {
case up
case down
}
var direction↓: Direction = Direction.up