dev: refactor .golangci.yml configuration and fix up nolintlint issues (#4537)
This commit is contained in:
parent
02ea91d77e
commit
6709c974a4
@ -17,13 +17,15 @@ linters-settings:
|
|||||||
logger:
|
logger:
|
||||||
deny:
|
deny:
|
||||||
# logging is allowed only by logutils.Log,
|
# logging is allowed only by logutils.Log,
|
||||||
# logrus is allowed to use only in logutils package.
|
|
||||||
- pkg: "github.com/sirupsen/logrus"
|
- pkg: "github.com/sirupsen/logrus"
|
||||||
desc: logging is allowed only by logutils.Log.
|
desc: logging is allowed only by logutils.Log.
|
||||||
- pkg: "github.com/pkg/errors"
|
- pkg: "github.com/pkg/errors"
|
||||||
desc: Should be replaced by standard lib errors package.
|
desc: Should be replaced by standard lib errors package.
|
||||||
- pkg: "github.com/instana/testify"
|
- pkg: "github.com/instana/testify"
|
||||||
desc: It's a fork of github.com/stretchr/testify.
|
desc: It's a fork of github.com/stretchr/testify.
|
||||||
|
files:
|
||||||
|
# logrus is allowed to use only in logutils package.
|
||||||
|
- "!**/pkg/logutils/**.go"
|
||||||
dupl:
|
dupl:
|
||||||
threshold: 100
|
threshold: 100
|
||||||
funlen:
|
funlen:
|
||||||
@ -86,10 +88,12 @@ linters-settings:
|
|||||||
line-length: 140
|
line-length: 140
|
||||||
misspell:
|
misspell:
|
||||||
locale: US
|
locale: US
|
||||||
|
ignore-words:
|
||||||
|
- "importas" # linter name
|
||||||
nolintlint:
|
nolintlint:
|
||||||
allow-unused: false # report any unused nolint directives
|
allow-unused: false # report any unused nolint directives
|
||||||
require-explanation: false # don't require an explanation for nolint directives
|
require-explanation: true # require an explanation for nolint directives
|
||||||
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
|
require-specific: true # require nolint directives to be specific about which linter is being skipped
|
||||||
revive:
|
revive:
|
||||||
rules:
|
rules:
|
||||||
- name: unexported-return
|
- name: unexported-return
|
||||||
@ -144,7 +148,9 @@ issues:
|
|||||||
exclude-rules:
|
exclude-rules:
|
||||||
- path: _test\.go
|
- path: _test\.go
|
||||||
linters:
|
linters:
|
||||||
|
- dupl
|
||||||
- gomnd
|
- gomnd
|
||||||
|
- lll
|
||||||
|
|
||||||
- path: pkg/golinters/errcheck.go
|
- path: pkg/golinters/errcheck.go
|
||||||
linters: [staticcheck]
|
linters: [staticcheck]
|
||||||
@ -158,6 +164,10 @@ issues:
|
|||||||
- path: pkg/golinters/govet.go
|
- path: pkg/golinters/govet.go
|
||||||
text: "SA1019: cfg.CheckShadowing is deprecated: the linter should be enabled inside `Enable`."
|
text: "SA1019: cfg.CheckShadowing is deprecated: the linter should be enabled inside `Enable`."
|
||||||
|
|
||||||
|
- path: pkg/golinters
|
||||||
|
linters:
|
||||||
|
- dupl
|
||||||
|
|
||||||
- path: pkg/golinters/gofumpt.go
|
- path: pkg/golinters/gofumpt.go
|
||||||
linters: [staticcheck]
|
linters: [staticcheck]
|
||||||
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead."
|
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead."
|
||||||
|
@ -80,7 +80,7 @@ func setupOutputFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
|
|||||||
internal.AddFlagAndBind(v, fs, fs.Bool, "show-stats", "output.show-stats", false, color.GreenString("Show statistics per linter"))
|
internal.AddFlagAndBind(v, fs, fs.Bool, "show-stats", "output.show-stats", false, color.GreenString("Show statistics per linter"))
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gomnd
|
//nolint:gomnd // magic numbers here is ok
|
||||||
func setupIssuesFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
|
func setupIssuesFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
|
||||||
internal.AddHackedStringSliceP(fs, "exclude", "e", color.GreenString("Exclude issue by regexp"))
|
internal.AddHackedStringSliceP(fs, "exclude", "e", color.GreenString("Exclude issue by regexp"))
|
||||||
internal.AddFlagAndBind(v, fs, fs.Bool, "exclude-use-default", "issues.exclude-use-default", true,
|
internal.AddFlagAndBind(v, fs, fs.Bool, "exclude-use-default", "issues.exclude-use-default", true,
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
const dogsledName = "dogsled"
|
const dogsledName = "dogsled"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewDogsled(settings *config.DogsledSettings) *goanalysis.Linter {
|
func NewDogsled(settings *config.DogsledSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -17,7 +17,6 @@ import (
|
|||||||
|
|
||||||
const duplName = "dupl"
|
const duplName = "dupl"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewDupl(settings *config.DuplSettings) *goanalysis.Linter {
|
func NewDupl(settings *config.DuplSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
const forbidigoName = "forbidigo"
|
const forbidigoName = "forbidigo"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewForbidigo(settings *config.ForbidigoSettings) *goanalysis.Linter {
|
func NewForbidigo(settings *config.ForbidigoSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
const funlenName = "funlen"
|
const funlenName = "funlen"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewFunlen(settings *config.FunlenSettings) *goanalysis.Linter {
|
func NewFunlen(settings *config.FunlenSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -177,10 +177,9 @@ func (r *runner) buildActionFactDeps(act *action, a *analysis.Analyzer, pkg *pac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gocritic
|
|
||||||
func (r *runner) prepareAnalysis(pkgs []*packages.Package,
|
func (r *runner) prepareAnalysis(pkgs []*packages.Package,
|
||||||
analyzers []*analysis.Analyzer,
|
analyzers []*analysis.Analyzer,
|
||||||
) (map[*packages.Package]bool, []*action, []*action) {
|
) (initialPkgs map[*packages.Package]bool, allActions, roots []*action) {
|
||||||
// Construct the action graph.
|
// Construct the action graph.
|
||||||
|
|
||||||
// Each graph node (action) is one unit of analysis.
|
// Each graph node (action) is one unit of analysis.
|
||||||
@ -200,13 +199,13 @@ func (r *runner) prepareAnalysis(pkgs []*packages.Package,
|
|||||||
actions := make(map[actKey]*action, totalActionsCount)
|
actions := make(map[actKey]*action, totalActionsCount)
|
||||||
actAlloc := newActionAllocator(totalActionsCount)
|
actAlloc := newActionAllocator(totalActionsCount)
|
||||||
|
|
||||||
initialPkgs := make(map[*packages.Package]bool, len(pkgs))
|
initialPkgs = make(map[*packages.Package]bool, len(pkgs))
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
initialPkgs[pkg] = true
|
initialPkgs[pkg] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build nodes for initial packages.
|
// Build nodes for initial packages.
|
||||||
roots := make([]*action, 0, len(pkgs)*len(analyzers))
|
roots = make([]*action, 0, len(pkgs)*len(analyzers))
|
||||||
for _, a := range analyzers {
|
for _, a := range analyzers {
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
root := r.makeAction(a, pkg, initialPkgs, actions, actAlloc)
|
root := r.makeAction(a, pkg, initialPkgs, actions, actAlloc)
|
||||||
@ -215,7 +214,7 @@ func (r *runner) prepareAnalysis(pkgs []*packages.Package,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allActions := maps.Values(actions)
|
allActions = maps.Values(actions)
|
||||||
|
|
||||||
debugf("Built %d actions", len(actions))
|
debugf("Built %d actions", len(actions))
|
||||||
|
|
||||||
@ -281,7 +280,6 @@ func (r *runner) analyze(pkgs []*packages.Package, analyzers []*analysis.Analyze
|
|||||||
return rootActions
|
return rootActions
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:nakedret
|
|
||||||
func extractDiagnostics(roots []*action) (retDiags []Diagnostic, retErrors []error) {
|
func extractDiagnostics(roots []*action) (retDiags []Diagnostic, retErrors []error) {
|
||||||
extracted := make(map[*action]bool)
|
extracted := make(map[*action]bool)
|
||||||
var extract func(*action)
|
var extract func(*action)
|
||||||
@ -338,5 +336,5 @@ func extractDiagnostics(roots []*action) (retDiags []Diagnostic, retErrors []err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
visitAll(roots)
|
visitAll(roots)
|
||||||
return
|
return retDiags, retErrors
|
||||||
}
|
}
|
||||||
|
@ -184,10 +184,9 @@ func saveIssuesToCache(allPkgs []*packages.Package, pkgsFromCache map[*packages.
|
|||||||
issuesCacheDebugf("Saved %d issues from %d packages to cache in %s", savedIssuesCount, len(allPkgs), time.Since(startedAt))
|
issuesCacheDebugf("Saved %d issues from %d packages to cache in %s", savedIssuesCount, len(allPkgs), time.Since(startedAt))
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gocritic
|
|
||||||
func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context,
|
func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context,
|
||||||
analyzers []*analysis.Analyzer,
|
analyzers []*analysis.Analyzer,
|
||||||
) ([]result.Issue, map[*packages.Package]bool) {
|
) (issuesFromCache []result.Issue, pkgsFromCache map[*packages.Package]bool) {
|
||||||
startedAt := time.Now()
|
startedAt := time.Now()
|
||||||
|
|
||||||
lintResKey := getIssuesCacheKey(analyzers)
|
lintResKey := getIssuesCacheKey(analyzers)
|
||||||
@ -221,17 +220,18 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
issues := make([]result.Issue, 0, len(pkgIssues))
|
issues := make([]result.Issue, 0, len(pkgIssues))
|
||||||
for _, i := range pkgIssues {
|
for i := range pkgIssues {
|
||||||
|
issue := &pkgIssues[i]
|
||||||
issues = append(issues, result.Issue{
|
issues = append(issues, result.Issue{
|
||||||
FromLinter: i.FromLinter,
|
FromLinter: issue.FromLinter,
|
||||||
Text: i.Text,
|
Text: issue.Text,
|
||||||
Severity: i.Severity,
|
Severity: issue.Severity,
|
||||||
Pos: i.Pos,
|
Pos: issue.Pos,
|
||||||
LineRange: i.LineRange,
|
LineRange: issue.LineRange,
|
||||||
Replacement: i.Replacement,
|
Replacement: issue.Replacement,
|
||||||
Pkg: pkg,
|
Pkg: pkg,
|
||||||
ExpectNoLint: i.ExpectNoLint,
|
ExpectNoLint: issue.ExpectNoLint,
|
||||||
ExpectedNoLintLinter: i.ExpectedNoLintLinter,
|
ExpectedNoLintLinter: issue.ExpectedNoLintLinter,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
cacheRes.issues = issues
|
cacheRes.issues = issues
|
||||||
@ -246,13 +246,12 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context,
|
|||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
loadedIssuesCount := 0
|
loadedIssuesCount := 0
|
||||||
var issues []result.Issue
|
pkgsFromCache = map[*packages.Package]bool{}
|
||||||
pkgsFromCache := map[*packages.Package]bool{}
|
|
||||||
for pkg, cacheRes := range pkgToCacheRes {
|
for pkg, cacheRes := range pkgToCacheRes {
|
||||||
if cacheRes.loadErr == nil {
|
if cacheRes.loadErr == nil {
|
||||||
loadedIssuesCount += len(cacheRes.issues)
|
loadedIssuesCount += len(cacheRes.issues)
|
||||||
pkgsFromCache[pkg] = true
|
pkgsFromCache[pkg] = true
|
||||||
issues = append(issues, cacheRes.issues...)
|
issuesFromCache = append(issuesFromCache, cacheRes.issues...)
|
||||||
issuesCacheDebugf("Loaded package %s issues (%d) from cache", pkg, len(cacheRes.issues))
|
issuesCacheDebugf("Loaded package %s issues (%d) from cache", pkg, len(cacheRes.issues))
|
||||||
} else {
|
} else {
|
||||||
issuesCacheDebugf("Didn't load package %s issues from cache: %s", pkg, cacheRes.loadErr)
|
issuesCacheDebugf("Didn't load package %s issues from cache: %s", pkg, cacheRes.loadErr)
|
||||||
@ -260,7 +259,7 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context,
|
|||||||
}
|
}
|
||||||
issuesCacheDebugf("Loaded %d issues from cache in %s, analyzing %d/%d packages",
|
issuesCacheDebugf("Loaded %d issues from cache in %s, analyzing %d/%d packages",
|
||||||
loadedIssuesCount, time.Since(startedAt), len(pkgs)-len(pkgsFromCache), len(pkgs))
|
loadedIssuesCount, time.Since(startedAt), len(pkgs)-len(pkgsFromCache), len(pkgs))
|
||||||
return issues, pkgsFromCache
|
return issuesFromCache, pkgsFromCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func analyzersHashID(analyzers []*analysis.Analyzer) string {
|
func analyzersHashID(analyzers []*analysis.Analyzer) string {
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
const gocognitName = "gocognit"
|
const gocognitName = "gocognit"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewGocognit(settings *config.GocognitSettings) *goanalysis.Linter {
|
func NewGocognit(settings *config.GocognitSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
|
|
||||||
const goconstName = "goconst"
|
const goconstName = "goconst"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewGoconst(settings *config.GoConstSettings) *goanalysis.Linter {
|
func NewGoconst(settings *config.GoConstSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
|
|
||||||
const gocycloName = "gocyclo"
|
const gocycloName = "gocyclo"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewGocyclo(settings *config.GoCycloSettings) *goanalysis.Linter {
|
func NewGocyclo(settings *config.GoCycloSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
const godoxName = "godox"
|
const godoxName = "godox"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewGodox(settings *config.GodoxSettings) *goanalysis.Linter {
|
func NewGodox(settings *config.GodoxSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -133,8 +133,8 @@ func (p *hunkChangesParser) handleDeletedLines(deletedLines []diffLine, addedLin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(addedLines) != 0 {
|
if len(addedLines) != 0 {
|
||||||
//nolint:gocritic
|
change.Replacement.NewLines = append([]string{}, p.replacementLinesToPrepend...)
|
||||||
change.Replacement.NewLines = append(p.replacementLinesToPrepend, addedLines...)
|
change.Replacement.NewLines = append(change.Replacement.NewLines, addedLines...)
|
||||||
if len(p.replacementLinesToPrepend) != 0 {
|
if len(p.replacementLinesToPrepend) != 0 {
|
||||||
p.replacementLinesToPrepend = nil
|
p.replacementLinesToPrepend = nil
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/julz/importas" //nolint:misspell
|
"github.com/julz/importas"
|
||||||
"golang.org/x/tools/go/analysis"
|
"golang.org/x/tools/go/analysis"
|
||||||
|
|
||||||
"github.com/golangci/golangci-lint/pkg/config"
|
"github.com/golangci/golangci-lint/pkg/config"
|
||||||
@ -26,7 +26,7 @@ func NewImportAs(settings *config.ImportAsSettings) *goanalysis.Linter {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(settings.Alias) == 0 {
|
if len(settings.Alias) == 0 {
|
||||||
lintCtx.Log.Infof("importas settings found, but no aliases listed. List aliases under alias: key.") //nolint:misspell
|
lintCtx.Log.Infof("importas settings found, but no aliases listed. List aliases under alias: key.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := analyzer.Flags.Set("no-unaliased", strconv.FormatBool(settings.NoUnaliased)); err != nil {
|
if err := analyzer.Flags.Set("no-unaliased", strconv.FormatBool(settings.NoUnaliased)); err != nil {
|
||||||
|
@ -22,7 +22,6 @@ const lllName = "lll"
|
|||||||
|
|
||||||
const goCommentDirectivePrefix = "//go:"
|
const goCommentDirectivePrefix = "//go:"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewLLL(settings *config.LllSettings) *goanalysis.Linter {
|
func NewLLL(settings *config.LllSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
|
|
||||||
const makezeroName = "makezero"
|
const makezeroName = "makezero"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewMakezero(settings *config.MakezeroSettings) *goanalysis.Linter {
|
func NewMakezero(settings *config.MakezeroSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
|
|
||||||
const nestifName = "nestif"
|
const nestifName = "nestif"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewNestif(settings *config.NestifSettings) *goanalysis.Linter {
|
func NewNestif(settings *config.NestifSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
const NoLintLintName = "nolintlint"
|
const NoLintLintName = "nolintlint"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewNoLintLint(settings *config.NoLintLintSettings) *goanalysis.Linter {
|
func NewNoLintLint(settings *config.NoLintLintSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -156,7 +156,7 @@ var (
|
|||||||
trailingBlankExplanation = regexp.MustCompile(`\s*(//\s*)?$`)
|
trailingBlankExplanation = regexp.MustCompile(`\s*(//\s*)?$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint:funlen,gocyclo
|
//nolint:funlen,gocyclo // the function is going to be refactored in the future
|
||||||
func (l Linter) Run(fset *token.FileSet, nodes ...ast.Node) ([]Issue, error) {
|
func (l Linter) Run(fset *token.FileSet, nodes ...ast.Node) ([]Issue, error) {
|
||||||
var issues []Issue
|
var issues []Issue
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ func foo() {
|
|||||||
good() //nolint: linter1, linter2
|
good() //nolint: linter1, linter2
|
||||||
}`,
|
}`,
|
||||||
expected: []issueWithReplacement{
|
expected: []issueWithReplacement{
|
||||||
{issue: "directive `//nolint:linter1 linter2` should match `//nolint[:<comma-separated-linters>] [// <explanation>]` at testing.go:6:9"}, //nolint:lll // this is a string
|
{issue: "directive `//nolint:linter1 linter2` should match `//nolint[:<comma-separated-linters>] [// <explanation>]` at testing.go:6:9"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
|
|
||||||
const preallocName = "prealloc"
|
const preallocName = "prealloc"
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
func NewPreAlloc(settings *config.PreallocSettings) *goanalysis.Linter {
|
func NewPreAlloc(settings *config.PreallocSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
|
|
||||||
const unconvertName = "unconvert"
|
const unconvertName = "unconvert"
|
||||||
|
|
||||||
//nolint:dupl // This is not a duplicate of dogsled.
|
|
||||||
func NewUnconvert(settings *config.UnconvertSettings) *goanalysis.Linter {
|
func NewUnconvert(settings *config.UnconvertSettings) *goanalysis.Linter {
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var resIssues []goanalysis.Issue
|
var resIssues []goanalysis.Issue
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus" //nolint:depguard
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/golangci/golangci-lint/pkg/exitcodes"
|
"github.com/golangci/golangci-lint/pkg/exitcodes"
|
||||||
)
|
)
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint:lll
|
|
||||||
func Test_stackCrusher(t *testing.T) {
|
func Test_stackCrusher(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
|
@ -49,7 +49,6 @@ func TestCheckstyle_Print(t *testing.T) {
|
|||||||
err := printer.Print(issues)
|
err := printer.Print(issues)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
//nolint:lll
|
|
||||||
expected := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<checkstyle version=\"5.0\">\n <file name=\"path/to/filea.go\">\n <error column=\"4\" line=\"10\" message=\"some issue\" severity=\"warning\" source=\"linter-a\"></error>\n </file>\n <file name=\"path/to/fileb.go\">\n <error column=\"9\" line=\"300\" message=\"another issue\" severity=\"error\" source=\"linter-b\"></error>\n </file>\n</checkstyle>\n"
|
expected := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<checkstyle version=\"5.0\">\n <file name=\"path/to/filea.go\">\n <error column=\"4\" line=\"10\" message=\"some issue\" severity=\"warning\" source=\"linter-a\"></error>\n </file>\n <file name=\"path/to/fileb.go\">\n <error column=\"9\" line=\"300\" message=\"another issue\" severity=\"error\" source=\"linter-b\"></error>\n </file>\n</checkstyle>\n"
|
||||||
|
|
||||||
assert.Equal(t, expected, strings.ReplaceAll(buf.String(), "\r", ""))
|
assert.Equal(t, expected, strings.ReplaceAll(buf.String(), "\r", ""))
|
||||||
|
@ -63,7 +63,6 @@ func TestCodeClimate_Print(t *testing.T) {
|
|||||||
err := printer.Print(issues)
|
err := printer.Print(issues)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
//nolint:lll
|
|
||||||
expected := `[{"description":"linter-a: some issue","severity":"warning","fingerprint":"BA73C5DF4A6FD8462FFF1D3140235777","location":{"path":"path/to/filea.go","lines":{"begin":10}}},{"description":"linter-b: another issue","severity":"error","fingerprint":"0777B4FE60242BD8B2E9B7E92C4B9521","location":{"path":"path/to/fileb.go","lines":{"begin":300}}},{"description":"linter-c: issue c","severity":"critical","fingerprint":"BEE6E9FBB6BFA4B7DB9FB036697FB036","location":{"path":"path/to/filec.go","lines":{"begin":200}}}]
|
expected := `[{"description":"linter-a: some issue","severity":"warning","fingerprint":"BA73C5DF4A6FD8462FFF1D3140235777","location":{"path":"path/to/filea.go","lines":{"begin":10}}},{"description":"linter-b: another issue","severity":"error","fingerprint":"0777B4FE60242BD8B2E9B7E92C4B9521","location":{"path":"path/to/fileb.go","lines":{"begin":300}}},{"description":"linter-c: issue c","severity":"critical","fingerprint":"BEE6E9FBB6BFA4B7DB9FB036697FB036","location":{"path":"path/to/filec.go","lines":{"begin":200}}}]
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
//nolint:dupl
|
|
||||||
package printers
|
package printers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/golangci/golangci-lint/pkg/result"
|
"github.com/golangci/golangci-lint/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint:lll
|
|
||||||
const expectedHTML = `<!doctype html>
|
const expectedHTML = `<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
@ -49,7 +49,6 @@ func TestJSON_Print(t *testing.T) {
|
|||||||
err := printer.Print(issues)
|
err := printer.Print(issues)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
//nolint:lll
|
|
||||||
expected := `{"Issues":[{"FromLinter":"linter-a","Text":"some issue","Severity":"warning","SourceLines":null,"Replacement":null,"Pos":{"Filename":"path/to/filea.go","Offset":2,"Line":10,"Column":4},"ExpectNoLint":false,"ExpectedNoLintLinter":""},{"FromLinter":"linter-b","Text":"another issue","Severity":"error","SourceLines":["func foo() {","\tfmt.Println(\"bar\")","}"],"Replacement":null,"Pos":{"Filename":"path/to/fileb.go","Offset":5,"Line":300,"Column":9},"ExpectNoLint":false,"ExpectedNoLintLinter":""}],"Report":null}
|
expected := `{"Issues":[{"FromLinter":"linter-a","Text":"some issue","Severity":"warning","SourceLines":null,"Replacement":null,"Pos":{"Filename":"path/to/filea.go","Offset":2,"Line":10,"Column":4},"ExpectNoLint":false,"ExpectedNoLintLinter":""},{"FromLinter":"linter-b","Text":"another issue","Severity":"error","SourceLines":["func foo() {","\tfmt.Println(\"bar\")","}"],"Replacement":null,"Pos":{"Filename":"path/to/fileb.go","Offset":5,"Line":300,"Column":9},"ExpectNoLint":false,"ExpectedNoLintLinter":""}],"Report":null}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
//nolint:dupl
|
|
||||||
package printers
|
package printers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -77,7 +77,6 @@ path/to/fileb.go:300:9 another issue
|
|||||||
desc: "enable all options",
|
desc: "enable all options",
|
||||||
printLinterName: true,
|
printLinterName: true,
|
||||||
useColors: true,
|
useColors: true,
|
||||||
//nolint:lll // color characters must be in a simple string.
|
|
||||||
expected: "\x1b[1mpath/to/filea.go:10\x1b[22m:4 linter-a \x1b[31msome issue\x1b[0m\n\x1b[1mpath/to/fileb.go:300\x1b[22m:9 linter-b \x1b[31manother issue\x1b[0m\n",
|
expected: "\x1b[1mpath/to/filea.go:10\x1b[22m:4 linter-a \x1b[31msome issue\x1b[0m\n\x1b[1mpath/to/fileb.go:300\x1b[22m:9 linter-b \x1b[31manother issue\x1b[0m\n",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,6 @@ func foo() {
|
|||||||
printIssuedLine: true,
|
printIssuedLine: true,
|
||||||
printLinterName: true,
|
printLinterName: true,
|
||||||
useColors: true,
|
useColors: true,
|
||||||
//nolint:lll // color characters must be in a simple string.
|
|
||||||
expected: "\x1b[1mpath/to/filea.go:10\x1b[22m:4: \x1b[31msome issue\x1b[0m (linter-a)\n\x1b[1mpath/to/fileb.go:300\x1b[22m:9: \x1b[31manother issue\x1b[0m (linter-b)\nfunc foo() {\n\tfmt.Println(\"bar\")\n}\n",
|
expected: "\x1b[1mpath/to/filea.go:10\x1b[22m:4: \x1b[31msome issue\x1b[0m (linter-a)\n\x1b[1mpath/to/fileb.go:300\x1b[22m:9: \x1b[31manother issue\x1b[0m (linter-b)\nfunc foo() {\n\tfmt.Println(\"bar\")\n}\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package result
|
package result
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5" //nolint:gosec
|
"crypto/md5" //nolint:gosec // for md5 hash
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/token"
|
"go/token"
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ func (i *Issue) Fingerprint() string {
|
|||||||
firstLine = i.SourceLines[0]
|
firstLine = i.SourceLines[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
hash := md5.New() //nolint:gosec
|
hash := md5.New() //nolint:gosec // we don't need a strong hash here
|
||||||
_, _ = fmt.Fprintf(hash, "%s%s%s", i.Pos.Filename, i.Text, firstLine)
|
_, _ = fmt.Fprintf(hash, "%s%s%s", i.Pos.Filename, i.Text, firstLine)
|
||||||
|
|
||||||
return fmt.Sprintf("%X", hash.Sum(nil))
|
return fmt.Sprintf("%X", hash.Sum(nil))
|
||||||
|
@ -65,7 +65,7 @@ func (r *baseRule) matchLinter(issue *result.Issue) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *baseRule) matchSource(issue *result.Issue, lineCache *fsutils.LineCache, log logutils.Log) bool { //nolint:interfacer
|
func (r *baseRule) matchSource(issue *result.Issue, lineCache *fsutils.LineCache, log logutils.Log) bool {
|
||||||
sourceLine, errSourceLine := lineCache.GetLine(issue.FilePath(), issue.Line())
|
sourceLine, errSourceLine := lineCache.GetLine(issue.FilePath(), issue.Line())
|
||||||
if errSourceLine != nil {
|
if errSourceLine != nil {
|
||||||
log.Warnf("Failed to get line %s:%d from line cache: %s", issue.FilePath(), issue.Line(), errSourceLine)
|
log.Warnf("Failed to get line %s:%d from line cache: %s", issue.FilePath(), issue.Line(), errSourceLine)
|
||||||
|
@ -50,7 +50,6 @@ func TestExcludeRules_multiple(t *testing.T) {
|
|||||||
|
|
||||||
p := NewExcludeRules(nil, files, opts)
|
p := NewExcludeRules(nil, files, opts)
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
cases := []issueTestCase{
|
cases := []issueTestCase{
|
||||||
{Path: "e.go", Text: "exclude", Linter: "linter"},
|
{Path: "e.go", Text: "exclude", Linter: "linter"},
|
||||||
{Path: "e.go", Text: "some", Linter: "linter"},
|
{Path: "e.go", Text: "some", Linter: "linter"},
|
||||||
@ -210,7 +209,6 @@ func TestExcludeRules_caseSensitive_multiple(t *testing.T) {
|
|||||||
|
|
||||||
p := NewExcludeRules(nil, files, opts)
|
p := NewExcludeRules(nil, files, opts)
|
||||||
|
|
||||||
//nolint:dupl
|
|
||||||
cases := []issueTestCase{
|
cases := []issueTestCase{
|
||||||
{Path: "e.go", Text: "exclude", Linter: "linter"},
|
{Path: "e.go", Text: "exclude", Linter: "linter"},
|
||||||
{Path: "e.go", Text: "excLude", Linter: "linter"},
|
{Path: "e.go", Text: "excLude", Linter: "linter"},
|
||||||
|
@ -164,7 +164,7 @@ func (f Fixer) applyInlineFixes(lineIssues []result.Issue, origLine []byte, line
|
|||||||
var newLineBuf bytes.Buffer
|
var newLineBuf bytes.Buffer
|
||||||
newLineBuf.Grow(len(origLine))
|
newLineBuf.Grow(len(origLine))
|
||||||
|
|
||||||
//nolint:misspell
|
//nolint:misspell // misspelling is intentional
|
||||||
// example: origLine="it's becouse of them", StartCol=5, Length=7, NewString="because"
|
// example: origLine="it's becouse of them", StartCol=5, Length=7, NewString="because"
|
||||||
|
|
||||||
curOrigLinePos := 0
|
curOrigLinePos := 0
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestIdentifierMarker(t *testing.T) {
|
func TestIdentifierMarker(t *testing.T) {
|
||||||
//nolint:lll
|
|
||||||
cases := []struct{ in, out string }{
|
cases := []struct{ in, out string }{
|
||||||
{"unknown field Address in struct literal", "unknown field `Address` in struct literal"},
|
{"unknown field Address in struct literal", "unknown field `Address` in struct literal"},
|
||||||
{
|
{
|
||||||
|
@ -104,7 +104,7 @@ func TestCompareByLine(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompareByFileName(t *testing.T) { //nolint:dupl
|
func TestCompareByFileName(t *testing.T) {
|
||||||
testCompareValues(t, byFileName(), "Compare By File Name", []compareTestCase{
|
testCompareValues(t, byFileName(), "Compare By File Name", []compareTestCase{
|
||||||
{issues[0], issues[1], greater}, // file_windows.go vs file_linux.go
|
{issues[0], issues[1], greater}, // file_windows.go vs file_linux.go
|
||||||
{issues[1], issues[2], greater}, // file_linux.go vs file_darwin.go
|
{issues[1], issues[2], greater}, // file_linux.go vs file_darwin.go
|
||||||
@ -119,7 +119,7 @@ func TestCompareByFileName(t *testing.T) { //nolint:dupl
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompareByColumn(t *testing.T) { //nolint:dupl
|
func TestCompareByColumn(t *testing.T) {
|
||||||
testCompareValues(t, byColumn(), "Compare By Column", []compareTestCase{
|
testCompareValues(t, byColumn(), "Compare By Column", []compareTestCase{
|
||||||
{issues[0], issues[1], greater}, // 80 vs 70
|
{issues[0], issues[1], greater}, // 80 vs 70
|
||||||
{issues[1], issues[2], none}, // 70 vs zero value
|
{issues[1], issues[2], none}, // 70 vs zero value
|
||||||
@ -134,7 +134,7 @@ func TestCompareByColumn(t *testing.T) { //nolint:dupl
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompareByLinter(t *testing.T) { //nolint:dupl
|
func TestCompareByLinter(t *testing.T) {
|
||||||
testCompareValues(t, byLinter(), "Compare By Linter", []compareTestCase{
|
testCompareValues(t, byLinter(), "Compare By Linter", []compareTestCase{
|
||||||
{issues[0], issues[1], greater}, // b vs a
|
{issues[0], issues[1], greater}, // b vs a
|
||||||
{issues[1], issues[2], less}, // a vs c
|
{issues[1], issues[2], less}, // a vs c
|
||||||
|
@ -96,7 +96,7 @@ type latestRelease struct {
|
|||||||
func getLatestVersion() (string, error) {
|
func getLatestVersion() (string, error) {
|
||||||
endpoint := "https://api.github.com/repos/golangci/golangci-lint/releases/latest"
|
endpoint := "https://api.github.com/repos/golangci/golangci-lint/releases/latest"
|
||||||
|
|
||||||
//nolint:noctx
|
//nolint:noctx // request timeout handled by the client
|
||||||
req, err := http.NewRequest(http.MethodGet, endpoint, http.NoBody)
|
req, err := http.NewRequest(http.MethodGet, endpoint, http.NoBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("prepare a HTTP request: %w", err)
|
return "", fmt.Errorf("prepare a HTTP request: %w", err)
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/golangci/golangci-lint/test/testshared"
|
"github.com/golangci/golangci-lint/test/testshared"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint:misspell,lll
|
//nolint:misspell // misspelling is intentional
|
||||||
const expectedJSONOutput = `{"Issues":[{"FromLinter":"misspell","Text":"` + "`" + `occured` + "`" + ` is a misspelling of ` + "`" + `occurred` + "`" + `","Severity":"","SourceLines":["\t// comment with incorrect spelling: occured // want \"` + "`" + `occured` + "`" + ` is a misspelling of ` + "`" + `occurred` + "`" + `\""],"Replacement":{"NeedOnlyDelete":false,"NewLines":null,"Inline":{"StartCol":37,"Length":7,"NewString":"occurred"}},"Pos":{"Filename":"testdata/misspell.go","Offset":0,"Line":6,"Column":38},"ExpectNoLint":false,"ExpectedNoLintLinter":""}]`
|
const expectedJSONOutput = `{"Issues":[{"FromLinter":"misspell","Text":"` + "`" + `occured` + "`" + ` is a misspelling of ` + "`" + `occurred` + "`" + `","Severity":"","SourceLines":["\t// comment with incorrect spelling: occured // want \"` + "`" + `occured` + "`" + ` is a misspelling of ` + "`" + `occurred` + "`" + `\""],"Replacement":{"NeedOnlyDelete":false,"NewLines":null,"Inline":{"StartCol":37,"Length":7,"NewString":"occurred"}},"Pos":{"Filename":"testdata/misspell.go","Offset":0,"Line":6,"Column":38},"ExpectNoLint":false,"ExpectedNoLintLinter":""}]`
|
||||||
|
|
||||||
func TestOutput_lineNumber(t *testing.T) {
|
func TestOutput_lineNumber(t *testing.T) {
|
||||||
@ -30,7 +30,7 @@ func TestOutput_lineNumber(t *testing.T) {
|
|||||||
Runner().
|
Runner().
|
||||||
Install().
|
Install().
|
||||||
Run().
|
Run().
|
||||||
//nolint:misspell
|
//nolint:misspell // misspelling is intentional
|
||||||
ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`")
|
ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ func TestOutput_Multiple(t *testing.T) {
|
|||||||
Runner().
|
Runner().
|
||||||
Install().
|
Install().
|
||||||
Run().
|
Run().
|
||||||
//nolint:misspell
|
//nolint:misspell // misspelling is intentional
|
||||||
ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`").
|
ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`").
|
||||||
ExpectOutputContains(testshared.NormalizeFilePathInJSON(expectedJSONOutput))
|
ExpectOutputContains(testshared.NormalizeFilePathInJSON(expectedJSONOutput))
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ type RunContext struct {
|
|||||||
|
|
||||||
// ParseTestDirectives parses test directives from sources files.
|
// ParseTestDirectives parses test directives from sources files.
|
||||||
//
|
//
|
||||||
//nolint:gocyclo,funlen
|
//nolint:funlen,gocyclo // can't be simplified without losing readability
|
||||||
func ParseTestDirectives(tb testing.TB, sourcePath string) *RunContext {
|
func ParseTestDirectives(tb testing.TB, sourcePath string) *RunContext {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
@ -108,7 +108,9 @@ func ParseTestDirectives(tb testing.TB, sourcePath string) *RunContext {
|
|||||||
if rc.ExpectedLinter == "" {
|
if rc.ExpectedLinter == "" {
|
||||||
for _, arg := range rc.Args {
|
for _, arg := range rc.Args {
|
||||||
if strings.HasPrefix(arg, "-E") && !strings.Contains(arg, ",") {
|
if strings.HasPrefix(arg, "-E") && !strings.Contains(arg, ",") {
|
||||||
require.Empty(tb, rc.ExpectedLinter, "could not infer expected linter for errors because multiple linters are enabled. Please use the `//golangcitest:expected_linter ` directive in your test to indicate the linter-under-test.") //nolint:lll
|
require.Empty(tb, rc.ExpectedLinter,
|
||||||
|
"could not infer expected linter for errors because multiple linters are enabled. "+
|
||||||
|
"Please use the `//golangcitest:expected_linter ` directive in your test to indicate the linter-under-test.")
|
||||||
rc.ExpectedLinter = arg[2:]
|
rc.ExpectedLinter = arg[2:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ func (r *Runner) Command() *exec.Cmd {
|
|||||||
|
|
||||||
runArgs := append([]string{r.command}, r.args...)
|
runArgs := append([]string{r.command}, r.args...)
|
||||||
|
|
||||||
//nolint:gosec
|
//nolint:gosec // we don't use user input here
|
||||||
cmd := exec.Command(r.binPath, runArgs...)
|
cmd := exec.Command(r.binPath, runArgs...)
|
||||||
cmd.Env = append(os.Environ(), r.env...)
|
cmd.Env = append(os.Environ(), r.env...)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user