Silence superfluous_else rule for availability conditions (#5857)

This commit is contained in:
Danny Mösch
2024-11-16 22:54:59 +01:00
committed by GitHub
parent 707a63daf0
commit cafed078fa
2 changed files with 15 additions and 4 deletions
+5
View File
@@ -40,6 +40,11 @@
[SimplyDanny](https://github.com/SimplyDanny)
[#5787](https://github.com/realm/SwiftLint/issues/5787)
* Silence `superfluous_else` rule on `if` expressions with only a single
availability condition.
[SimplyDanny](https://github.com/SimplyDanny)
[#5833](https://github.com/realm/SwiftLint/issues/5833)
* Stop triggering the `control_statement` rule on closures being directly
called as conditions.
[SimplyDanny](https://github.com/SimplyDanny)
@@ -69,6 +69,13 @@ struct SuperfluousElseRule: OptInRule {
}
}
"""),
Example("""
if #available(iOS 13, *) {
return
} else {
deprecatedFunction()
}
"""),
],
triggeringExamples: [
Example("""
@@ -324,10 +331,9 @@ private extension SuperfluousElseRule {
private extension IfExprSyntax {
var superfluousElse: TokenSyntax? {
if elseKeyword == nil {
return nil
}
if !lastStatementExitsScope(in: body) {
guard elseKeyword != nil,
conditions.onlyElement?.condition.is(AvailabilityConditionSyntax.self) != true,
lastStatementExitsScope(in: body) else {
return nil
}
if let parent = parent?.as(IfExprSyntax.self) {