Motivation
Opt-in redundant_type_annotation flags cases where the type name is restated on the RHS, e.g.:
var url: URL = URL()
let alphanumerics: CharacterSet = CharacterSet.alphanumerics
It does not flag an annotation that is redundant because the RHS is already a typed value/property of that type:
enum Metrics {
static let avatarLabelSpacing: Double = 6
}
struct AvatarLabelStyle {
var spacing: Double = Metrics.avatarLabelSpacing // annotation is unnecessary
}
Verified with SwiftLint 0.65.0 (only_rules: [redundant_type_annotation]): zero violations for the example above. consider_default_literal_types_redundant only adds literal cases like : Double = 6, not property references.
Feature request
Please extend redundant_type_annotation so it also treats an explicit type as redundant when the RHS expression’s type is unambiguously the same as the annotation—at least for simple cases like a reference to a static let / let / var of that type.
Example desired violation / correction:
- var spacing: Double = Metrics.avatarLabelSpacing
+ var spacing = Metrics.avatarLabelSpacing
Happy to discuss scope (e.g. identifier / member-access RHS only; skip cases that would change overload resolution). Related discussion also opened for SwiftFormat’s propertyTypes / redundantType: nicklockwood/SwiftFormat#2752
Motivation
Opt-in
redundant_type_annotationflags cases where the type name is restated on the RHS, e.g.:It does not flag an annotation that is redundant because the RHS is already a typed value/property of that type:
Verified with SwiftLint 0.65.0 (
only_rules: [redundant_type_annotation]): zero violations for the example above.consider_default_literal_types_redundantonly adds literal cases like: Double = 6, not property references.Feature request
Please extend
redundant_type_annotationso it also treats an explicit type as redundant when the RHS expression’s type is unambiguously the same as the annotation—at least for simple cases like a reference to astatic let/let/varof that type.Example desired violation / correction:
Happy to discuss scope (e.g. identifier / member-access RHS only; skip cases that would change overload resolution). Related discussion also opened for SwiftFormat’s
propertyTypes/redundantType: nicklockwood/SwiftFormat#2752