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 {
41
41
// with a single condition whose body is just `continue`.
42
42
switch stmt. item. as ( SyntaxEnum . self) {
43
43
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 :
45
46
// Extract the condition of the IfStmt.
46
47
let conditionElement = ifStmt. conditions. first!
47
48
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 {
11
11
}
12
12
}
13
13
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
+
14
30
for i in [0, 1, 2, 3] {
15
31
if i > 30 {
16
32
print(i)
@@ -36,6 +52,22 @@ final class UseWhereClausesInForLoopsTests: LintOrFormatRuleTestCase {
36
52
print(i)
37
53
}
38
54
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
+
39
71
for i in [0, 1, 2, 3] {
40
72
if i > 30 {
41
73
print(i)
You can’t perform that action at this time.
0 commit comments