Skip to content

Commit f4b2e7a

Browse files
committed
tests: add missing whitespace tests
1 parent 3763e1a commit f4b2e7a

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

pkg/golinters/whitespace/testdata/whitespace.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ package testdata
44

55
import "fmt"
66

7-
func oneLeadingNewline() {
7+
func oneLeadingNewline() { // want "unnecessary leading newline"
88

99
fmt.Println("Hello world")
1010
}
1111

12-
func oneNewlineAtBothEnds() {
12+
func oneNewlineAtBothEnds() { // want "unnecessary leading newline"
1313

1414
fmt.Println("Hello world")
1515

16-
}
16+
} // want "unnecessary trailing newline"
1717

1818
func noNewlineFunc() {
1919
}
@@ -41,36 +41,36 @@ func oneLeadingNewlineWithCommentFunc() {
4141
// some comment
4242
}
4343

44-
func twoLeadingNewlines() {
44+
func twoLeadingNewlines() { // want "unnecessary leading newline"
4545

4646

4747
fmt.Println("Hello world")
4848
}
4949

5050
func multiFuncFunc(a int,
51-
b int) {
51+
b int) { // want "multi-line statement should be followed by a newline"
5252
fmt.Println("Hello world")
5353
}
5454

5555
func multiIfFunc() {
5656
if 1 == 1 &&
57-
2 == 2 {
57+
2 == 2 { // want "multi-line statement should be followed by a newline"
5858
fmt.Println("Hello multi-line world")
5959
}
6060

6161
if true {
6262
if true {
6363
if true {
6464
if 1 == 1 &&
65-
2 == 2 {
65+
2 == 2 { // want "multi-line statement should be followed by a newline"
6666
fmt.Println("Hello nested multi-line world")
6767
}
6868
}
6969
}
7070
}
7171
}
7272

73-
func notGoFmted() {
73+
func notGoFmted() { // want "unnecessary leading newline"
7474

7575

7676

@@ -79,4 +79,4 @@ func notGoFmted() {
7979

8080

8181

82-
}
82+
} // want "unnecessary trailing newline"

pkg/golinters/whitespace/testdata/whitespace_cgo.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//go:build ignore
2+
3+
// TODO(ldez) the linter doesn't support cgo.
4+
15
//golangcitest:args -Ewhitespace
26
//golangcitest:config_path testdata/whitespace.yml
37
package testdata
@@ -14,7 +18,6 @@ import "C"
1418

1519
import (
1620
"fmt"
17-
"strings"
1821
"unsafe"
1922
)
2023

@@ -24,16 +27,16 @@ func _() {
2427
C.free(unsafe.Pointer(cs))
2528
}
2629

27-
func oneLeadingNewline() {
30+
func oneLeadingNewline() { // want "unnecessary leading newline"
2831

2932
fmt.Println("Hello world")
3033
}
3134

32-
func oneNewlineAtBothEnds() {
35+
func oneNewlineAtBothEnds() { // want "unnecessary leading newline"
3336

3437
fmt.Println("Hello world")
3538

36-
}
39+
} // want "unnecessary trailing newline"
3740

3841
func noNewlineFunc() {
3942
}
@@ -61,36 +64,36 @@ func oneLeadingNewlineWithCommentFunc() {
6164
// some comment
6265
}
6366

64-
func twoLeadingNewlines() {
67+
func twoLeadingNewlines() { // want "unnecessary leading newline"
6568

6669

6770
fmt.Println("Hello world")
6871
}
6972

7073
func multiFuncFunc(a int,
71-
b int) {
74+
b int) { // want "multi-line statement should be followed by a newline"
7275
fmt.Println("Hello world")
7376
}
7477

7578
func multiIfFunc() {
7679
if 1 == 1 &&
77-
2 == 2 {
80+
2 == 2 { // want "multi-line statement should be followed by a newline"
7881
fmt.Println("Hello multi-line world")
7982
}
8083

8184
if true {
8285
if true {
8386
if true {
8487
if 1 == 1 &&
85-
2 == 2 {
88+
2 == 2 { // want "multi-line statement should be followed by a newline"
8689
fmt.Println("Hello nested multi-line world")
8790
}
8891
}
8992
}
9093
}
9194
}
9295

93-
func notGoFmted() {
96+
func notGoFmted() { // want "unnecessary leading newline"
9497

9598

9699

@@ -99,4 +102,4 @@ func notGoFmted() {
99102

100103

101104

102-
}
105+
} // want "unnecessary trailing newline"

pkg/golinters/whitespace/whitespace_integration_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
"github.com/golangci/golangci-lint/test/testshared/integration"
77
)
88

9+
func TestFromTestdata(t *testing.T) {
10+
integration.RunTestdata(t)
11+
}
12+
913
func TestFix(t *testing.T) {
1014
integration.RunFix(t)
1115
}

0 commit comments

Comments
 (0)