mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
Silence superfluous_else rule for availability conditions (#5857)
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user