File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
Tests/SwiftFormatRulesTests Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,8 @@ public final class UseWhereClausesInForLoops: SyntaxFormatRule {
4141 // with a single condition whose body is just `continue`.
4242 switch stmt. item. as ( SyntaxEnum . self) {
4343 case . ifStmt( let ifStmt)
44- where ifStmt. conditions. count == 1 && node. body. statements. count == 1 :
44+ where ifStmt. conditions. count == 1 && ifStmt. elseKeyword == nil
45+ && node. body. statements. count == 1 :
4546 // Extract the condition of the IfStmt.
4647 let conditionElement = ifStmt. conditions. first!
4748 guard let condition = conditionElement. condition. as ( ExprSyntax . self) else {
Original file line number Diff line number Diff line change @@ -11,6 +11,22 @@ final class UseWhereClausesInForLoopsTests: LintOrFormatRuleTestCase {
1111 }
1212 }
1313
14+ for i in [0, 1, 2, 3] {
15+ if i > 30 {
16+ print(i)
17+ } else {
18+ print(i)
19+ }
20+ }
21+
22+ for i in [0, 1, 2, 3] {
23+ if i > 30 {
24+ print(i)
25+ } else if i > 40 {
26+ print(i)
27+ }
28+ }
29+
1430 for i in [0, 1, 2, 3] {
1531 if i > 30 {
1632 print(i)
@@ -36,6 +52,22 @@ final class UseWhereClausesInForLoopsTests: LintOrFormatRuleTestCase {
3652 print(i)
3753 }
3854
55+ for i in [0, 1, 2, 3] {
56+ if i > 30 {
57+ print(i)
58+ } else {
59+ print(i)
60+ }
61+ }
62+
63+ for i in [0, 1, 2, 3] {
64+ if i > 30 {
65+ print(i)
66+ } else if i > 40 {
67+ print(i)
68+ }
69+ }
70+
3971 for i in [0, 1, 2, 3] {
4072 if i > 30 {
4173 print(i)
You can’t perform that action at this time.
0 commit comments