github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/golang/lint/testdata/names.go (about)

     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  var var_name int // MATCH /underscore.*var.*var_name/
    14  
    15  type t_wow struct { // MATCH /underscore.*type.*t_wow/
    16  	x_damn int      // MATCH /underscore.*field.*x_damn/
    17  	Url    *url.URL // MATCH /struct field.*Url.*URL/
    18  }
    19  
    20  const fooId = "blah" // MATCH /fooId.*fooID/
    21  
    22  func f_it() { // MATCH /underscore.*func.*f_it/
    23  	more_underscore := 4 // MATCH /underscore.*var.*more_underscore/
    24  	_ = more_underscore
    25  	var err error
    26  	if isEof := (err == io.EOF); isEof { // MATCH /var.*isEof.*isEOF/
    27  		more_underscore = 7 // should be okay
    28  	}
    29  
    30  	x := net_http.Request{} // should be okay
    31  	_ = x
    32  
    33  	var ips []net.IP
    34  	for _, theIp := range ips { // MATCH /range var.*theIp.*theIP/
    35  		_ = theIp
    36  	}
    37  
    38  	switch myJson := g(); { // MATCH /var.*myJson.*myJSON/
    39  	default:
    40  		_ = myJson
    41  	}
    42  	var y net_http.ResponseWriter // an interface
    43  	switch tApi := y.(type) {     // MATCH /var.*tApi.*tAPI/
    44  	default:
    45  		_ = tApi
    46  	}
    47  
    48  	var c chan int
    49  	select {
    50  	case qId := <-c: // MATCH /var.*qId.*qID/
    51  		_ = qId
    52  	}
    53  }
    54  
    55  // Common styles in other languages that don't belong in Go.
    56  const (
    57  	CPP_CONST   = 1 // MATCH /ALL_CAPS.*CamelCase/
    58  	kLeadingKay = 2 // MATCH /k.*leadingKay/
    59  
    60  	HTML  = 3 // okay; no underscore
    61  	X509B = 4 // ditto
    62  )
    63  
    64  func f(bad_name int)                    {}            // MATCH /underscore.*func parameter.*bad_name/
    65  func g() (no_way int)                   { return 0 }  // MATCH /underscore.*func result.*no_way/
    66  func (t *t_wow) f(more_under string)    {}            // MATCH /underscore.*method parameter.*more_under/
    67  func (t *t_wow) g() (still_more string) { return "" } // MATCH /underscore.*method result.*still_more/
    68  
    69  type i interface {
    70  	CheckHtml() string // okay; interface method names are often constrained by the concrete types' method names
    71  
    72  	F(foo_bar int) // MATCH /foo_bar.*fooBar/
    73  }
    74  
    75  // All okay; underscore between digits
    76  const case1_1 = 1
    77  
    78  type case2_1 struct {
    79  	case2_2 int
    80  }
    81  
    82  func case3_1(case3_2 int) (case3_3 string) {
    83  	case3_4 := 4
    84  	_ = case3_4
    85  
    86  	return ""
    87  }