Open 72A12F4E opened 5 years ago
Here is a regex based rule that I implemented to identify these issues. I hope it helps!
custom_rules:
legacy_objc_type:
included: ".*.swift"
name: "Legacy Obj-C Type"
regex: "NSAffineTransform|NSArray|NSCalendar|NSCharacterSet|NSData|NSDateComponents|NSDateInterval|NSDate|NSDecimalNumber|NSDictionary|NSIndexPath|NSIndexSet|NSLocale|NSMeasurement|NSNotification|NSNumber|NSPersonNameComponents|NSSet|NSString|NSTimeZone|NSURL|NSURLComponents|NSURLQueryItem|NSURLRequest|NSUUID"
message: "Avoid using Obj-C types when Swift types will suffice."
severity: warning
match_kinds:
- typeidentifier
New Issue Checklist
New rule request
Please describe the rule idea, format this issue's title as
Rule Request: [Rule Name]
and describe:This would prevent developers from using legacy NS types where swift versions of those types already exist. Apple outlines guidance on which types get bridged here:
https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/working_with_foundation_types
Bad
All of the below types have a Swift analogue and should not be used in Swift code
Ok
These types do not have a Swift analogue, so they should be allowed.
Unsure
I think this rule should be opt-in. There is a lot of potential for flagging types that should be completely valid in normal Swift code, and in codebases where very particular Swift-ObjC is required.