-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
syntactic_sugar flags var declarations that can't be fixed #928
Comments
I agree we should handle this, but I'm curious on why not just using |
I was going to say that |
I don't know how we would catch this case vs using a valid static function. Should we loose the rule and just skip if there's a dot after the type? In this case we would have a false positive. We'd just need to add a negative lookahead in the regex: For example: func defaultStringArray(_ object: Any?) -> [String] {
// wouldn't trigger, but it should
return Array<String>.array(of: object) ?? []
} Another option would be check if it's a var declaration/parameter, but this wouldn't prevent this issue in return types, for example: // would trigger
func x(a: [Int], b: Int) -> Array<Int>.Index {
// ..
} However, this last case can be ignored if there's an arrow before the type. Am I missing any other cases/options? |
I think there's a way to further refine the rule to avoid false positives based on the |
I have this line:
because I want a variable of the same type as the index of an array of
OnboardingPage
s. However, if I change it to[OnboardingPage].Index?
, I get this from Xcode:I suppose this should also be considered a Swift bug, but SwiftLint shouldn't report issues that can't be fixed. For now, I'll use
// swiftlint:disable:next syntactic_sugar
The text was updated successfully, but these errors were encountered: