Skip to content

Commit 6bd3a55

Browse files
committed
Remove the hardcoded suppressRules list in generate-pipeline.
Now that we have the `isOptIn` property for rules, this should be used to disable rules by default instead of removing them from pipeline generation entirely. This also unblocks #261, since excluded rules wouldn't show up in the generated name cache, causing their tests to crash.
1 parent e3a4b21 commit 6bd3a55

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

Sources/SwiftFormat/Pipelines+Generated.swift

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class LintPipeline: SyntaxVisitor {
6363
override func visit(_ node: CodeBlockItemListSyntax) -> SyntaxVisitorContinueKind {
6464
visitIfEnabled(DoNotUseSemicolons.visit, for: node)
6565
visitIfEnabled(OneVariableDeclarationPerLine.visit, for: node)
66+
visitIfEnabled(UseEarlyExits.visit, for: node)
6667
return .visitChildren
6768
}
6869

@@ -106,6 +107,11 @@ class LintPipeline: SyntaxVisitor {
106107
return .visitChildren
107108
}
108109

110+
override func visit(_ node: ForInStmtSyntax) -> SyntaxVisitorContinueKind {
111+
visitIfEnabled(UseWhereClausesInForLoops.visit, for: node)
112+
return .visitChildren
113+
}
114+
109115
override func visit(_ node: ForcedValueExprSyntax) -> SyntaxVisitorContinueKind {
110116
visitIfEnabled(NeverForceUnwrap.visit, for: node)
111117
return .visitChildren
@@ -314,9 +320,11 @@ extension FormatPipeline {
314320
node = OneVariableDeclarationPerLine(context: context).visit(node)
315321
node = OrderedImports(context: context).visit(node)
316322
node = ReturnVoidInsteadOfEmptyTuple(context: context).visit(node)
323+
node = UseEarlyExits(context: context).visit(node)
317324
node = UseShorthandTypeNames(context: context).visit(node)
318325
node = UseSingleLinePropertyGetter(context: context).visit(node)
319326
node = UseTripleSlashForDocumentationComments(context: context).visit(node)
327+
node = UseWhereClausesInForLoops(context: context).visit(node)
320328
return node
321329
}
322330
}

Sources/SwiftFormatConfiguration/RuleRegistry+Generated.swift

+2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ enum RuleRegistry {
4040
"OnlyOneTrailingClosureArgument": true,
4141
"OrderedImports": true,
4242
"ReturnVoidInsteadOfEmptyTuple": true,
43+
"UseEarlyExits": false,
4344
"UseLetInEveryBoundCaseVariable": true,
4445
"UseShorthandTypeNames": true,
4546
"UseSingleLinePropertyGetter": true,
4647
"UseSynthesizedInitializer": true,
4748
"UseTripleSlashForDocumentationComments": true,
49+
"UseWhereClausesInForLoops": false,
4850
"ValidateDocumentationComments": false,
4951
]
5052
}

Sources/SwiftFormatRules/UseEarlyExits.swift

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ import SwiftSyntax
4444
/// equivalent `guard ... else { return/throw/break/continue }` constructs.
4545
public final class UseEarlyExits: SyntaxFormatRule {
4646

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+
4751
public override func visit(_ node: CodeBlockItemListSyntax) -> Syntax {
4852
// Continue recursing down the tree first, so that any nested/child nodes get transformed first.
4953
let nodeAfterTransformingChildren = super.visit(node)

Sources/SwiftFormatRules/UseWhereClausesInForLoops.swift

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import SwiftSyntax
2121
/// statement factored out to a `where` clause.
2222
public final class UseWhereClausesInForLoops: SyntaxFormatRule {
2323

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+
2428
public override func visit(_ node: ForInStmtSyntax) -> StmtSyntax {
2529
// Extract IfStmt node if it's the only node in the function's body.
2630
guard !node.body.statements.isEmpty else { return StmtSyntax(node) }

Sources/generate-pipeline/RuleCollector.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import Foundation
1414
import SwiftFormatCore
1515
import SwiftSyntax
1616

17-
// These rules will not be added to the pipeline.
18-
let suppressRules = ["UseEarlyExits", "UseWhereClausesInForLoops"]
19-
2017
/// Collects information about rules in the formatter code base.
2118
final class RuleCollector {
2219
/// Information about a detected rule.
@@ -99,8 +96,8 @@ final class RuleCollector {
9996
return nil
10097
}
10198

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 {
104101
return nil
105102
}
106103

0 commit comments

Comments
 (0)