Skip to content

Commit 711a4ba

Browse files
committed
Remove BlankLineBetweenMembers rule because it creates non-idempotent behavior.
The rule is unfortunately based on the trivia before the pretty printing pass, which means it decides single-line-ness based on the input which may be incorrect. The single-line-ness must be based on the source *after* pretty printing, so it cannot be accomplished in a phase 1 rule. Even linting in a phase 1 rule is too inaccurate, because it may flag false positives and false negatives creating useless noise. In the future, the blank line between members requirement can be better implemented using breaks in the pretty printer.
1 parent e0a13b1 commit 711a4ba

File tree

8 files changed

+3
-566
lines changed

8 files changed

+3
-566
lines changed

Documentation/Configuration.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ top-level keys and values:
3838
line breaks where absolutely necessary and removing any others, effectively
3939
canonicalizing the output.
4040

41-
* `blankLineBetweenMembers` _(object)_: Controls logic specific to the
42-
enforcement of blank lines between type members. The object value of this
43-
property has the following properties:
44-
45-
* `ignoreSingleLineProperties` _(boolean)_: If `true`, then single-line
46-
property declarations are allowed to appear consecutively without a
47-
blank line separating them.
48-
4941
* `lineBreakBeforeControlFlowKeywords` _(boolean)_: Determines the
5042
line-breaking behavior for control flow keywords that follow a closing
5143
brace, like `else` and `catch`. If true, a line break will be added before
@@ -103,9 +95,6 @@ An example `.swift-format` configuration file is shown below.
10395
},
10496
"maximumBlankLines": 1,
10597
"respectsExistingLineBreaks": true,
106-
"blankLineBetweenMembers": {
107-
"ignoreSingleLineProperties": true
108-
},
10998
"lineBreakBeforeControlFlowKeywords": true,
11099
"lineBreakBeforeEachArgument": true
111100
}

Documentation/IgnoringSource.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ set of rules, add a comment of the form:
4444
`// swift-format-ignore: [comma delimited list of rule names]`.
4545

4646
```swift
47-
// swift-format-ignore: BlankLineBetweenMembers
47+
// swift-format-ignore: DoNotUseSemicolons
4848
struct Foo {
4949
var bar = true
5050
}
5151

52-
// swift-format-ignore: BlankLineBetweenMembers, FullyIndirectEnum, UseEarlyExits
52+
// swift-format-ignore: DoNotUseSemicolons, FullyIndirectEnum, UseEarlyExits
5353
func foo() {
5454
var bar = true
5555
}

Sources/SwiftFormat/Pipelines+Generated.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// This file is automatically generated with generate-pipeline. Do Not Edit!
1414

1515
import SwiftFormatCore
16-
import SwiftSyntax
1716
import SwiftFormatRules
17+
import SwiftSyntax
1818

1919
/// A syntax visitor that delegates to individual rules for linting.
2020
///
@@ -167,7 +167,6 @@ class LintPipeline: SyntaxVisitor {
167167

168168
override func visit(_ node: MemberDeclBlockSyntax) -> SyntaxVisitorContinueKind {
169169
visitIfEnabled(AmbiguousTrailingClosureOverload.visit, in: context, for: node)
170-
visitIfEnabled(BlankLineBetweenMembers.visit, in: context, for: node)
171170
return .visitChildren
172171
}
173172

@@ -286,7 +285,6 @@ extension FormatPipeline {
286285

287286
func visit(_ node: Syntax) -> Syntax {
288287
var node = node
289-
node = BlankLineBetweenMembers(context: context).visit(node)
290288
node = DoNotUseSemicolons(context: context).visit(node)
291289
node = FullyIndirectEnum(context: context).visit(node)
292290
node = GroupNumericLiterals(context: context).visit(node)

Sources/SwiftFormatConfiguration/Configuration.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public struct Configuration: Codable, Equatable {
2626
case tabWidth
2727
case indentation
2828
case respectsExistingLineBreaks
29-
case blankLineBetweenMembers
3029
case lineBreakBeforeControlFlowKeywords
3130
case lineBreakBeforeEachArgument
3231
case lineBreakBeforeEachGenericRequirement
@@ -72,9 +71,6 @@ public struct Configuration: Codable, Equatable {
7271

7372
/// MARK: Rule-specific configuration
7473

75-
/// Rules for limiting blank lines between members.
76-
public var blankLineBetweenMembers = BlankLineBetweenMembersConfiguration()
77-
7874
/// Determines the line-breaking behavior for control flow keywords that follow a closing brace,
7975
/// like `else` and `catch`.
8076
///
@@ -152,9 +148,6 @@ public struct Configuration: Codable, Equatable {
152148
= try container.decodeIfPresent(Indent.self, forKey: .indentation) ?? .spaces(2)
153149
self.respectsExistingLineBreaks
154150
= try container.decodeIfPresent(Bool.self, forKey: .respectsExistingLineBreaks) ?? true
155-
self.blankLineBetweenMembers = try container.decodeIfPresent(
156-
BlankLineBetweenMembersConfiguration.self, forKey: .blankLineBetweenMembers)
157-
?? BlankLineBetweenMembersConfiguration()
158151
self.lineBreakBeforeControlFlowKeywords
159152
= try container.decodeIfPresent(Bool.self, forKey: .lineBreakBeforeControlFlowKeywords) ?? false
160153
self.lineBreakBeforeEachArgument
@@ -186,7 +179,6 @@ public struct Configuration: Codable, Equatable {
186179
try container.encode(tabWidth, forKey: .tabWidth)
187180
try container.encode(indentation, forKey: .indentation)
188181
try container.encode(respectsExistingLineBreaks, forKey: .respectsExistingLineBreaks)
189-
try container.encode(blankLineBetweenMembers, forKey: .blankLineBetweenMembers)
190182
try container.encode(lineBreakBeforeControlFlowKeywords, forKey: .lineBreakBeforeControlFlowKeywords)
191183
try container.encode(lineBreakBeforeEachArgument, forKey: .lineBreakBeforeEachArgument)
192184
try container.encode(lineBreakBeforeEachGenericRequirement, forKey: .lineBreakBeforeEachGenericRequirement)
@@ -199,16 +191,6 @@ public struct Configuration: Codable, Equatable {
199191
}
200192
}
201193

202-
/// Configuration for the BlankLineBetweenMembers rule.
203-
public struct BlankLineBetweenMembersConfiguration: Codable, Equatable {
204-
/// If true, blank lines are not required between single-line properties.
205-
public let ignoreSingleLineProperties: Bool
206-
207-
public init(ignoreSingleLineProperties: Bool = true) {
208-
self.ignoreSingleLineProperties = ignoreSingleLineProperties
209-
}
210-
}
211-
212194
/// Configuration for the NoPlaygroundLiterals rule.
213195
public struct NoPlaygroundLiteralsConfiguration: Codable, Equatable {
214196
public enum ResolveBehavior: String, Codable {

Sources/SwiftFormatConfiguration/RuleRegistry+Generated.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ enum RuleRegistry {
1818
"AlwaysUseLowerCamelCase": true,
1919
"AmbiguousTrailingClosureOverload": true,
2020
"BeginDocumentationCommentWithOneLineSummary": true,
21-
"BlankLineBetweenMembers": true,
2221
"DoNotUseSemicolons": true,
2322
"DontRepeatTypeInStaticProperties": true,
2423
"FullyIndirectEnum": true,

Sources/SwiftFormatRules/BlankLineBetweenMembers.swift

Lines changed: 0 additions & 149 deletions
This file was deleted.

0 commit comments

Comments
 (0)