pikeman 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +21 -0
  4. data/CONTRIBUTING.md +15 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +36 -0
  7. data/LICENSE +27 -0
  8. data/LICENSE.txt +21 -0
  9. data/Makefile +39 -0
  10. data/README.md +85 -0
  11. data/Rakefile +10 -0
  12. data/VERSION +1 -0
  13. data/bin/console +14 -0
  14. data/bin/pikeman +15 -0
  15. data/bin/setup +8 -0
  16. data/golint/golint.go +213 -0
  17. data/golint/import.go +309 -0
  18. data/golint/version.go +3 -0
  19. data/lib/pikeman.rb +34 -0
  20. data/lib/pikeman/version.rb +3 -0
  21. data/lint.go +1708 -0
  22. data/lint_test.go +317 -0
  23. data/misc/emacs/golint.el +54 -0
  24. data/misc/vim/ftplugin/go/lint.vim +31 -0
  25. data/pikeman.gemspec +28 -0
  26. data/testdata/4.go +38 -0
  27. data/testdata/5_test.go +17 -0
  28. data/testdata/blank-import-lib.go +39 -0
  29. data/testdata/blank-import-lib_test.go +25 -0
  30. data/testdata/blank-import-main.go +14 -0
  31. data/testdata/broken.go +9 -0
  32. data/testdata/common-methods.go +16 -0
  33. data/testdata/const-block.go +36 -0
  34. data/testdata/context.go +24 -0
  35. data/testdata/contextkeytypes.go +38 -0
  36. data/testdata/else-multi.go +18 -0
  37. data/testdata/else.go +23 -0
  38. data/testdata/error-return.go +43 -0
  39. data/testdata/errorf.go +40 -0
  40. data/testdata/errors.go +38 -0
  41. data/testdata/iferr.go +101 -0
  42. data/testdata/import-dot.go +8 -0
  43. data/testdata/inc.go +14 -0
  44. data/testdata/names.go +116 -0
  45. data/testdata/pkg-caps.go +4 -0
  46. data/testdata/pkg-doc1.go +3 -0
  47. data/testdata/pkg-doc2.go +5 -0
  48. data/testdata/pkg-doc3.go +7 -0
  49. data/testdata/pkg-doc4.go +7 -0
  50. data/testdata/pkg-doc5.go +9 -0
  51. data/testdata/pkg-main.go +5 -0
  52. data/testdata/range.go +43 -0
  53. data/testdata/receiver-names.go +49 -0
  54. data/testdata/sort.go +20 -0
  55. data/testdata/stutter.go +25 -0
  56. data/testdata/time.go +13 -0
  57. data/testdata/unexp-return.go +46 -0
  58. data/testdata/var-decl.go +86 -0
  59. metadata +172 -0
@@ -0,0 +1,8 @@
1
+ // Test that dot imports are flagged.
2
+
3
+ // Package pkg ...
4
+ package pkg
5
+
6
+ import . "fmt" // MATCH /dot import/
7
+
8
+ var _ Stringer // from "fmt"
@@ -0,0 +1,14 @@
1
+ // Test for use of x++ and x--.
2
+
3
+ // Package pkg ...
4
+ package pkg
5
+
6
+ func addOne(x int) int {
7
+ x += 1 // MATCH /x\+\+/
8
+ return x
9
+ }
10
+
11
+ func subOneInLoop(y int) {
12
+ for ; y > 0; y -= 1 { // MATCH /y--/
13
+ }
14
+ }
@@ -0,0 +1,116 @@
1
+ // Test for name linting.
2
+
3
+ // Package pkg_with_underscores ...
4
+ package pkg_with_underscores // MATCH /underscore.*package name/
5
+
6
+ import (
7
+ "io"
8
+ "net"
9
+ net_http "net/http" // renamed deliberately
10
+ "net/url"
11
+ )
12
+
13
+ import "C"
14
+
15
+ var var_name int // MATCH /underscore.*var.*var_name/
16
+
17
+ type t_wow struct { // MATCH /underscore.*type.*t_wow/
18
+ x_damn int // MATCH /underscore.*field.*x_damn/
19
+ Url *url.URL // MATCH /struct field.*Url.*URL/
20
+ }
21
+
22
+ const fooId = "blah" // MATCH /fooId.*fooID/
23
+
24
+ func f_it() { // MATCH /underscore.*func.*f_it/
25
+ more_underscore := 4 // MATCH /underscore.*var.*more_underscore/
26
+ _ = more_underscore
27
+ var err error
28
+ if isEof := (err == io.EOF); isEof { // MATCH /var.*isEof.*isEOF/
29
+ more_underscore = 7 // should be okay
30
+ }
31
+
32
+ x := net_http.Request{} // should be okay
33
+ _ = x
34
+
35
+ var ips []net.IP
36
+ for _, theIp := range ips { // MATCH /range var.*theIp.*theIP/
37
+ _ = theIp
38
+ }
39
+
40
+ switch myJson := g(); { // MATCH /var.*myJson.*myJSON/
41
+ default:
42
+ _ = myJson
43
+ }
44
+ var y net_http.ResponseWriter // an interface
45
+ switch tApi := y.(type) { // MATCH /var.*tApi.*tAPI/
46
+ default:
47
+ _ = tApi
48
+ }
49
+
50
+ var c chan int
51
+ select {
52
+ case qId := <-c: // MATCH /var.*qId.*qID/
53
+ _ = qId
54
+ }
55
+ }
56
+
57
+ // Common styles in other languages that don't belong in Go.
58
+ const (
59
+ CPP_CONST = 1 // MATCH /ALL_CAPS.*CamelCase/
60
+ kLeadingKay = 2 // MATCH /k.*leadingKay/
61
+
62
+ HTML = 3 // okay; no underscore
63
+ X509B = 4 // ditto
64
+ )
65
+
66
+ func f(bad_name int) {} // MATCH /underscore.*func parameter.*bad_name/
67
+ func g() (no_way int) { return 0 } // MATCH /underscore.*func result.*no_way/
68
+ func (t *t_wow) f(more_under string) {} // MATCH /underscore.*method parameter.*more_under/
69
+ func (t *t_wow) g() (still_more string) { return "" } // MATCH /underscore.*method result.*still_more/
70
+
71
+ type i interface {
72
+ CheckHtml() string // okay; interface method names are often constrained by the concrete types' method names
73
+
74
+ F(foo_bar int) // MATCH /foo_bar.*fooBar/
75
+ }
76
+
77
+ // All okay; underscore between digits
78
+ const case1_1 = 1
79
+
80
+ type case2_1 struct {
81
+ case2_2 int
82
+ }
83
+
84
+ func case3_1(case3_2 int) (case3_3 string) {
85
+ case3_4 := 4
86
+ _ = case3_4
87
+
88
+ return ""
89
+ }
90
+
91
+ type t struct{}
92
+
93
+ func (t) LastInsertId() (int64, error) { return 0, nil } // okay because it matches a known style violation
94
+
95
+ //export exported_to_c
96
+ func exported_to_c() {} // okay: https://github.com/golang/lint/issues/144
97
+
98
+ //export exported_to_c_with_arg
99
+ func exported_to_c_with_arg(but_use_go_param_names int) // MATCH /underscore.*func parameter.*but_use_go_param_names/
100
+
101
+ // This is an exported C function with a leading doc comment.
102
+ //
103
+ //export exported_to_c_with_comment
104
+ func exported_to_c_with_comment() {} // okay: https://github.com/golang/lint/issues/144
105
+
106
+ //export maybe_exported_to_CPlusPlusWithCamelCase
107
+ func maybe_exported_to_CPlusPlusWithCamelCase() {} // okay: https://github.com/golang/lint/issues/144
108
+
109
+ // WhyAreYouUsingCapitalLetters_InACFunctionName is a Go-exported function that
110
+ // is also exported to C as a name with underscores.
111
+ //
112
+ // Don't do that. If you want to use a C-style name for a C export, make it
113
+ // lower-case and leave it out of the Go-exported API.
114
+ //
115
+ //export WhyAreYouUsingCapitalLetters_InACFunctionName
116
+ func WhyAreYouUsingCapitalLetters_InACFunctionName() {} // MATCH /underscore.*func.*Why.*CFunctionName/
@@ -0,0 +1,4 @@
1
+ // MixedCaps package name
2
+
3
+ // Package PkgName ...
4
+ package PkgName // MATCH /don't use MixedCaps in package name/
@@ -0,0 +1,3 @@
1
+ // Test of missing package comment.
2
+
3
+ package foo // MATCH /should.*package comment.*unless/
@@ -0,0 +1,5 @@
1
+ // Test of package comment in an incorrect form.
2
+
3
+ // Some random package doc that isn't in the right form.
4
+ // MATCH /package comment should.*form.*"Package testdata .*"/
5
+ package testdata
@@ -0,0 +1,7 @@
1
+ // Test of block package comment.
2
+ // OK
3
+
4
+ /*
5
+ Package foo is pretty sweet.
6
+ */
7
+ package foo
@@ -0,0 +1,7 @@
1
+ // Test of block package comment with leading space.
2
+
3
+ /*
4
+ Package foo is pretty sweet.
5
+ MATCH /package comment.*leading space/
6
+ */
7
+ package foo
@@ -0,0 +1,9 @@
1
+ // Test of detached package comment.
2
+
3
+ /*
4
+ Package foo is pretty sweet.
5
+ */
6
+
7
+ package foo
8
+
9
+ // MATCH:6 /package comment.*detached/
@@ -0,0 +1,5 @@
1
+ // Test of package comment for package main.
2
+ // OK
3
+
4
+ // This binary does something awesome.
5
+ package main
@@ -0,0 +1,43 @@
1
+ // Test for range construction.
2
+
3
+ // Package foo ...
4
+ package foo
5
+
6
+ func f() {
7
+ var m map[string]int
8
+
9
+ // with :=
10
+ for x, _ := range m { // MATCH /should omit 2nd value.*range.*equivalent.*for x := range/ -> ` for x := range m {`
11
+ _ = x
12
+ }
13
+ // with =
14
+ var y string
15
+ _ = y
16
+ for y, _ = range m { // MATCH /should omit 2nd value.*range.*equivalent.*for y = range/
17
+ }
18
+
19
+ for _ = range m { // MATCH /should omit values.*range.*equivalent.*for range/
20
+ }
21
+
22
+ for _, _ = range m { // MATCH /should omit values.*range.*equivalent.*for range/
23
+ }
24
+
25
+ // all OK:
26
+ for x := range m {
27
+ _ = x
28
+ }
29
+ for x, y := range m {
30
+ _, _ = x, y
31
+ }
32
+ for _, y := range m {
33
+ _ = y
34
+ }
35
+ var x int
36
+ _ = x
37
+ for y = range m {
38
+ }
39
+ for y, x = range m {
40
+ }
41
+ for _, x = range m {
42
+ }
43
+ }
@@ -0,0 +1,49 @@
1
+ // Test for bad receiver names.
2
+
3
+ // Package foo ...
4
+ package foo
5
+
6
+ type foo struct{}
7
+
8
+ func (this foo) f1() { // MATCH /should be a reflection of its identity/
9
+ }
10
+
11
+ func (self foo) f2() { // MATCH /should be a reflection of its identity/
12
+ }
13
+
14
+ func (f foo) f3() {
15
+ }
16
+
17
+ func (foo) f4() {
18
+ }
19
+
20
+ type bar struct{}
21
+
22
+ func (b bar) f1() {
23
+ }
24
+
25
+ func (b bar) f2() {
26
+ }
27
+
28
+ func (a bar) f3() { // MATCH /receiver name a should be consistent with previous receiver name b for bar/
29
+ }
30
+
31
+ func (a *bar) f4() { // MATCH /receiver name a should be consistent with previous receiver name b for bar/
32
+ }
33
+
34
+ func (b *bar) f5() {
35
+ }
36
+
37
+ func (bar) f6() {
38
+ }
39
+
40
+ func (_ *bar) f7() { // MATCH /receiver name should not be an underscore/
41
+ }
42
+
43
+ type multiError struct{}
44
+
45
+ func (me multiError) f8() {
46
+ }
47
+
48
+ // Regression test for a panic caused by ill-formed receiver type.
49
+ func (recv []*x.y) f()
@@ -0,0 +1,20 @@
1
+ // Test that we don't ask for comments on sort.Interface methods.
2
+
3
+ // Package pkg ...
4
+ package pkg
5
+
6
+ // T is ...
7
+ type T []int
8
+
9
+ // Len by itself should get documented.
10
+
11
+ func (t T) Len() int { return len(t) } // MATCH /exported method T\.Len.*should.*comment/
12
+
13
+ // U is ...
14
+ type U []int
15
+
16
+ func (u U) Len() int { return len(u) }
17
+ func (u U) Less(i, j int) bool { return u[i] < u[j] }
18
+ func (u U) Swap(i, j int) { u[i], u[j] = u[j], u[i] }
19
+
20
+ func (u U) Other() {} // MATCH /exported method U\.Other.*should.*comment/
@@ -0,0 +1,25 @@
1
+ // Test of stuttery names.
2
+
3
+ // Package donut ...
4
+ package donut
5
+
6
+ // DonutMaker makes donuts.
7
+ type DonutMaker struct{} // MATCH /donut\.DonutMaker.*stutter/
8
+
9
+ // DonutRank computes the ranking of a donut.
10
+ func DonutRank(d Donut) int { // MATCH /donut\.DonutRank.*stutter/
11
+ return 0
12
+ }
13
+
14
+ // Donut is a delicious treat.
15
+ type Donut struct{} // ok because it is the whole name
16
+
17
+ // Donuts are great, aren't they?
18
+ type Donuts []Donut // ok because it didn't start a new word
19
+
20
+ type donutGlaze int // ok because it is unexported
21
+
22
+ // DonutMass reports the mass of a donut.
23
+ func (d *Donut) DonutMass() (grams int) { // okay because it is a method
24
+ return 38
25
+ }
@@ -0,0 +1,13 @@
1
+ // Test of time suffixes.
2
+
3
+ // Package foo ...
4
+ package foo
5
+
6
+ import (
7
+ "flag"
8
+ "time"
9
+ )
10
+
11
+ var rpcTimeoutMsec = flag.Duration("rpc_timeout", 100*time.Millisecond, "some flag") // MATCH /Msec.*\*time.Duration/
12
+
13
+ var timeoutSecs = 5 * time.Second // MATCH /Secs.*time.Duration/
@@ -0,0 +1,46 @@
1
+ // Test for unexported return types.
2
+
3
+ // Package foo ...
4
+ package foo
5
+
6
+ import ()
7
+
8
+ type hidden struct{}
9
+
10
+ // Exported returns a hidden type, which is annoying.
11
+ func Exported() hidden { // MATCH /Exported.*unexported.*hidden/
12
+ return hidden{}
13
+ }
14
+
15
+ // ExpErr returns a builtin type.
16
+ func ExpErr() error { // ok
17
+ }
18
+
19
+ func (hidden) ExpOnHidden() hidden { // ok
20
+ }
21
+
22
+ // T is another test type.
23
+ type T struct{}
24
+
25
+ // MethodOnT returns a hidden type, which is annoying.
26
+ func (T) MethodOnT() hidden { // MATCH /method MethodOnT.*unexported.*hidden/
27
+ return hidden{}
28
+ }
29
+
30
+ // ExpT returns a T.
31
+ func ExpT() T { // ok
32
+ return T{}
33
+ }
34
+
35
+ func unexp() hidden { // ok
36
+ return hidden{}
37
+ }
38
+
39
+ // This is slightly sneaky: we shadow the builtin "int" type.
40
+
41
+ type int struct{}
42
+
43
+ // ExportedIntReturner returns an unexported type from this package.
44
+ func ExportedIntReturner() int { // MATCH /ExportedIntReturner.*unexported.*int/
45
+ return int{}
46
+ }
@@ -0,0 +1,86 @@
1
+ // Test for redundant type declaration.
2
+
3
+ // Package foo ...
4
+ package foo
5
+
6
+ import (
7
+ "fmt"
8
+ "io"
9
+ "net/http"
10
+ "nosuchpkg" // export data unavailable
11
+ "os"
12
+ )
13
+
14
+ // Q is a test type.
15
+ type Q bool
16
+
17
+ var myInt int = 7 // MATCH /should.*int.*myInt.*inferred/
18
+ var mux *http.ServeMux = http.NewServeMux() // MATCH /should.*\*http\.ServeMux.*inferred/
19
+
20
+ var myZeroInt int = 0 // MATCH /should.*= 0.*myZeroInt.*zero value/
21
+ var myZeroFlt float32 = 0. // MATCH /should.*= 0\..*myZeroFlt.*zero value/
22
+ var myZeroF64 float64 = 0.0 // MATCH /should.*= 0\..*myZeroF64.*zero value/
23
+ var myZeroImg complex64 = 0i // MATCH /should.*= 0i.*myZeroImg.*zero value/
24
+ var myZeroStr string = "" // MATCH /should.*= "".*myZeroStr.*zero value/
25
+ var myZeroRaw string = `` // MATCH /should.*= ``.*myZeroRaw.*zero value/
26
+ var myZeroPtr *Q = nil // MATCH /should.*= nil.*myZeroPtr.*zero value/
27
+ var myZeroRune rune = '\x00' // MATCH /should.*= '\\x00'.*myZeroRune.*zero value/
28
+ var myZeroRune2 rune = '\000' // MATCH /should.*= '\\000'.*myZeroRune2.*zero value/
29
+
30
+ // No warning because there's no type on the LHS
31
+ var x = 0
32
+
33
+ // This shouldn't get a warning because there's no initial values.
34
+ var str fmt.Stringer
35
+
36
+ // No warning because this is a const.
37
+ const k uint64 = 7
38
+
39
+ const num = 123
40
+
41
+ // No warning because the var's RHS is known to be an untyped const.
42
+ var flags uint32 = num
43
+
44
+ // No warnings because the RHS is an ideal int, and the LHS is a different int type.
45
+ var userID int64 = 1235
46
+ var negID int64 = -1
47
+ var parenID int64 = (17)
48
+ var crazyID int64 = -(-(-(-9)))
49
+
50
+ // Same, but for strings and floats.
51
+ type stringT string
52
+ type floatT float64
53
+
54
+ var stringV stringT = "abc"
55
+ var floatV floatT = 123.45
56
+
57
+ // No warning because the LHS names an interface type.
58
+ var data interface{} = googleIPs
59
+ var googleIPs []int
60
+
61
+ // No warning because it's a common idiom for interface satisfaction.
62
+ var _ Server = (*serverImpl)(nil)
63
+
64
+ // Server is a test type.
65
+ type Server interface{}
66
+ type serverImpl struct{}
67
+
68
+ // LHS is a different type than the RHS.
69
+ var myStringer fmt.Stringer = q(0)
70
+
71
+ // LHS is a different type than the RHS.
72
+ var out io.Writer = os.Stdout
73
+
74
+ var out2 io.Writer = newWriter() // MATCH /should omit.*io\.Writer/
75
+
76
+ func newWriter() io.Writer { return nil }
77
+
78
+ // We don't figure out the true types of LHS and RHS here,
79
+ // so we suppress the check.
80
+ var ni nosuchpkg.Interface = nosuchpkg.NewConcrete()
81
+
82
+ var y string = q(1).String() // MATCH /should.*string/
83
+
84
+ type q int
85
+
86
+ func (q) String() string { return "I'm a q" }