initial vendor commit
This commit is contained in:
1 parent
747c805a82
commit
21e1fb3451
660 files changed
+133146
No files matched your search
@@ -0,0 +1,34 @@
|
||||
// Test that exported names have correct comments.
|
||||
|
||||
// Package pkg does something.
|
||||
package pkg
|
||||
|
||||
import "time"
|
||||
|
||||
type T int // MATCH /exported type T.*should.*comment.*or.*unexport/
|
||||
|
||||
func (T) F() {} // MATCH /exported method T\.F.*should.*comment.*or.*unexport/
|
||||
|
||||
// this is a nice type.
|
||||
// MATCH /comment.*exported type U.*should.*form.*"U ..."/
|
||||
type U string
|
||||
|
||||
// this is a neat function.
|
||||
// MATCH /comment.*exported method U\.G.*should.*form.*"G ..."/
|
||||
func (U) G() {}
|
||||
|
||||
// A V is a string.
|
||||
type V string
|
||||
|
||||
// V.H has a pointer receiver
|
||||
|
||||
func (*V) H() {} // MATCH /exported method V\.H.*should.*comment.*or.*unexport/
|
||||
|
||||
var W = "foo" // MATCH /exported var W.*should.*comment.*or.*unexport/
|
||||
|
||||
const X = "bar" // MATCH /exported const X.*should.*comment.*or.*unexport/
|
||||
|
||||
var Y, Z int // MATCH /exported var Z.*own declaration/
|
||||
|
||||
// Location should be okay, since the other var name is an underscore.
|
||||
var Location, _ = time.LoadLocation("Europe/Istanbul") // not Constantinople
|
||||
@@ -0,0 +1,17 @@
|
||||
// This file ends in _test.go, so we should not warn about doc comments.
|
||||
// OK
|
||||
|
||||
package pkg
|
||||
|
||||
import "testing"
|
||||
|
||||
type H int
|
||||
|
||||
func TestSomething(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSomething_suffix(t *testing.T) {
|
||||
}
|
||||
|
||||
func ExampleBuffer_reader() {
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// Test that blank imports in library packages are flagged.
|
||||
|
||||
// Package foo ...
|
||||
package foo
|
||||
|
||||
// The instructions need to go before the imports below so they will not be
|
||||
// mistaken for documentation.
|
||||
|
||||
/* MATCH /blank import/ */ import _ "encoding/json"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
/* MATCH /blank import/ */ _ "os"
|
||||
|
||||
/* MATCH /blank import/ */ _ "net/http"
|
||||
_ "path"
|
||||
)
|
||||
|
||||
import _ "encoding/base64" // Don't gripe about this
|
||||
|
||||
import (
|
||||
// Don't gripe about these next two lines.
|
||||
_ "compress/zlib"
|
||||
_ "syscall"
|
||||
|
||||
/* MATCH /blank import/ */ _ "path/filepath"
|
||||
)
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
_ "go/scanner" // Don't gripe about this or the following line.
|
||||
_ "go/token"
|
||||
)
|
||||
|
||||
var (
|
||||
_ fmt.Stringer // for "fmt"
|
||||
_ ast.Node // for "go/ast"
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
// Test that blank imports in test packages are not flagged.
|
||||
// OK
|
||||
|
||||
// Package foo ...
|
||||
package foo
|
||||
|
||||
// These are essentially the same imports as in the "library" package, but
|
||||
// these should not trigger the warning because this is a test.
|
||||
|
||||
import _ "encoding/json"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
_ "os"
|
||||
|
||||
_ "net/http"
|
||||
_ "path"
|
||||
)
|
||||
|
||||
var (
|
||||
_ fmt.Stringer // for "fmt"
|
||||
_ testing.T // for "testing"
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
// Test that blank imports in package main are not flagged.
|
||||
// OK
|
||||
|
||||
// Binary foo ...
|
||||
package main
|
||||
|
||||
import _ "fmt"
|
||||
|
||||
import (
|
||||
"os"
|
||||
_ "path"
|
||||
)
|
||||
|
||||
var _ os.File // for "os"
|
||||
@@ -0,0 +1,16 @@
|
||||
// Test that we don't nag for comments on common methods.
|
||||
// OK
|
||||
|
||||
// Package pkg ...
|
||||
package pkg
|
||||
|
||||
import "net/http"
|
||||
|
||||
// T is ...
|
||||
type T int
|
||||
|
||||
func (T) Error() string { return "" }
|
||||
func (T) String() string { return "" }
|
||||
func (T) ServeHTTP(w http.ResponseWriter, r *http.Request) {}
|
||||
func (T) Read(p []byte) (n int, err error) { return 0, nil }
|
||||
func (T) Write(p []byte) (n int, err error) { return 0, nil }
|
||||
@@ -0,0 +1,36 @@
|
||||
// Test for docs in const blocks
|
||||
|
||||
// Package foo ...
|
||||
package foo
|
||||
|
||||
const (
|
||||
// Prefix for something.
|
||||
// MATCH /InlineWhatever.*form/
|
||||
InlineWhatever = "blah"
|
||||
|
||||
Whatsit = "missing_comment" // MATCH /Whatsit.*should have comment.*block/
|
||||
|
||||
// We should only warn once per block for missing comments,
|
||||
// but always complain about malformed comments.
|
||||
|
||||
WhosYourDaddy = "another_missing_one"
|
||||
|
||||
// Something
|
||||
// MATCH /WhatDoesHeDo.*form/
|
||||
WhatDoesHeDo = "it's not a tumor!"
|
||||
)
|
||||
|
||||
// These shouldn't need doc comments.
|
||||
const (
|
||||
Alpha = "a"
|
||||
Beta = "b"
|
||||
Gamma = "g"
|
||||
)
|
||||
|
||||
// The comment on the previous const block shouldn't flow through to here.
|
||||
|
||||
const UndocAgain = 6 // MATCH /UndocAgain.*should have comment/
|
||||
|
||||
const (
|
||||
SomeUndocumented = 7 // MATCH /SomeUndocumented.*should have comment.*block/
|
||||
)
|
||||
@@ -0,0 +1,18 @@
|
||||
// Test of return+else warning; should not trigger on multi-branch if/else.
|
||||
// OK
|
||||
|
||||
// Package pkg ...
|
||||
package pkg
|
||||
|
||||
import "log"
|
||||
|
||||
func f(x int) bool {
|
||||
if x == 0 {
|
||||
log.Print("x is zero")
|
||||
} else if x > 0 {
|
||||
return true
|
||||
} else {
|
||||
log.Printf("non-positive x: %d", x)
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// Test of return+else warning.
|
||||
|
||||
// Package pkg ...
|
||||
package pkg
|
||||
|
||||
import "log"
|
||||
|
||||
func f(x int) bool {
|
||||
if x > 0 {
|
||||
return true
|
||||
} else { // MATCH /if.*return.*else.*outdent/
|
||||
log.Printf("non-positive x: %d", x)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func g(f func() bool) string {
|
||||
if ok := f(); ok {
|
||||
return "it's okay"
|
||||
} else { // MATCH /if.*return.*else.*outdent.*short.*var.*declaration/
|
||||
return "it's NOT okay!"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Test for returning errors.
|
||||
|
||||
// Package foo ...
|
||||
package foo
|
||||
|
||||
// Returns nothing
|
||||
func f() { // ok
|
||||
}
|
||||
|
||||
// Check for a single error return
|
||||
func g() error { // ok
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check for a single other return type
|
||||
func h() int { // ok
|
||||
return 0
|
||||
}
|
||||
|
||||
// Check for multiple return but error at end.
|
||||
func i() (int, error) { // ok
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// Check for multiple return but error at end with named variables.
|
||||
func j() (x int, err error) { // ok
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// Check for error in the wrong location on 2 types
|
||||
func k() (error, int) { // MATCH /error should be the last type/
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
// Check for error in the wrong location for > 2 types
|
||||
func l() (int, error, int) { // MATCH /error should be the last type/
|
||||
return 0, nil, 0
|
||||
}
|
||||
|
||||
// Check for error in the wrong location with named variables.
|
||||
func m() (x int, err error, y int) { // MATCH /error should be the last type/
|
||||
return 0, nil, 0
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Test for not using fmt.Errorf.
|
||||
|
||||
// Package foo ...
|
||||
package foo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func f(x int) error {
|
||||
if x > 10 {
|
||||
return errors.New(fmt.Sprintf("something %d", x)) // MATCH /should replace.*errors\.New\(fmt\.Sprintf\(\.\.\.\)\).*fmt\.Errorf\(\.\.\.\)/
|
||||
}
|
||||
if x > 5 {
|
||||
return errors.New(g("blah")) // ok
|
||||
}
|
||||
if x > 4 {
|
||||
return errors.New("something else") // ok
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func g(s string) string { return "prefix: " + s }
|
||||
@@ -0,0 +1,36 @@
|
||||
// Test for naming errors.
|
||||
|
||||
// Package foo ...
|
||||
package foo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var unexp = errors.New("some unexported error") // MATCH /error var.*unexp.*errFoo/
|
||||
|
||||
// Exp ...
|
||||
var Exp = errors.New("some exported error") // MATCH /error var.*Exp.*ErrFoo/
|
||||
|
||||
var (
|
||||
e1 = fmt.Errorf("blah %d", 4) // MATCH /error var.*e1.*errFoo/
|
||||
// E2 ...
|
||||
E2 = fmt.Errorf("blah %d", 5) // MATCH /error var.*E2.*ErrFoo/
|
||||
)
|
||||
|
||||
func f() {
|
||||
var whatever = errors.New("ok") // ok
|
||||
_ = whatever
|
||||
}
|
||||
|
||||
// Check for the error strings themselves.
|
||||
|
||||
func g(x int) error {
|
||||
if x < 1 {
|
||||
return fmt.Errorf("This %d is too low", x) // MATCH /error strings.*not be capitalized/
|
||||
} else if x == 0 {
|
||||
return fmt.Errorf("XML time") // ok
|
||||
}
|
||||
return errors.New(`too much stuff.`) // MATCH /error strings.*not end with punctuation/
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Test that dot imports are flagged.
|
||||
|
||||
// Package pkg ...
|
||||
package pkg
|
||||
|
||||
import . "fmt" // MATCH /dot import/
|
||||
|
||||
var _ Stringer // from "fmt"
|
||||
@@ -0,0 +1,14 @@
|
||||
// Test for use of x++ and x--.
|
||||
|
||||
// Package pkg ...
|
||||
package pkg
|
||||
|
||||
func addOne(x int) int {
|
||||
x += 1 // MATCH /x\+\+/
|
||||
return x
|
||||
}
|
||||
|
||||
func subOneInLoop(y int) {
|
||||
for ; y > 0; y -= 1 { // MATCH /y--/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Test for pointless make() calls.
|
||||
|
||||
// Package pkg ...
|
||||
package pkg
|
||||
|
||||
import "net/http"
|
||||
|
||||
// T is a test type.
|
||||
type T int
|
||||
|
||||
var z []T
|
||||
|
||||
func f() {
|
||||
x := make([]T, 0) // MATCH /var x \[\]T/
|
||||
y := make([]http.Request, 0) // MATCH /var y \[\]http\.Request/
|
||||
z = make([]T, 0) // ok, because we don't know where z is declared
|
||||
|
||||
_, _ = x, y
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// Test for name linting.
|
||||
|
||||
// Package pkg_with_underscores ...
|
||||
package pkg_with_underscores // MATCH /underscore.*package name/
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
net_http "net/http" // renamed deliberately
|
||||
"net/url"
|
||||
)
|
||||
|
||||
var var_name int // MATCH /underscore.*var.*var_name/
|
||||
|
||||
type t_wow struct { // MATCH /underscore.*type.*t_wow/
|
||||
x_damn int // MATCH /underscore.*field.*x_damn/
|
||||
Url *url.URL // MATCH /struct field.*Url.*URL/
|
||||
}
|
||||
|
||||
const fooId = "blah" // MATCH /fooId.*fooID/
|
||||
|
||||
func f_it() { // MATCH /underscore.*func.*f_it/
|
||||
more_underscore := 4 // MATCH /underscore.*var.*more_underscore/
|
||||
_ = more_underscore
|
||||
var err error
|
||||
if isEof := (err == io.EOF); isEof { // MATCH /var.*isEof.*isEOF/
|
||||
more_underscore = 7 // should be okay
|
||||
}
|
||||
|
||||
x := net_http.Request{} // should be okay
|
||||
_ = x
|
||||
|
||||
var ips []net.IP
|
||||
for _, theIp := range ips { // MATCH /range var.*theIp.*theIP/
|
||||
_ = theIp
|
||||
}
|
||||
|
||||
switch myJson := g(); { // MATCH /var.*myJson.*myJSON/
|
||||
default:
|
||||
_ = myJson
|
||||
}
|
||||
var y net_http.ResponseWriter // an interface
|
||||
switch tApi := y.(type) { // MATCH /var.*tApi.*tAPI/
|
||||
default:
|
||||
_ = tApi
|
||||
}
|
||||
|
||||
var c chan int
|
||||
select {
|
||||
case qId := <-c: // MATCH /var.*qId.*qID/
|
||||
_ = qId
|
||||
}
|
||||
}
|
||||
|
||||
// Common styles in other languages that don't belong in Go.
|
||||
const (
|
||||
CPP_CONST = 1 // MATCH /ALL_CAPS.*CamelCase/
|
||||
kLeadingKay = 2 // MATCH /k.*leadingKay/
|
||||
|
||||
HTML = 3 // okay; no underscore
|
||||
X509B = 4 // ditto
|
||||
)
|
||||
|
||||
func f(bad_name int) {} // MATCH /underscore.*func parameter.*bad_name/
|
||||
func g() (no_way int) { return 0 } // MATCH /underscore.*func result.*no_way/
|
||||
func (t *t_wow) f(more_under string) {} // MATCH /underscore.*method parameter.*more_under/
|
||||
func (t *t_wow) g() (still_more string) { return "" } // MATCH /underscore.*method result.*still_more/
|
||||
|
||||
type i interface {
|
||||
CheckHtml() string // okay; interface method names are often constrained by the concrete types' method names
|
||||
|
||||
F(foo_bar int) // MATCH /foo_bar.*fooBar/
|
||||
}
|
||||
|
||||
// All okay; underscore between digits
|
||||
const case1_1 = 1
|
||||
|
||||
type case2_1 struct {
|
||||
case2_2 int
|
||||
}
|
||||
|
||||
func case3_1(case3_2 int) (case3_3 string) {
|
||||
case3_4 := 4
|
||||
_ = case3_4
|
||||
|
||||
return ""
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// Test of missing package comment.
|
||||
|
||||
package foo // MATCH /should.*package comment.*unless/
|
||||
@@ -0,0 +1,5 @@
|
||||
// Test of package comment in an incorrect form.
|
||||
|
||||
// Some random package doc that isn't in the right form.
|
||||
// MATCH /package comment should.*form.*"Package testdata .*"/
|
||||
package testdata
|
||||
@@ -0,0 +1,7 @@
|
||||
// Test of block package comment.
|
||||
// OK
|
||||
|
||||
/*
|
||||
Package foo is pretty sweet.
|
||||
*/
|
||||
package foo
|
||||
@@ -0,0 +1,7 @@
|
||||
// Test of block package comment with leading space.
|
||||
|
||||
/*
|
||||
Package foo is pretty sweet.
|
||||
MATCH /package comment.*leading space/
|
||||
*/
|
||||
package foo
|
||||
@@ -0,0 +1,9 @@
|
||||
// Test of detached package comment.
|
||||
|
||||
/*
|
||||
Package foo is pretty sweet.
|
||||
*/
|
||||
|
||||
package foo
|
||||
|
||||
// MATCH:6 /package comment.*detached/
|
||||
@@ -0,0 +1,5 @@
|
||||
// Test of package comment for package main.
|
||||
// OK
|
||||
|
||||
// This binary does something awesome.
|
||||
package main
|
||||
@@ -0,0 +1,37 @@
|
||||
// Test for range construction.
|
||||
|
||||
// Package foo ...
|
||||
package foo
|
||||
|
||||
func f() {
|
||||
var m map[string]int
|
||||
|
||||
// with :=
|
||||
for x, _ := range m { // MATCH /should omit 2nd value.*range.*equivalent.*for x := range/
|
||||
_ = x
|
||||
}
|
||||
// with =
|
||||
var y string
|
||||
_ = y
|
||||
for y, _ = range m { // MATCH /should omit 2nd value.*range.*equivalent.*for y = range/
|
||||
}
|
||||
|
||||
// all OK:
|
||||
for x := range m {
|
||||
_ = x
|
||||
}
|
||||
for x, y := range m {
|
||||
_, _ = x, y
|
||||
}
|
||||
for _, y := range m {
|
||||
_ = y
|
||||
}
|
||||
var x int
|
||||
_ = x
|
||||
for y = range m {
|
||||
}
|
||||
for y, x = range m {
|
||||
}
|
||||
for _, x = range m {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Test for bad receiver names.
|
||||
|
||||
// Package foo ...
|
||||
package foo
|
||||
|
||||
type foo struct{}
|
||||
|
||||
func (this foo) f1() { // MATCH /should be a reflection of its identity/
|
||||
}
|
||||
|
||||
func (self foo) f2() { // MATCH /should be a reflection of its identity/
|
||||
}
|
||||
|
||||
func (f foo) f3() {
|
||||
}
|
||||
|
||||
func (foo) f4() {
|
||||
}
|
||||
|
||||
type bar struct{}
|
||||
|
||||
func (b bar) f1() {
|
||||
}
|
||||
|
||||
func (b bar) f2() {
|
||||
}
|
||||
|
||||
func (a bar) f3() { // MATCH /receiver name a should be consistent with previous receiver name b for bar/
|
||||
}
|
||||
|
||||
func (a *bar) f4() { // MATCH /receiver name a should be consistent with previous receiver name b for bar/
|
||||
}
|
||||
|
||||
func (b *bar) f5() {
|
||||
}
|
||||
|
||||
func (bar) f6() {
|
||||
}
|
||||
|
||||
func (_ *bar) f7() { // MATCH /receiver name should not be an underscore/
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Test that we don't ask for comments on sort.Interface methods.
|
||||
|
||||
// Package pkg ...
|
||||
package pkg
|
||||
|
||||
// T is ...
|
||||
type T []int
|
||||
|
||||
// Len by itself should get documented.
|
||||
|
||||
func (t T) Len() int { return len(t) } // MATCH /exported method T\.Len.*should.*comment/
|
||||
|
||||
// U is ...
|
||||
type U []int
|
||||
|
||||
func (u U) Len() int { return len(u) }
|
||||
func (u U) Less(i, j int) bool { return u[i] < u[j] }
|
||||
func (u U) Swap(i, j int) { u[i], u[j] = u[j], u[i] }
|
||||
|
||||
func (u U) Other() {} // MATCH /exported method U\.Other.*should.*comment/
|
||||
@@ -0,0 +1,25 @@
|
||||
// Test of stuttery names.
|
||||
|
||||
// Package donut ...
|
||||
package donut
|
||||
|
||||
// DonutMaker makes donuts.
|
||||
type DonutMaker struct{} // MATCH /donut\.DonutMaker.*stutter/
|
||||
|
||||
// DonutRank computes the ranking of a donut.
|
||||
func DonutRank(d Donut) int { // MATCH /donut\.DonutRank.*stutter/
|
||||
return 0
|
||||
}
|
||||
|
||||
// Donut is a delicious treat.
|
||||
type Donut struct{} // ok because it is the whole name
|
||||
|
||||
// Donuts are great, aren't they?
|
||||
type Donuts []Donut // ok because it didn't start a new word
|
||||
|
||||
type donutGlaze int // ok because it is unexported
|
||||
|
||||
// DonutMass reports the mass of a donut.
|
||||
func (d *Donut) DonutMass() (grams int) { // okay because it is a method
|
||||
return 38
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Test of time suffixes.
|
||||
|
||||
// Package foo ...
|
||||
package foo
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"time"
|
||||
)
|
||||
|
||||
var rpcTimeoutMsec = flag.Duration("rpc_timeout", 100*time.Millisecond, "some flag") // MATCH /Msec.*\*time.Duration/
|
||||
|
||||
var timeoutSecs = 5 * time.Second // MATCH /Secs.*time.Duration/
|
||||
@@ -0,0 +1,46 @@
|
||||
// Test for unexported return types.
|
||||
|
||||
// Package foo ...
|
||||
package foo
|
||||
|
||||
import ()
|
||||
|
||||
type hidden struct{}
|
||||
|
||||
// Exported returns a hidden type, which is annoying.
|
||||
func Exported() hidden { // MATCH /Exported.*unexported.*hidden/
|
||||
return hidden{}
|
||||
}
|
||||
|
||||
// ExpErr returns a builtin type.
|
||||
func ExpErr() error { // ok
|
||||
}
|
||||
|
||||
func (hidden) ExpOnHidden() hidden { // ok
|
||||
}
|
||||
|
||||
// T is another test type.
|
||||
type T struct{}
|
||||
|
||||
// MethodOnT returns a hidden type, which is annoying.
|
||||
func (T) MethodOnT() hidden { // MATCH /method MethodOnT.*unexported.*hidden/
|
||||
return hidden{}
|
||||
}
|
||||
|
||||
// ExpT returns a T.
|
||||
func ExpT() T { // ok
|
||||
return T{}
|
||||
}
|
||||
|
||||
func unexp() hidden { // ok
|
||||
return hidden{}
|
||||
}
|
||||
|
||||
// This is slightly sneaky: we shadow the builtin "int" type.
|
||||
|
||||
type int struct{}
|
||||
|
||||
// ExportedIntReturner returns an unexported type from this package.
|
||||
func ExportedIntReturner() int { // MATCH /ExportedIntReturner.*unexported.*int/
|
||||
return int{}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// Test for redundant type declaration.
|
||||
|
||||
// Package foo ...
|
||||
package foo
|
||||
|
||||
import "fmt"
|
||||
import "net/http"
|
||||
|
||||
// Q is a test type.
|
||||
type Q bool
|
||||
|
||||
var myInt int = 7 // MATCH /should.*int.*myInt.*inferred/
|
||||
var mux *http.ServeMux = http.NewServeMux() // MATCH /should.*\*http\.ServeMux.*inferred/
|
||||
|
||||
var myZeroInt int = 0 // MATCH /should.*= 0.*myZeroInt.*zero value/
|
||||
var myZeroFlt float32 = 0. // MATCH /should.*= 0\..*myZeroFlt.*zero value/
|
||||
var myZeroF64 float64 = 0.0 // MATCH /should.*= 0\..*myZeroF64.*zero value/
|
||||
var myZeroImg complex64 = 0i // MATCH /should.*= 0i.*myZeroImg.*zero value/
|
||||
var myZeroStr string = "" // MATCH /should.*= "".*myZeroStr.*zero value/
|
||||
var myZeroRaw string = `` // MATCH /should.*= ``.*myZeroRaw.*zero value/
|
||||
var myZeroPtr *Q = nil // MATCH /should.*= nil.*myZeroPtr.*zero value/
|
||||
var myZeroRune rune = '\x00' // MATCH /should.*= '\\x00'.*myZeroRune.*zero value/
|
||||
var myZeroRune2 rune = '\000' // MATCH /should.*= '\\000'.*myZeroRune2.*zero value/
|
||||
|
||||
// No warning because there's no type on the LHS
|
||||
var x = 0
|
||||
|
||||
// This shouldn't get a warning because there's no initial values.
|
||||
var str fmt.Stringer
|
||||
|
||||
// No warning because this is a const.
|
||||
const k uint64 = 7
|
||||
|
||||
const num = 123
|
||||
|
||||
// No warning because the var's RHS is known to be an untyped const.
|
||||
var flags uint32 = num
|
||||
|
||||
// No warnings because the RHS is an ideal int, and the LHS is a different int type.
|
||||
var userID int64 = 1235
|
||||
var negID int64 = -1
|
||||
var parenID int64 = (17)
|
||||
var crazyID int64 = -(-(-(-9)))
|
||||
|
||||
// Same, but for strings and floats.
|
||||
type stringT string
|
||||
type floatT float64
|
||||
|
||||
var stringV stringT = "abc"
|
||||
var floatV floatT = 123.45
|
||||
|
||||
// No warning because the LHS names an interface type.
|
||||
var data interface{} = googleIPs
|
||||
var googleIPs []int
|
||||
|
||||
// No warning because it's a common idiom for interface satisfaction.
|
||||
var _ Server = (*serverImpl)(nil)
|
||||
|
||||
// Server is a test type.
|
||||
type Server interface{}
|
||||
type serverImpl struct{}
|
||||
|
||||
// LHS is a different type than the RHS.
|
||||
var myStringer fmt.Stringer = q(0)
|
||||
|
||||
var y string = q(1).String() // MATCH /should.*string/
|
||||
|
||||
type q int
|
||||
|
||||
func (q) String() string { return "I'm a q" }
|
||||
Reference in new issue
Block a user