Skip to content

Commit 1851cda

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

File tree

3 files changed

+27
-39
lines changed

3 files changed

+27
-39
lines changed

pkg/golinters/whitespace/testdata/whitespace.go

+9-9
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"
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
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
48

5-
/*
6-
#include <stdio.h>
7-
#include <stdlib.h>
8-
9-
void myprint(char* s) {
10-
printf("%d\n", s);
11-
}
12-
*/
13-
import "C"
14-
15-
import (
16-
"fmt"
17-
"strings"
18-
"unsafe"
19-
)
20-
21-
func _() {
22-
cs := C.CString("Hello from stdio\n")
23-
C.myprint(cs)
24-
C.free(unsafe.Pointer(cs))
25-
}
9+
import "fmt"
2610

27-
func oneLeadingNewline() {
11+
func oneLeadingNewline() { // want "unnecessary leading newline"
2812

2913
fmt.Println("Hello world")
3014
}
3115

32-
func oneNewlineAtBothEnds() {
16+
func oneNewlineAtBothEnds() { // want "unnecessary leading newline"
3317

3418
fmt.Println("Hello world")
3519

36-
}
20+
} // want "unnecessary trailing newline"
3721

3822
func noNewlineFunc() {
3923
}
@@ -61,36 +45,36 @@ func oneLeadingNewlineWithCommentFunc() {
6145
// some comment
6246
}
6347

64-
func twoLeadingNewlines() {
48+
func twoLeadingNewlines() { // want "unnecessary leading newline"
6549

6650

6751
fmt.Println("Hello world")
6852
}
6953

7054
func multiFuncFunc(a int,
71-
b int) {
55+
b int) { // want "multi-line statement should be followed by a newline"
7256
fmt.Println("Hello world")
7357
}
7458

7559
func multiIfFunc() {
7660
if 1 == 1 &&
77-
2 == 2 {
61+
2 == 2 { // want "multi-line statement should be followed by a newline"
7862
fmt.Println("Hello multi-line world")
7963
}
8064

8165
if true {
8266
if true {
8367
if true {
8468
if 1 == 1 &&
85-
2 == 2 {
69+
2 == 2 { // want "multi-line statement should be followed by a newline"
8670
fmt.Println("Hello nested multi-line world")
8771
}
8872
}
8973
}
9074
}
9175
}
9276

93-
func notGoFmted() {
77+
func notGoFmted() { // want "unnecessary leading newline"
9478

9579

9680

@@ -99,4 +83,4 @@ func notGoFmted() {
9983

10084

10185

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

pkg/golinters/whitespace/whitespace_integration_test.go

+4
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)