Skip to content

Commit f3595ed

Browse files
authored
remove newlines immediately after an assignment operator
Fixes #76.
1 parent 4d8e76d commit f3595ed

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@ The added formatting rules are in the `format` package.
1515

1616
### Added rules
1717

18+
No empty lines following an assignment operator
19+
20+
<details><summary><i>example</i></summary>
21+
22+
```
23+
func foo() {
24+
foo :=
25+
"bar"
26+
}
27+
```
28+
29+
```
30+
func foo() {
31+
foo := "bar"
32+
}
33+
```
34+
35+
</details>
36+
1837
No empty lines at the beginning or end of a function
1938

2039
<details><summary><i>example</i></summary>

format/format.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,10 @@ func (f *fumpter) applyPre(c *astutil.Cursor) {
599599
c.Replace(node)
600600
}
601601
}
602+
603+
case *ast.AssignStmt:
604+
// Only remove lines between the assignment token and the first right-hand side expression
605+
f.removeLines(f.Line(node.TokPos), f.Line(node.Rhs[0].Pos()))
602606
}
603607
}
604608

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
gofumpt -w foo.go
2+
cmp foo.go foo.go.golden
3+
4+
gofumpt -d foo.go.golden
5+
! stdout .
6+
7+
-- foo.go --
8+
package p
9+
10+
func f() {
11+
foo :=
12+
13+
14+
"bar"
15+
16+
foo :=
17+
"bar"
18+
19+
_, _ =
20+
0,
21+
1
22+
23+
_, _ = 0,
24+
1
25+
26+
_ =
27+
`
28+
foo
29+
`
30+
31+
_ = /* inline */
32+
"foo"
33+
34+
_ = // inline
35+
"foo"
36+
}
37+
38+
-- foo.go.golden --
39+
package p
40+
41+
func f() {
42+
foo := "bar"
43+
44+
foo := "bar"
45+
46+
_, _ = 0,
47+
1
48+
49+
_, _ = 0,
50+
1
51+
52+
_ = `
53+
foo
54+
`
55+
56+
_ = /* inline */ "foo"
57+
58+
_ = // inline
59+
"foo"
60+
}

0 commit comments

Comments
 (0)