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