github.com/serversong/goreporter@v0.0.0-20200325104552-3cfaf44fd178/linters/golint/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  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/