File tree Expand file tree Collapse file tree 5 files changed +259
-0
lines changed
pkg/golinters/wsl/testdata Expand file tree Collapse file tree 5 files changed +259
-0
lines changed Original file line number Diff line number Diff line change 1+ //golangcitest:args -Ewsl_v5
2+ //golangcitest:expected_exitcode 0
3+ package testdata
4+
5+ import (
6+ "bytes"
7+ "encoding/json"
8+ )
9+
10+ type T struct {
11+ I int
12+ }
13+
14+ func NewT () * T {
15+ return & T {}
16+ }
17+
18+ func (* T ) Fn () int {
19+ return 1
20+ }
21+
22+ func FnC (_ string , fn func () error ) error {
23+ fn ()
24+ return nil
25+ }
26+
27+ func strictAppend () {
28+ s := []string {}
29+ s = append (s , "a" )
30+ s = append (s , "b" )
31+ x := "c"
32+ s = append (s , x )
33+ y := "e"
34+ s = append (s , "d" ) // want `missing whitespace above this line \(no shared variables above append\)`
35+ s = append (s , y )
36+ }
37+
38+ func incDec () {
39+ x := 1
40+ x ++
41+ x --
42+ y := x
43+
44+ _ = y
45+ }
46+
47+ func assignAndCall () {
48+ t1 := NewT ()
49+ t2 := NewT ()
50+
51+ t1 .Fn ()
52+ x := t1 .Fn ()
53+ t1 .Fn ()
54+
55+ _ , _ = t2 , x
56+ }
57+
58+ func closureInCall () {
59+ buf := & bytes.Buffer {}
60+ _ = FnC ("buf" , func () error {
61+ return json .NewEncoder (buf ).Encode ("x" )
62+ })
63+ }
64+
65+ func assignAfterBlock () {
66+ x := 1
67+ if x > 0 {
68+ return
69+ }
70+ x = 2 // want `missing whitespace above this line \(invalid statement above assign\)`
71+ }
72+
73+ func decl () {
74+ var x string
75+ y := "" // want `missing whitespace above this line \(invalid statement above assign\)`
76+
77+ _ , _ = x , y
78+ }
Original file line number Diff line number Diff line change 1+ //golangcitest:args -Ewsl_v5
2+ //golangcitest:expected_exitcode 0
3+ package testdata
4+
5+ import (
6+ "bytes"
7+ "encoding/json"
8+ )
9+
10+ type T struct {
11+ I int
12+ }
13+
14+ func NewT () * T {
15+ return & T {}
16+ }
17+
18+ func (* T ) Fn () int {
19+ return 1
20+ }
21+
22+ func FnC (_ string , fn func () error ) error {
23+ fn ()
24+ return nil
25+ }
26+
27+ func strictAppend () {
28+ s := []string {}
29+ s = append (s , "a" )
30+ s = append (s , "b" )
31+ x := "c"
32+ s = append (s , x )
33+ y := "e"
34+
35+ s = append (s , "d" ) // want `missing whitespace above this line \(no shared variables above append\)`
36+ s = append (s , y )
37+ }
38+
39+ func incDec () {
40+ x := 1
41+ x ++
42+ x --
43+ y := x
44+
45+ _ = y
46+ }
47+
48+ func assignAndCall () {
49+ t1 := NewT ()
50+ t2 := NewT ()
51+
52+ t1 .Fn ()
53+ x := t1 .Fn ()
54+ t1 .Fn ()
55+
56+ _ , _ = t2 , x
57+ }
58+
59+ func closureInCall () {
60+ buf := & bytes.Buffer {}
61+ _ = FnC ("buf" , func () error {
62+ return json .NewEncoder (buf ).Encode ("x" )
63+ })
64+ }
65+
66+ func assignAfterBlock () {
67+ x := 1
68+ if x > 0 {
69+ return
70+ }
71+
72+ x = 2 // want `missing whitespace above this line \(invalid statement above assign\)`
73+ }
74+
75+ func decl () {
76+ var x string
77+
78+ y := "" // want `missing whitespace above this line \(invalid statement above assign\)`
79+
80+ _ , _ = x , y
81+ }
Original file line number Diff line number Diff line change 1+ //golangcitest:args -Ewsl_v5
2+ package testdata
3+
4+ import (
5+ "bytes"
6+ "encoding/json"
7+ )
8+
9+ type T struct {
10+ I int
11+ }
12+
13+ func NewT () * T {
14+ return & T {}
15+ }
16+
17+ func (* T ) Fn () int {
18+ return 1
19+ }
20+
21+ func FnC (_ string , fn func () error ) error {
22+ fn ()
23+ return nil
24+ }
25+
26+ func strictAppend () {
27+ s := []string {}
28+ s = append (s , "a" )
29+ s = append (s , "b" )
30+ x := "c"
31+ s = append (s , x )
32+ y := "e"
33+ s = append (s , "d" ) // want `missing whitespace above this line \(no shared variables above append\)`
34+ s = append (s , y )
35+ }
36+
37+ func incDec () {
38+ x := 1
39+ x ++
40+ x --
41+ y := x
42+
43+ _ = y
44+ }
45+
46+ func assignAndCall () {
47+ t1 := NewT ()
48+ t2 := NewT ()
49+
50+ t1 .Fn ()
51+ x := t1 .Fn ()
52+ t1 .Fn ()
53+
54+ _ , _ = t2 , x
55+ }
56+
57+ func closureInCall () {
58+ buf := & bytes.Buffer {}
59+ _ = FnC ("buf" , func () error {
60+ return json .NewEncoder (buf ).Encode ("x" )
61+ })
62+ }
63+
64+ func assignAfterBlock () {
65+ x := 1
66+ if x > 0 {
67+ return
68+ }
69+ x = 2 // want `missing whitespace above this line \(invalid statement above assign\)`
70+ }
71+
72+ func decl () {
73+ var x string
74+ y := "" // want `missing whitespace above this line \(invalid statement above assign\)`
75+
76+ _ , _ = x , y
77+ }
Original file line number Diff line number Diff line change 1+ //golangcitest:args -Ewsl_v5
2+ //golangcitest:config_path testdata/wsl_v5_config.yml
3+ package testdata
4+
5+ func fn1 (s []string ) {
6+ a := "a"
7+ s = append (s , a )
8+
9+ x := 1
10+ s = append (s , "s" ) // want `missing whitespace above this line \(no shared variables above append\)`
11+
12+ _ = x
13+ }
Original file line number Diff line number Diff line change 1+ version : " 2"
2+
3+ linters :
4+ settings :
5+ wsl_v5 :
6+ allow-first-in-block : true
7+ allow-whole-block : false
8+ branch-max-lines : 2
9+ case-max-lines : 0
10+ default : all
You can’t perform that action at this time.
0 commit comments