File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed
Sources/SwiftFormatPrettyPrint
Tests/SwiftFormatPrettyPrintTests Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -211,7 +211,7 @@ public class PrettyPrinter {
211
211
numberToPrint = consecutiveNewlineCount == 0 ? 1 : 0
212
212
case . soft( let count, _) :
213
213
// We add 1 to the max blank lines because it takes 2 newlines to create the first blank line.
214
- numberToPrint = min ( count - consecutiveNewlineCount , configuration. maximumBlankLines + 1 )
214
+ numberToPrint = min ( count, configuration. maximumBlankLines + 1 ) - consecutiveNewlineCount
215
215
case . hard( let count) :
216
216
numberToPrint = count
217
217
}
Original file line number Diff line number Diff line change @@ -74,4 +74,60 @@ final class NewlineTests: PrettyPrintTestCase {
74
74
75
75
assertPrettyPrintEqual ( input: input, expected: expected, linelength: 45 )
76
76
}
77
+
78
+ func testNewlinesBetweenMembers( ) {
79
+ let input =
80
+ """
81
+
82
+
83
+ class MyClazz {
84
+
85
+ lazy var memberView: UIView = {
86
+ let view = UIView()
87
+ return view
88
+ }()
89
+
90
+
91
+ func doSomething() {
92
+ print( " ! " )
93
+ }
94
+
95
+
96
+ func doSomethingElse() {
97
+ print( " else! " )
98
+ }
99
+
100
+
101
+ let constMember = 1
102
+
103
+
104
+
105
+ }
106
+ """
107
+
108
+ let expected =
109
+ """
110
+ class MyClazz {
111
+
112
+ lazy var memberView: UIView = {
113
+ let view = UIView()
114
+ return view
115
+ }()
116
+
117
+ func doSomething() {
118
+ print( " ! " )
119
+ }
120
+
121
+ func doSomethingElse() {
122
+ print( " else! " )
123
+ }
124
+
125
+ let constMember = 1
126
+
127
+ }
128
+
129
+ """
130
+
131
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 100 )
132
+ }
77
133
}
You can’t perform that action at this time.
0 commit comments