mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
Prepare for #164: rename GAS to gosec
1. Rename in a backward compatible way 2. Remove gosec default exclude list because gosec is already disabled by default. 3. Warn about unmatched linter names in //nolint directives 4. Process linter names in //nolint directives in upper case 5. Disable gosec for golangci-lint in .golangci.yml
This commit is contained in:
parent
47440bc2cc
commit
8a478c47ac
29 changed files with 361 additions and 107 deletions
|
@ -1,10 +1,12 @@
|
|||
package processors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/token"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/golangci/golangci-lint/pkg/lint/astcache"
|
||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
|
@ -27,8 +29,22 @@ func newNolint2FileIssue(line int) result.Issue {
|
|||
return i
|
||||
}
|
||||
|
||||
func newTestNolintProcessor(log logutils.Log) *Nolint {
|
||||
return NewNolint(astcache.NewCache(log), log)
|
||||
}
|
||||
|
||||
func getOkLogger(ctrl *gomock.Controller) *logutils.MockLog {
|
||||
log := logutils.NewMockLog(ctrl)
|
||||
log.EXPECT().Infof(gomock.Any(), gomock.Any()).AnyTimes()
|
||||
return log
|
||||
}
|
||||
|
||||
func TestNolint(t *testing.T) {
|
||||
p := NewNolint(astcache.NewCache(logutils.NewStderrLog("")))
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
p := newTestNolintProcessor(getOkLogger(ctrl))
|
||||
defer p.Finish()
|
||||
|
||||
// test inline comments
|
||||
processAssertEmpty(t, p, newNolintFileIssue(3, "gofmt"))
|
||||
|
@ -99,7 +115,48 @@ func TestNolint(t *testing.T) {
|
|||
for i := 15; i <= 18; i++ {
|
||||
processAssertSame(t, p, newNolint2FileIssue(i))
|
||||
}
|
||||
}
|
||||
|
||||
func TestNolintInvalidLinterName(t *testing.T) {
|
||||
fileName := filepath.Join("testdata", "nolint_bad_names.go")
|
||||
issues := []result.Issue{
|
||||
{
|
||||
Pos: token.Position{
|
||||
Filename: fileName,
|
||||
Line: 3,
|
||||
},
|
||||
FromLinter: "varcheck",
|
||||
},
|
||||
{
|
||||
Pos: token.Position{
|
||||
Filename: fileName,
|
||||
Line: 6,
|
||||
},
|
||||
FromLinter: "deadcode",
|
||||
},
|
||||
}
|
||||
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
log := getOkLogger(ctrl)
|
||||
log.EXPECT().Warnf("Found unknown linters in //nolint directives: %s", "bad1, bad2")
|
||||
|
||||
p := newTestNolintProcessor(log)
|
||||
processAssertEmpty(t, p, issues...)
|
||||
p.Finish()
|
||||
}
|
||||
|
||||
func TestNolintAliases(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
p := newTestNolintProcessor(getOkLogger(ctrl))
|
||||
for _, line := range []int{47, 49, 51} {
|
||||
t.Run(fmt.Sprintf("line-%d", line), func(t *testing.T) {
|
||||
processAssertEmpty(t, p, newNolintFileIssue(line, "gosec"))
|
||||
})
|
||||
}
|
||||
p.Finish()
|
||||
}
|
||||
|
||||
func TestIgnoredRangeMatches(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue