File tree 3 files changed +82
-13
lines changed 3 files changed +82
-13
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ No empty lines at the beginning or end of a function
40
40
41
41
```
42
42
func foo() {
43
+
43
44
println("bar")
44
45
45
46
}
@@ -53,6 +54,28 @@ func foo() {
53
54
54
55
</details >
55
56
57
+ Functions using an empty line for readability should use a ` ) { ` line instead
58
+
59
+ <details ><summary ><i >example</i ></summary >
60
+
61
+ ```
62
+ func foo(s string,
63
+ i int) {
64
+
65
+ println("bar")
66
+ }
67
+ ```
68
+
69
+ ```
70
+ func foo(s string,
71
+ i int,
72
+ ) {
73
+ println("bar")
74
+ }
75
+ ```
76
+
77
+ </details >
78
+
56
79
No empty lines around a lone statement (or comment) in a block
57
80
58
81
<details ><summary ><i >example</i ></summary >
Original file line number Diff line number Diff line change @@ -542,12 +542,22 @@ func (f *fumpter) applyPre(c *astutil.Cursor) {
542
542
f .Position (sign .Results .Closing ).Column == 1 &&
543
543
f .Line (sign .Results .Closing ) == endLine
544
544
545
- if f .Line (sign .Pos ()) != endLine &&
546
- // param/result closing is not the 1st char of the left bracket line
547
- ! (paramClosingIsFirstCharOnEndLine || resultClosingIsFirstCharOnEndLine ) {
545
+ endLineIsIndented := ! (paramClosingIsFirstCharOnEndLine || resultClosingIsFirstCharOnEndLine )
546
+
547
+ if f .Line (sign .Pos ()) != endLine && endLineIsIndented {
548
+ // is there an empty line?
549
+ isThereAnEmptyLine := endLine + 1 != f .Line (bodyPos )
550
+
548
551
// The body is preceded by a multi-line function
549
- // signature, and the empty line helps readability.
550
- return
552
+ // signature, we move the `) {` to avoid the empty line.
553
+ switch {
554
+ case isThereAnEmptyLine && sign .Results != nil && ! resultClosingIsFirstCharOnEndLine :
555
+ sign .Results .Closing += 1
556
+ f .addNewline (sign .Results .Closing )
557
+ case isThereAnEmptyLine && sign .Params != nil && ! paramClosingIsFirstCharOnEndLine :
558
+ sign .Params .Closing += 1
559
+ f .addNewline (sign .Params .Closing )
560
+ }
551
561
}
552
562
}
553
563
Original file line number Diff line number Diff line change @@ -230,6 +230,25 @@ func f2(
230
230
231
231
return "", nil
232
232
}
233
+
234
+ func multilineResultsMultipleEmptyLines() (p1 string,
235
+ p2 string) {
236
+
237
+
238
+ println("body")
239
+
240
+ }
241
+
242
+ func multilineParamsWithoutEmptyLine(p1 string,
243
+ p2 string) {
244
+ println("body")
245
+ }
246
+
247
+ func multilineParamsWithoutEmptyLineWithComment(p1 string,
248
+ p2 string) {
249
+ // comment
250
+ println("body")
251
+ }
233
252
-- foo.go.golden --
234
253
package p
235
254
@@ -253,8 +272,8 @@ func _() {
253
272
}
254
273
255
274
func multilineParams(p1 string,
256
- p2 string) {
257
-
275
+ p2 string,
276
+ ) {
258
277
println("body")
259
278
}
260
279
@@ -380,8 +399,8 @@ func multilineParamsOneParamReturningMultiLineValues(
380
399
}
381
400
382
401
func multilineResults() (p1 string,
383
- p2 string) {
384
-
402
+ p2 string,
403
+ ) {
385
404
println("body")
386
405
}
387
406
@@ -398,8 +417,8 @@ func multilineNoFields() {
398
417
func f(
399
418
foo int,
400
419
bar string,
401
- /* baz */) {
402
-
420
+ /* baz */
421
+ ) {
403
422
body()
404
423
}
405
424
@@ -409,7 +428,24 @@ func f2(
409
428
) (
410
429
string,
411
430
error,
412
- /* baz */) {
413
-
431
+ /* baz */
432
+ ) {
414
433
return "", nil
415
434
}
435
+
436
+ func multilineResultsMultipleEmptyLines() (p1 string,
437
+ p2 string,
438
+ ) {
439
+ println("body")
440
+ }
441
+
442
+ func multilineParamsWithoutEmptyLine(p1 string,
443
+ p2 string) {
444
+ println("body")
445
+ }
446
+
447
+ func multilineParamsWithoutEmptyLineWithComment(p1 string,
448
+ p2 string) {
449
+ // comment
450
+ println("body")
451
+ }
You can’t perform that action at this time.
0 commit comments