github.com/elek/golangci-lint@v1.42.2-0.20211208090441-c05b7fcb3a9a/pkg/result/processors/identifier_marker_test.go (about)

     1  package processors
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/elek/golangci-lint/pkg/result"
     9  )
    10  
    11  func TestIdentifierMarker(t *testing.T) {
    12  	//nolint:lll
    13  	cases := []struct{ in, out string }{
    14  		{"unknown field Address in struct literal", "unknown field `Address` in struct literal"},
    15  		{"invalid operation: res (variable of type github.com/iotexproject/iotex-core/explorer/idl/explorer.GetBlkOrActResponse) has no field or method Address",
    16  			"invalid operation: `res` (variable of type `github.com/iotexproject/iotex-core/explorer/idl/explorer.GetBlkOrActResponse`) has no field or method `Address`"},
    17  		{"should use a simple channel send/receive instead of select with a single case",
    18  			"should use a simple channel send/receive instead of `select` with a single case"},
    19  		{"var testInputs is unused", "var `testInputs` is unused"},
    20  		{"undeclared name: stateIDLabel", "undeclared name: `stateIDLabel`"},
    21  		{"exported type Metrics should have comment or be unexported",
    22  			"exported type `Metrics` should have comment or be unexported"},
    23  		{`comment on exported function NewMetrics should be of the form "NewMetrics ..."`,
    24  			"comment on exported function `NewMetrics` should be of the form `NewMetrics ...`"},
    25  		{"cannot use addr (variable of type string) as github.com/iotexproject/iotex-core/pkg/keypair.PublicKey value in argument to action.FakeSeal",
    26  			"cannot use addr (variable of type `string`) as `github.com/iotexproject/iotex-core/pkg/keypair.PublicKey` value in argument to `action.FakeSeal`"},
    27  		{"other declaration of out", "other declaration of `out`"},
    28  		{"should check returned error before deferring response.Close()", "should check returned error before deferring `response.Close()`"},
    29  		{"should use time.Since instead of time.Now().Sub", "should use `time.Since` instead of `time.Now().Sub`"},
    30  		{"TestFibZeroCount redeclared in this block", "`TestFibZeroCount` redeclared in this block"},
    31  		{"should replace i += 1 with i++", "should replace `i += 1` with `i++`"},
    32  		{"createEntry - result err is always nil", "`createEntry` - result `err` is always `nil`"},
    33  		{"should omit comparison to bool constant, can be simplified to !projectIntegration.Model.Storage",
    34  			"should omit comparison to bool constant, can be simplified to `!projectIntegration.Model.Storage`"},
    35  		{"if block ends with a return statement, so drop this else and outdent its block",
    36  			"`if` block ends with a `return` statement, so drop this `else` and outdent its block"},
    37  		{"should write pupData := ms.m[pupID] instead of pupData, _ := ms.m[pupID]",
    38  			"should write `pupData := ms.m[pupID]` instead of `pupData, _ := ms.m[pupID]`"},
    39  		{"no value of type uint is less than 0", "no value of type `uint` is less than `0`"},
    40  		{"redundant return statement", "redundant `return` statement"},
    41  		{"struct field Id should be ID", "struct field `Id` should be `ID`"},
    42  		{"don't use underscores in Go names; var Go_lint should be GoLint",
    43  			"don't use underscores in Go names; var `Go_lint` should be `GoLint`"},
    44  		{"G501: Blacklisted import crypto/md5: weak cryptographic primitive",
    45  			"G501: Blacklisted import `crypto/md5`: weak cryptographic primitive"},
    46  		{"S1017: should replace this if statement with an unconditional strings.TrimPrefix",
    47  			"S1017: should replace this `if` statement with an unconditional `strings.TrimPrefix`"},
    48  	}
    49  	p := NewIdentifierMarker()
    50  
    51  	for _, c := range cases {
    52  		out, err := p.Process([]result.Issue{{Text: c.in}})
    53  		assert.NoError(t, err)
    54  		assert.Equal(t, []result.Issue{{Text: c.out}}, out)
    55  	}
    56  }