Skip to content

Commit

Permalink
dev: organize golinters package (#4578)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Mar 26, 2024
1 parent 085ac85 commit 87a35e6
Show file tree
Hide file tree
Showing 132 changed files with 230 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ issues:
- path: pkg/golinters/gofumpt.go
linters: [staticcheck]
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead."
- path: pkg/golinters/staticcheck_common.go
- path: pkg/golinters/internal/staticcheck_common.go
linters: [staticcheck]
text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead."
- path: pkg/lint/lintersdb/manager.go
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/exitcodes"
"github.com/golangci/golangci-lint/pkg/fsutils"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis/load"
"github.com/golangci/golangci-lint/pkg/goanalysis/load"
"github.com/golangci/golangci-lint/pkg/goutil"
"github.com/golangci/golangci-lint/pkg/lint"
"github.com/golangci/golangci-lint/pkg/lint/linter"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/golangci/golangci-lint/internal/errorutil"
"github.com/golangci/golangci-lint/internal/pkgcache"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis/load"
"github.com/golangci/golangci-lint/pkg/goanalysis/load"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/timeutils"
)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"golang.org/x/tools/go/gcexportdata"
"golang.org/x/tools/go/packages"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis/load"
"github.com/golangci/golangci-lint/pkg/goanalysis/load"
"github.com/golangci/golangci-lint/pkg/logutils"
)

Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions pkg/golinters/asasalint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
"github.com/golangci/golangci-lint/pkg/golinters/internal"
)

func NewAsasalint(setting *config.AsasalintSettings) *goanalysis.Linter {
Expand All @@ -18,7 +19,7 @@ func NewAsasalint(setting *config.AsasalintSettings) *goanalysis.Linter {

a, err := asasalint.NewAnalyzer(cfg)
if err != nil {
linterLogger.Fatalf("asasalint: create analyzer: %v", err)
internal.LinterLogger.Fatalf("asasalint: create analyzer: %v", err)
}

return goanalysis.NewLinter(
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/asciicheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/tdakkota/asciicheck"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewAsciicheck() *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/bidichk.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewBiDiChk(cfg *config.BiDiChkSettings) *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/bodyclose.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/timakin/bodyclose/passes/bodyclose"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewBodyclose() *goanalysis.Linter {
Expand Down
6 changes: 0 additions & 6 deletions pkg/golinters/commons.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/golinters/containedctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/sivchari/containedctx"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewContainedCtx() *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/contextcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/kkHAIKE/contextcheck"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
"github.com/golangci/golangci-lint/pkg/lint/linter"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/copyloopvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewCopyLoopVar(settings *config.CopyLoopVarSettings) *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/cyclop.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewCyclop(settings *config.Cyclop) *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/decorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewDecorder(settings *config.DecorderSettings) *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/depguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
"github.com/golangci/golangci-lint/pkg/lint/linter"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/dogsled.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/result"
)
Expand Down
7 changes: 4 additions & 3 deletions pkg/golinters/dupl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/fsutils"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
"github.com/golangci/golangci-lint/pkg/golinters/internal"
"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/result"
)
Expand Down Expand Up @@ -53,7 +54,7 @@ func NewDupl(settings *config.DuplSettings) *goanalysis.Linter {
}

func runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]goanalysis.Issue, error) {
fileNames := getFileNames(pass)
fileNames := internal.GetFileNames(pass)

issues, err := duplAPI.Run(fileNames, settings.Threshold)
if err != nil {
Expand All @@ -75,7 +76,7 @@ func runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]goanalysis.I
dupl := fmt.Sprintf("%s:%d-%d", toFilename, i.To.LineStart(), i.To.LineEnd())
text := fmt.Sprintf("%d-%d lines are duplicate of %s",
i.From.LineStart(), i.From.LineEnd(),
formatCode(dupl, nil))
internal.FormatCode(dupl, nil))

res = append(res, goanalysis.NewIssue(&result.Issue{
Pos: token.Position{
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/dupword.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewDupWord(setting *config.DupWordSettings) *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/durationcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/charithe/durationcheck"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewDurationCheck() *goanalysis.Linter {
Expand Down
5 changes: 3 additions & 2 deletions pkg/golinters/errcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/fsutils"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
"github.com/golangci/golangci-lint/pkg/golinters/internal"
"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/result"
)
Expand Down Expand Up @@ -94,7 +95,7 @@ func runErrCheck(lintCtx *linter.Context, pass *analysis.Pass, checker *errcheck
code = err.FuncName
}

text = fmt.Sprintf("Error return value of %s is not checked", formatCode(code, lintCtx.Cfg))
text = fmt.Sprintf("Error return value of %s is not checked", internal.FormatCode(code, lintCtx.Cfg))
}

issues[i] = goanalysis.NewIssue(
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/errchkjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewErrChkJSON(cfg *config.ErrChkJSONSettings) *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/Antonboom/errname/pkg/analyzer"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewErrName() *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/errorlint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewErrorLint(cfg *config.ErrorLintSettings) *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/execinquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/lufeee/execinquery"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewExecInQuery() *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/exhaustive.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewExhaustive(settings *config.ExhaustiveSettings) *goanalysis.Linter {
Expand Down
5 changes: 3 additions & 2 deletions pkg/golinters/exhaustruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
"github.com/golangci/golangci-lint/pkg/golinters/internal"
)

func NewExhaustruct(settings *config.ExhaustructSettings) *goanalysis.Linter {
Expand All @@ -17,7 +18,7 @@ func NewExhaustruct(settings *config.ExhaustructSettings) *goanalysis.Linter {

a, err := analyzer.NewAnalyzer(include, exclude)
if err != nil {
linterLogger.Fatalf("exhaustruct configuration: %v", err)
internal.LinterLogger.Fatalf("exhaustruct configuration: %v", err)
}

return goanalysis.NewLinter(
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/exportloopref.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/kyoh86/exportloopref"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewExportLoopRef() *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/forbidigo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/result"
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/forcetypeassert.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/gostaticanalysis/forcetypeassert"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewForceTypeAssert() *goanalysis.Linter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/funlen.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/result"
)
Expand Down
21 changes: 11 additions & 10 deletions pkg/golinters/gci.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
"github.com/golangci/golangci-lint/pkg/golinters/internal"
"github.com/golangci/golangci-lint/pkg/lint/linter"
)

Expand Down Expand Up @@ -48,7 +49,7 @@ func NewGci(settings *config.GciSettings) *goanalysis.Linter {
var err error
cfg, err = rawCfg.Parse()
if err != nil {
linterLogger.Fatalf("gci: configuration parsing: %v", err)
internal.LinterLogger.Fatalf("gci: configuration parsing: %v", err)
}
}

Expand Down Expand Up @@ -82,7 +83,7 @@ func NewGci(settings *config.GciSettings) *goanalysis.Linter {
}

func runGci(pass *analysis.Pass, lintCtx *linter.Context, cfg *gcicfg.Config, lock *sync.Mutex) ([]goanalysis.Issue, error) {
fileNames := getFileNames(pass)
fileNames := internal.GetFileNames(pass)

var diffs []string
err := diffFormattedFilesToArray(fileNames, *cfg, &diffs, lock)
Expand All @@ -97,7 +98,7 @@ func runGci(pass *analysis.Pass, lintCtx *linter.Context, cfg *gcicfg.Config, lo
continue
}

is, err := extractIssuesFromPatch(diff, lintCtx, gciName)
is, err := internal.ExtractIssuesFromPatch(diff, lintCtx, gciName, getIssuedTextGci)
if err != nil {
return nil, fmt.Errorf("can't extract issues from gci diff output %s: %w", diff, err)
}
Expand Down Expand Up @@ -129,27 +130,27 @@ func diffFormattedFilesToArray(paths []string, cfg gcicfg.Config, diffs *[]strin
})
}

func getErrorTextForGci(settings config.GciSettings) string {
func getIssuedTextGci(settings *config.LintersSettings) string {
text := "File is not `gci`-ed"

hasOptions := settings.SkipGenerated || len(settings.Sections) > 0
hasOptions := settings.Gci.SkipGenerated || len(settings.Gci.Sections) > 0
if !hasOptions {
return text
}

text += " with"

if settings.SkipGenerated {
if settings.Gci.SkipGenerated {
text += " --skip-generated"
}

if len(settings.Sections) > 0 {
for _, section := range settings.Sections {
if len(settings.Gci.Sections) > 0 {
for _, section := range settings.Gci.Sections {
text += " -s " + section
}
}

if settings.CustomOrder {
if settings.Gci.CustomOrder {
text += " --custom-order"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/ginkgolinter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewGinkgoLinter(settings *config.GinkgoLinterSettings) *goanalysis.Linter {
Expand Down
Loading

0 comments on commit 87a35e6

Please sign in to comment.