diff --git a/.golangci.yml b/.golangci.yml index 937488d65bb0..a0146f2ca51c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,13 +17,15 @@ linters-settings: logger: deny: # logging is allowed only by logutils.Log, - # logrus is allowed to use only in logutils package. - pkg: "github.com/sirupsen/logrus" desc: logging is allowed only by logutils.Log. - pkg: "github.com/pkg/errors" desc: Should be replaced by standard lib errors package. - pkg: "github.com/instana/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: threshold: 100 funlen: @@ -86,10 +88,12 @@ linters-settings: line-length: 140 misspell: locale: US + ignore-words: + - "importas" # linter name nolintlint: allow-unused: false # report any unused nolint directives - require-explanation: false # don't require an explanation for nolint directives - require-specific: false # don't require nolint directives to be specific about which linter is being skipped + require-explanation: true # require an explanation for nolint directives + require-specific: true # require nolint directives to be specific about which linter is being skipped revive: rules: - name: unexported-return @@ -144,7 +148,9 @@ issues: exclude-rules: - path: _test\.go linters: + - dupl - gomnd + - lll - path: pkg/golinters/errcheck.go linters: [staticcheck] @@ -158,6 +164,10 @@ issues: - path: pkg/golinters/govet.go text: "SA1019: cfg.CheckShadowing is deprecated: the linter should be enabled inside `Enable`." + - path: pkg/golinters + linters: + - dupl + - path: pkg/golinters/gofumpt.go linters: [staticcheck] text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead." diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go index be541d12716c..af5c351c5e1c 100644 --- a/pkg/commands/flagsets.go +++ b/pkg/commands/flagsets.go @@ -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")) } -//nolint:gomnd +//nolint:gomnd // magic numbers here is ok func setupIssuesFlagSet(v *viper.Viper, fs *pflag.FlagSet) { 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, diff --git a/pkg/golinters/dogsled.go b/pkg/golinters/dogsled.go index 79502fe8be6c..de567ce7cf64 100644 --- a/pkg/golinters/dogsled.go +++ b/pkg/golinters/dogsled.go @@ -16,7 +16,6 @@ import ( const dogsledName = "dogsled" -//nolint:dupl func NewDogsled(settings *config.DogsledSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/dupl.go b/pkg/golinters/dupl.go index 5d772a5f2faa..eec51eabab72 100644 --- a/pkg/golinters/dupl.go +++ b/pkg/golinters/dupl.go @@ -17,7 +17,6 @@ import ( const duplName = "dupl" -//nolint:dupl func NewDupl(settings *config.DuplSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/forbidigo.go b/pkg/golinters/forbidigo.go index 6aced29226e1..797484ba2cc4 100644 --- a/pkg/golinters/forbidigo.go +++ b/pkg/golinters/forbidigo.go @@ -16,7 +16,6 @@ import ( const forbidigoName = "forbidigo" -//nolint:dupl func NewForbidigo(settings *config.ForbidigoSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/funlen.go b/pkg/golinters/funlen.go index 8def9c1f678a..d421e174b7fb 100644 --- a/pkg/golinters/funlen.go +++ b/pkg/golinters/funlen.go @@ -16,7 +16,6 @@ import ( const funlenName = "funlen" -//nolint:dupl func NewFunlen(settings *config.FunlenSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/goanalysis/runner.go b/pkg/golinters/goanalysis/runner.go index 8243c345278b..b75e3fa0f557 100644 --- a/pkg/golinters/goanalysis/runner.go +++ b/pkg/golinters/goanalysis/runner.go @@ -177,10 +177,9 @@ func (r *runner) buildActionFactDeps(act *action, a *analysis.Analyzer, pkg *pac } } -//nolint:gocritic func (r *runner) prepareAnalysis(pkgs []*packages.Package, analyzers []*analysis.Analyzer, -) (map[*packages.Package]bool, []*action, []*action) { +) (initialPkgs map[*packages.Package]bool, allActions, roots []*action) { // Construct the action graph. // 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) actAlloc := newActionAllocator(totalActionsCount) - initialPkgs := make(map[*packages.Package]bool, len(pkgs)) + initialPkgs = make(map[*packages.Package]bool, len(pkgs)) for _, pkg := range pkgs { initialPkgs[pkg] = true } // 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 _, pkg := range pkgs { 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)) @@ -281,7 +280,6 @@ func (r *runner) analyze(pkgs []*packages.Package, analyzers []*analysis.Analyze return rootActions } -//nolint:nakedret func extractDiagnostics(roots []*action) (retDiags []Diagnostic, retErrors []error) { extracted := make(map[*action]bool) var extract func(*action) @@ -338,5 +336,5 @@ func extractDiagnostics(roots []*action) (retDiags []Diagnostic, retErrors []err } } visitAll(roots) - return + return retDiags, retErrors } diff --git a/pkg/golinters/goanalysis/runners.go b/pkg/golinters/goanalysis/runners.go index c5a0b61261bf..b832fc32da6a 100644 --- a/pkg/golinters/goanalysis/runners.go +++ b/pkg/golinters/goanalysis/runners.go @@ -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)) } -//nolint:gocritic func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context, analyzers []*analysis.Analyzer, -) ([]result.Issue, map[*packages.Package]bool) { +) (issuesFromCache []result.Issue, pkgsFromCache map[*packages.Package]bool) { startedAt := time.Now() lintResKey := getIssuesCacheKey(analyzers) @@ -221,17 +220,18 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context, } issues := make([]result.Issue, 0, len(pkgIssues)) - for _, i := range pkgIssues { + for i := range pkgIssues { + issue := &pkgIssues[i] issues = append(issues, result.Issue{ - FromLinter: i.FromLinter, - Text: i.Text, - Severity: i.Severity, - Pos: i.Pos, - LineRange: i.LineRange, - Replacement: i.Replacement, + FromLinter: issue.FromLinter, + Text: issue.Text, + Severity: issue.Severity, + Pos: issue.Pos, + LineRange: issue.LineRange, + Replacement: issue.Replacement, Pkg: pkg, - ExpectNoLint: i.ExpectNoLint, - ExpectedNoLintLinter: i.ExpectedNoLintLinter, + ExpectNoLint: issue.ExpectNoLint, + ExpectedNoLintLinter: issue.ExpectedNoLintLinter, }) } cacheRes.issues = issues @@ -246,13 +246,12 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context, wg.Wait() loadedIssuesCount := 0 - var issues []result.Issue - pkgsFromCache := map[*packages.Package]bool{} + pkgsFromCache = map[*packages.Package]bool{} for pkg, cacheRes := range pkgToCacheRes { if cacheRes.loadErr == nil { loadedIssuesCount += len(cacheRes.issues) 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)) } else { 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", loadedIssuesCount, time.Since(startedAt), len(pkgs)-len(pkgsFromCache), len(pkgs)) - return issues, pkgsFromCache + return issuesFromCache, pkgsFromCache } func analyzersHashID(analyzers []*analysis.Analyzer) string { diff --git a/pkg/golinters/gocognit.go b/pkg/golinters/gocognit.go index 406d34ed6cb8..f5cff840e468 100644 --- a/pkg/golinters/gocognit.go +++ b/pkg/golinters/gocognit.go @@ -16,7 +16,6 @@ import ( const gocognitName = "gocognit" -//nolint:dupl func NewGocognit(settings *config.GocognitSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/goconst.go b/pkg/golinters/goconst.go index b5188527546b..204e2496a661 100644 --- a/pkg/golinters/goconst.go +++ b/pkg/golinters/goconst.go @@ -15,7 +15,6 @@ import ( const goconstName = "goconst" -//nolint:dupl func NewGoconst(settings *config.GoConstSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/gocyclo.go b/pkg/golinters/gocyclo.go index b502623ba620..63aefb09fe98 100644 --- a/pkg/golinters/gocyclo.go +++ b/pkg/golinters/gocyclo.go @@ -15,7 +15,6 @@ import ( const gocycloName = "gocyclo" -//nolint:dupl func NewGocyclo(settings *config.GoCycloSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/godox.go b/pkg/golinters/godox.go index 955810417dcb..208bade5764c 100644 --- a/pkg/golinters/godox.go +++ b/pkg/golinters/godox.go @@ -16,7 +16,6 @@ import ( const godoxName = "godox" -//nolint:dupl func NewGodox(settings *config.GodoxSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/gofmt_common.go b/pkg/golinters/gofmt_common.go index 6b7184d65bc1..afa7afbf899e 100644 --- a/pkg/golinters/gofmt_common.go +++ b/pkg/golinters/gofmt_common.go @@ -133,8 +133,8 @@ func (p *hunkChangesParser) handleDeletedLines(deletedLines []diffLine, addedLin } if len(addedLines) != 0 { - //nolint:gocritic - change.Replacement.NewLines = append(p.replacementLinesToPrepend, addedLines...) + change.Replacement.NewLines = append([]string{}, p.replacementLinesToPrepend...) + change.Replacement.NewLines = append(change.Replacement.NewLines, addedLines...) if len(p.replacementLinesToPrepend) != 0 { p.replacementLinesToPrepend = nil } diff --git a/pkg/golinters/importas.go b/pkg/golinters/importas.go index b06aec7a3b4b..a426333dbf06 100644 --- a/pkg/golinters/importas.go +++ b/pkg/golinters/importas.go @@ -5,7 +5,7 @@ import ( "strconv" "strings" - "github.com/julz/importas" //nolint:misspell + "github.com/julz/importas" "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/pkg/config" @@ -26,7 +26,7 @@ func NewImportAs(settings *config.ImportAsSettings) *goanalysis.Linter { return } 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 { diff --git a/pkg/golinters/lll.go b/pkg/golinters/lll.go index 61498087a93d..84ce61a9ee50 100644 --- a/pkg/golinters/lll.go +++ b/pkg/golinters/lll.go @@ -22,7 +22,6 @@ const lllName = "lll" const goCommentDirectivePrefix = "//go:" -//nolint:dupl func NewLLL(settings *config.LllSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/makezero.go b/pkg/golinters/makezero.go index a9828629a2e1..7a14c8e09dfc 100644 --- a/pkg/golinters/makezero.go +++ b/pkg/golinters/makezero.go @@ -15,7 +15,6 @@ import ( const makezeroName = "makezero" -//nolint:dupl func NewMakezero(settings *config.MakezeroSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/nestif.go b/pkg/golinters/nestif.go index 12ad69eceb39..4125ad9afcd9 100644 --- a/pkg/golinters/nestif.go +++ b/pkg/golinters/nestif.go @@ -15,7 +15,6 @@ import ( const nestifName = "nestif" -//nolint:dupl func NewNestif(settings *config.NestifSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/nolintlint.go b/pkg/golinters/nolintlint.go index ae372ab795b2..7000620d199b 100644 --- a/pkg/golinters/nolintlint.go +++ b/pkg/golinters/nolintlint.go @@ -16,7 +16,6 @@ import ( const NoLintLintName = "nolintlint" -//nolint:dupl func NewNoLintLint(settings *config.NoLintLintSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/nolintlint/nolintlint.go b/pkg/golinters/nolintlint/nolintlint.go index aadc7eb681fc..1bce5ef5d2d8 100644 --- a/pkg/golinters/nolintlint/nolintlint.go +++ b/pkg/golinters/nolintlint/nolintlint.go @@ -156,7 +156,7 @@ var ( 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) { var issues []Issue diff --git a/pkg/golinters/nolintlint/nolintlint_test.go b/pkg/golinters/nolintlint/nolintlint_test.go index 0400e8dfe623..a483c7ea66b1 100644 --- a/pkg/golinters/nolintlint/nolintlint_test.go +++ b/pkg/golinters/nolintlint/nolintlint_test.go @@ -131,7 +131,7 @@ func foo() { good() //nolint: linter1, linter2 }`, expected: []issueWithReplacement{ - {issue: "directive `//nolint:linter1 linter2` should match `//nolint[:] [// ]` at testing.go:6:9"}, //nolint:lll // this is a string + {issue: "directive `//nolint:linter1 linter2` should match `//nolint[:] [// ]` at testing.go:6:9"}, }, }, { diff --git a/pkg/golinters/prealloc.go b/pkg/golinters/prealloc.go index f48d57562ef2..4777614939bf 100644 --- a/pkg/golinters/prealloc.go +++ b/pkg/golinters/prealloc.go @@ -15,7 +15,6 @@ import ( const preallocName = "prealloc" -//nolint:dupl func NewPreAlloc(settings *config.PreallocSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/golinters/unconvert.go b/pkg/golinters/unconvert.go index 5f8c73182c57..08e493aef09f 100644 --- a/pkg/golinters/unconvert.go +++ b/pkg/golinters/unconvert.go @@ -14,7 +14,6 @@ import ( const unconvertName = "unconvert" -//nolint:dupl // This is not a duplicate of dogsled. func NewUnconvert(settings *config.UnconvertSettings) *goanalysis.Linter { var mu sync.Mutex var resIssues []goanalysis.Issue diff --git a/pkg/logutils/stderr_log.go b/pkg/logutils/stderr_log.go index 367c94f38529..569a177a7c5c 100644 --- a/pkg/logutils/stderr_log.go +++ b/pkg/logutils/stderr_log.go @@ -5,7 +5,7 @@ import ( "os" "time" - "github.com/sirupsen/logrus" //nolint:depguard + "github.com/sirupsen/logrus" "github.com/golangci/golangci-lint/pkg/exitcodes" ) diff --git a/pkg/packages/util_test.go b/pkg/packages/util_test.go index 89584b7ff96a..5308429980ec 100644 --- a/pkg/packages/util_test.go +++ b/pkg/packages/util_test.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/assert" ) -//nolint:lll func Test_stackCrusher(t *testing.T) { testCases := []struct { desc string diff --git a/pkg/printers/checkstyle_test.go b/pkg/printers/checkstyle_test.go index cf8a7d81b19b..9c2691311b56 100644 --- a/pkg/printers/checkstyle_test.go +++ b/pkg/printers/checkstyle_test.go @@ -49,7 +49,6 @@ func TestCheckstyle_Print(t *testing.T) { err := printer.Print(issues) require.NoError(t, err) - //nolint:lll expected := "\n\n\n \n \n \n \n \n \n\n" assert.Equal(t, expected, strings.ReplaceAll(buf.String(), "\r", "")) diff --git a/pkg/printers/codeclimate_test.go b/pkg/printers/codeclimate_test.go index 6ee9f1cf8b6c..37c4d21ba95b 100644 --- a/pkg/printers/codeclimate_test.go +++ b/pkg/printers/codeclimate_test.go @@ -63,7 +63,6 @@ func TestCodeClimate_Print(t *testing.T) { err := printer.Print(issues) 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}}}] ` diff --git a/pkg/printers/github_test.go b/pkg/printers/github_test.go index d927ddd271e6..c6abd2de87aa 100644 --- a/pkg/printers/github_test.go +++ b/pkg/printers/github_test.go @@ -1,4 +1,3 @@ -//nolint:dupl package printers import ( diff --git a/pkg/printers/html_test.go b/pkg/printers/html_test.go index 23d479ca3b0a..9adf42a2f5d3 100644 --- a/pkg/printers/html_test.go +++ b/pkg/printers/html_test.go @@ -11,7 +11,6 @@ import ( "github.com/golangci/golangci-lint/pkg/result" ) -//nolint:lll const expectedHTML = ` diff --git a/pkg/printers/json_test.go b/pkg/printers/json_test.go index 78111d9bcfb5..98d21e908d9e 100644 --- a/pkg/printers/json_test.go +++ b/pkg/printers/json_test.go @@ -49,7 +49,6 @@ func TestJSON_Print(t *testing.T) { err := printer.Print(issues) 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} ` diff --git a/pkg/printers/junitxml_test.go b/pkg/printers/junitxml_test.go index c10d6403c1d1..d5b4bc1f62de 100644 --- a/pkg/printers/junitxml_test.go +++ b/pkg/printers/junitxml_test.go @@ -1,4 +1,3 @@ -//nolint:dupl package printers import ( diff --git a/pkg/printers/tab_test.go b/pkg/printers/tab_test.go index bbd529b099b7..00e376ef06dc 100644 --- a/pkg/printers/tab_test.go +++ b/pkg/printers/tab_test.go @@ -77,8 +77,7 @@ path/to/fileb.go:300:9 another issue desc: "enable all options", printLinterName: 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", }, } diff --git a/pkg/printers/text_test.go b/pkg/printers/text_test.go index f75313490727..fe9c53098576 100644 --- a/pkg/printers/text_test.go +++ b/pkg/printers/text_test.go @@ -96,8 +96,7 @@ func foo() { printIssuedLine: true, printLinterName: 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", }, { desc: "disable all options", diff --git a/pkg/result/issue.go b/pkg/result/issue.go index 1e8cd30524b0..32246a6df43a 100644 --- a/pkg/result/issue.go +++ b/pkg/result/issue.go @@ -1,7 +1,7 @@ package result import ( - "crypto/md5" //nolint:gosec + "crypto/md5" //nolint:gosec // for md5 hash "fmt" "go/token" @@ -91,7 +91,7 @@ func (i *Issue) Fingerprint() string { 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) return fmt.Sprintf("%X", hash.Sum(nil)) diff --git a/pkg/result/processors/base_rule.go b/pkg/result/processors/base_rule.go index 88140bfa6b7d..12333c898d3f 100644 --- a/pkg/result/processors/base_rule.go +++ b/pkg/result/processors/base_rule.go @@ -65,7 +65,7 @@ func (r *baseRule) matchLinter(issue *result.Issue) bool { 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()) if errSourceLine != nil { log.Warnf("Failed to get line %s:%d from line cache: %s", issue.FilePath(), issue.Line(), errSourceLine) diff --git a/pkg/result/processors/exclude_rules_test.go b/pkg/result/processors/exclude_rules_test.go index 96f6788e0933..05782a4445fd 100644 --- a/pkg/result/processors/exclude_rules_test.go +++ b/pkg/result/processors/exclude_rules_test.go @@ -50,7 +50,6 @@ func TestExcludeRules_multiple(t *testing.T) { p := NewExcludeRules(nil, files, opts) - //nolint:dupl cases := []issueTestCase{ {Path: "e.go", Text: "exclude", 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) - //nolint:dupl cases := []issueTestCase{ {Path: "e.go", Text: "exclude", Linter: "linter"}, {Path: "e.go", Text: "excLude", Linter: "linter"}, diff --git a/pkg/result/processors/fixer.go b/pkg/result/processors/fixer.go index 5c6d12ac0f74..2879beb48f58 100644 --- a/pkg/result/processors/fixer.go +++ b/pkg/result/processors/fixer.go @@ -164,7 +164,7 @@ func (f Fixer) applyInlineFixes(lineIssues []result.Issue, origLine []byte, line var newLineBuf bytes.Buffer newLineBuf.Grow(len(origLine)) - //nolint:misspell + //nolint:misspell // misspelling is intentional // example: origLine="it's becouse of them", StartCol=5, Length=7, NewString="because" curOrigLinePos := 0 diff --git a/pkg/result/processors/identifier_marker_test.go b/pkg/result/processors/identifier_marker_test.go index bef3f06afd55..beafab903f1f 100644 --- a/pkg/result/processors/identifier_marker_test.go +++ b/pkg/result/processors/identifier_marker_test.go @@ -10,7 +10,6 @@ import ( ) func TestIdentifierMarker(t *testing.T) { - //nolint:lll cases := []struct{ in, out string }{ {"unknown field Address in struct literal", "unknown field `Address` in struct literal"}, { diff --git a/pkg/result/processors/sort_results_test.go b/pkg/result/processors/sort_results_test.go index c75b0bbeb8db..46e8e76f1458 100644 --- a/pkg/result/processors/sort_results_test.go +++ b/pkg/result/processors/sort_results_test.go @@ -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{ {issues[0], issues[1], greater}, // file_windows.go vs file_linux.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{ {issues[0], issues[1], greater}, // 80 vs 70 {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{ {issues[0], issues[1], greater}, // b vs a {issues[1], issues[2], less}, // a vs c diff --git a/scripts/website/expand_templates/main.go b/scripts/website/expand_templates/main.go index e2951f3fc388..211a9a29dc6b 100644 --- a/scripts/website/expand_templates/main.go +++ b/scripts/website/expand_templates/main.go @@ -96,7 +96,7 @@ type latestRelease struct { func getLatestVersion() (string, error) { 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) if err != nil { return "", fmt.Errorf("prepare a HTTP request: %w", err) diff --git a/test/output_test.go b/test/output_test.go index fba1bededaa6..e3c3b71e975b 100644 --- a/test/output_test.go +++ b/test/output_test.go @@ -12,7 +12,7 @@ import ( "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":""}]` func TestOutput_lineNumber(t *testing.T) { @@ -30,7 +30,7 @@ func TestOutput_lineNumber(t *testing.T) { Runner(). Install(). Run(). - //nolint:misspell + //nolint:misspell // misspelling is intentional ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`") } @@ -91,7 +91,7 @@ func TestOutput_Multiple(t *testing.T) { Runner(). Install(). Run(). - //nolint:misspell + //nolint:misspell // misspelling is intentional ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`"). ExpectOutputContains(testshared.NormalizeFilePathInJSON(expectedJSONOutput)) } diff --git a/test/testshared/directives.go b/test/testshared/directives.go index 34f37daf3a15..2881816bb496 100644 --- a/test/testshared/directives.go +++ b/test/testshared/directives.go @@ -25,7 +25,7 @@ type RunContext struct { // 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 { tb.Helper() @@ -108,7 +108,9 @@ func ParseTestDirectives(tb testing.TB, sourcePath string) *RunContext { if rc.ExpectedLinter == "" { for _, arg := range rc.Args { 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:] } } diff --git a/test/testshared/runner.go b/test/testshared/runner.go index 0be6d7404930..f1f2adcb03c0 100644 --- a/test/testshared/runner.go +++ b/test/testshared/runner.go @@ -267,7 +267,7 @@ func (r *Runner) Command() *exec.Cmd { 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.Env = append(os.Environ(), r.env...)