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
I'd really like to see this, I've provided another example below which covers:
Where you are assigning to self
When you call a method that returns Never e.g. fatalError
When you throw an error
import Foundation
enumSupportedFruit{case lemon
case lime
case orange
}enumSupportFruitError:Error{case didYouMean(String)}// NON-TRIGGERINGextensionSupportedFruit{init(rawValue:String)throws{self= switch rawValue {case"🍋":.lemon
case"🍋🟩":.lime
case"🍊":throwSupportFruitError.didYouMean("to use an orange emoji instead of tangerine emoji")default:fatalError()}}}// TRIGGERINGextensionSupportedFruit{init(rawValue:String)throws{
switch rawValue {case"🍋":self=.lemon
case"🍋🟩":self=.lime
case"🍊":throwSupportFruitError.didYouMean("to use an orange emoji instead of tangerine emoji")default:fatalError()}}}
@AballahNsour I see you have a branch on your fork for starting the implementation of this rule, let me know if I can do anything to help out. My Swift Syntax skills are pretty lacking though 😢.
In version 5.9, Swift got support for
if
andswitch
expressions. A rule to enforce them where allowed should be possible.In the first implementation, the rule does not need to be configurable. It should be opt-in and might support automatic rewriting.
Triggering:
Non-triggering:
The text was updated successfully, but these errors were encountered: