File tree 5 files changed +20
-5
lines changed
5 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ class LintPipeline: SyntaxVisitor {
63
63
override func visit( _ node: CodeBlockItemListSyntax ) -> SyntaxVisitorContinueKind {
64
64
visitIfEnabled ( DoNotUseSemicolons . visit, for: node)
65
65
visitIfEnabled ( OneVariableDeclarationPerLine . visit, for: node)
66
+ visitIfEnabled ( UseEarlyExits . visit, for: node)
66
67
return . visitChildren
67
68
}
68
69
@@ -106,6 +107,11 @@ class LintPipeline: SyntaxVisitor {
106
107
return . visitChildren
107
108
}
108
109
110
+ override func visit( _ node: ForInStmtSyntax ) -> SyntaxVisitorContinueKind {
111
+ visitIfEnabled ( UseWhereClausesInForLoops . visit, for: node)
112
+ return . visitChildren
113
+ }
114
+
109
115
override func visit( _ node: ForcedValueExprSyntax ) -> SyntaxVisitorContinueKind {
110
116
visitIfEnabled ( NeverForceUnwrap . visit, for: node)
111
117
return . visitChildren
@@ -314,9 +320,11 @@ extension FormatPipeline {
314
320
node = OneVariableDeclarationPerLine ( context: context) . visit ( node)
315
321
node = OrderedImports ( context: context) . visit ( node)
316
322
node = ReturnVoidInsteadOfEmptyTuple ( context: context) . visit ( node)
323
+ node = UseEarlyExits ( context: context) . visit ( node)
317
324
node = UseShorthandTypeNames ( context: context) . visit ( node)
318
325
node = UseSingleLinePropertyGetter ( context: context) . visit ( node)
319
326
node = UseTripleSlashForDocumentationComments ( context: context) . visit ( node)
327
+ node = UseWhereClausesInForLoops ( context: context) . visit ( node)
320
328
return node
321
329
}
322
330
}
Original file line number Diff line number Diff line change @@ -40,11 +40,13 @@ enum RuleRegistry {
40
40
" OnlyOneTrailingClosureArgument " : true ,
41
41
" OrderedImports " : true ,
42
42
" ReturnVoidInsteadOfEmptyTuple " : true ,
43
+ " UseEarlyExits " : false ,
43
44
" UseLetInEveryBoundCaseVariable " : true ,
44
45
" UseShorthandTypeNames " : true ,
45
46
" UseSingleLinePropertyGetter " : true ,
46
47
" UseSynthesizedInitializer " : true ,
47
48
" UseTripleSlashForDocumentationComments " : true ,
49
+ " UseWhereClausesInForLoops " : false ,
48
50
" ValidateDocumentationComments " : false ,
49
51
]
50
52
}
Original file line number Diff line number Diff line change @@ -44,6 +44,10 @@ import SwiftSyntax
44
44
/// equivalent `guard ... else { return/throw/break/continue }` constructs.
45
45
public final class UseEarlyExits : SyntaxFormatRule {
46
46
47
+ /// Identifies this rule as being opt-in. This rule is experimental and not yet stable enough to
48
+ /// be enabled by default.
49
+ public override class var isOptIn : Bool { return true }
50
+
47
51
public override func visit( _ node: CodeBlockItemListSyntax ) -> Syntax {
48
52
// Continue recursing down the tree first, so that any nested/child nodes get transformed first.
49
53
let nodeAfterTransformingChildren = super. visit ( node)
Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ import SwiftSyntax
21
21
/// statement factored out to a `where` clause.
22
22
public final class UseWhereClausesInForLoops : SyntaxFormatRule {
23
23
24
+ /// Identifies this rule as being opt-in. This rule is experimental and not yet stable enough to
25
+ /// be enabled by default.
26
+ public override class var isOptIn : Bool { return true }
27
+
24
28
public override func visit( _ node: ForInStmtSyntax ) -> StmtSyntax {
25
29
// Extract IfStmt node if it's the only node in the function's body.
26
30
guard !node. body. statements. isEmpty else { return StmtSyntax ( node) }
Original file line number Diff line number Diff line change @@ -14,9 +14,6 @@ import Foundation
14
14
import SwiftFormatCore
15
15
import SwiftSyntax
16
16
17
- // These rules will not be added to the pipeline.
18
- let suppressRules = [ " UseEarlyExits " , " UseWhereClausesInForLoops " ]
19
-
20
17
/// Collects information about rules in the formatter code base.
21
18
final class RuleCollector {
22
19
/// Information about a detected rule.
@@ -99,8 +96,8 @@ final class RuleCollector {
99
96
return nil
100
97
}
101
98
102
- // Make sure the rule isn't suppressed, and it must have an inheritance clause.
103
- guard !suppressRules . contains ( typeName ) , let inheritanceClause = maybeInheritanceClause else {
99
+ // Make sure it has an inheritance clause.
100
+ guard let inheritanceClause = maybeInheritanceClause else {
104
101
return nil
105
102
}
106
103
You can’t perform that action at this time.
0 commit comments