Skip to content

Commit ca51724

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

File tree

3 files changed

+26
-39
lines changed

3 files changed

+26
-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,22 @@
1+
//go:build ignore
2+
3+
// TODO(ldez) the linter doesn't support cgo.
14
//golangcitest:args -Ewhitespace
25
//golangcitest:config_path testdata/whitespace.yml
36
package testdata
47

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-
}
8+
import "fmt"
269

27-
func oneLeadingNewline() {
10+
func oneLeadingNewline() { // want "unnecessary leading newline"
2811

2912
fmt.Println("Hello world")
3013
}
3114

32-
func oneNewlineAtBothEnds() {
15+
func oneNewlineAtBothEnds() { // want "unnecessary leading newline"
3316

3417
fmt.Println("Hello world")
3518

36-
}
19+
} // want "unnecessary trailing newline"
3720

3821
func noNewlineFunc() {
3922
}
@@ -61,36 +44,36 @@ func oneLeadingNewlineWithCommentFunc() {
6144
// some comment
6245
}
6346

64-
func twoLeadingNewlines() {
47+
func twoLeadingNewlines() { // want "unnecessary leading newline"
6548

6649

6750
fmt.Println("Hello world")
6851
}
6952

7053
func multiFuncFunc(a int,
71-
b int) {
54+
b int) { // want "multi-line statement should be followed by a newline"
7255
fmt.Println("Hello world")
7356
}
7457

7558
func multiIfFunc() {
7659
if 1 == 1 &&
77-
2 == 2 {
60+
2 == 2 { // want "multi-line statement should be followed by a newline"
7861
fmt.Println("Hello multi-line world")
7962
}
8063

8164
if true {
8265
if true {
8366
if true {
8467
if 1 == 1 &&
85-
2 == 2 {
68+
2 == 2 { // want "multi-line statement should be followed by a newline"
8669
fmt.Println("Hello nested multi-line world")
8770
}
8871
}
8972
}
9073
}
9174
}
9275

93-
func notGoFmted() {
76+
func notGoFmted() { // want "unnecessary leading newline"
9477

9578

9679

@@ -99,4 +82,4 @@ func notGoFmted() {
9982

10083

10184

102-
}
85+
} // 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)