diff --git a/.golangci.yml b/.golangci.yml index bf01de506275..c6190a00a99d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 8ed8c5eed20f..4240af217546 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -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" diff --git a/pkg/golinters/goanalysis/errors.go b/pkg/goanalysis/errors.go similarity index 100% rename from pkg/golinters/goanalysis/errors.go rename to pkg/goanalysis/errors.go diff --git a/pkg/golinters/goanalysis/issue.go b/pkg/goanalysis/issue.go similarity index 100% rename from pkg/golinters/goanalysis/issue.go rename to pkg/goanalysis/issue.go diff --git a/pkg/golinters/goanalysis/linter.go b/pkg/goanalysis/linter.go similarity index 100% rename from pkg/golinters/goanalysis/linter.go rename to pkg/goanalysis/linter.go diff --git a/pkg/golinters/goanalysis/linter_test.go b/pkg/goanalysis/linter_test.go similarity index 100% rename from pkg/golinters/goanalysis/linter_test.go rename to pkg/goanalysis/linter_test.go diff --git a/pkg/golinters/goanalysis/load/guard.go b/pkg/goanalysis/load/guard.go similarity index 100% rename from pkg/golinters/goanalysis/load/guard.go rename to pkg/goanalysis/load/guard.go diff --git a/pkg/golinters/goanalysis/metalinter.go b/pkg/goanalysis/metalinter.go similarity index 100% rename from pkg/golinters/goanalysis/metalinter.go rename to pkg/goanalysis/metalinter.go diff --git a/pkg/golinters/goanalysis/runner.go b/pkg/goanalysis/runner.go similarity index 99% rename from pkg/golinters/goanalysis/runner.go rename to pkg/goanalysis/runner.go index b75e3fa0f557..c1274ec09a7c 100644 --- a/pkg/golinters/goanalysis/runner.go +++ b/pkg/goanalysis/runner.go @@ -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" ) diff --git a/pkg/golinters/goanalysis/runner_action.go b/pkg/goanalysis/runner_action.go similarity index 100% rename from pkg/golinters/goanalysis/runner_action.go rename to pkg/goanalysis/runner_action.go diff --git a/pkg/golinters/goanalysis/runner_facts.go b/pkg/goanalysis/runner_facts.go similarity index 100% rename from pkg/golinters/goanalysis/runner_facts.go rename to pkg/goanalysis/runner_facts.go diff --git a/pkg/golinters/goanalysis/runner_loadingpackage.go b/pkg/goanalysis/runner_loadingpackage.go similarity index 99% rename from pkg/golinters/goanalysis/runner_loadingpackage.go rename to pkg/goanalysis/runner_loadingpackage.go index e39e2212c392..c54357eb6794 100644 --- a/pkg/golinters/goanalysis/runner_loadingpackage.go +++ b/pkg/goanalysis/runner_loadingpackage.go @@ -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" ) diff --git a/pkg/golinters/goanalysis/runners.go b/pkg/goanalysis/runners.go similarity index 100% rename from pkg/golinters/goanalysis/runners.go rename to pkg/goanalysis/runners.go diff --git a/pkg/golinters/asasalint.go b/pkg/golinters/asasalint.go index 67dde79918b2..d783d33653e3 100644 --- a/pkg/golinters/asasalint.go +++ b/pkg/golinters/asasalint.go @@ -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 { @@ -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( diff --git a/pkg/golinters/asciicheck.go b/pkg/golinters/asciicheck.go index 7e7ee05e5c8f..64c2e1fb3159 100644 --- a/pkg/golinters/asciicheck.go +++ b/pkg/golinters/asciicheck.go @@ -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 { diff --git a/pkg/golinters/bidichk.go b/pkg/golinters/bidichk.go index 2c2c7dba6218..62c60e8cec4c 100644 --- a/pkg/golinters/bidichk.go +++ b/pkg/golinters/bidichk.go @@ -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 { diff --git a/pkg/golinters/bodyclose.go b/pkg/golinters/bodyclose.go index aab364d963ac..97c768de13d9 100644 --- a/pkg/golinters/bodyclose.go +++ b/pkg/golinters/bodyclose.go @@ -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 { diff --git a/pkg/golinters/commons.go b/pkg/golinters/commons.go deleted file mode 100644 index 3b40e59bfea5..000000000000 --- a/pkg/golinters/commons.go +++ /dev/null @@ -1,6 +0,0 @@ -package golinters - -import "github.com/golangci/golangci-lint/pkg/logutils" - -// linterLogger must be use only when the context logger is not available. -var linterLogger = logutils.NewStderrLog(logutils.DebugKeyLinter) diff --git a/pkg/golinters/containedctx.go b/pkg/golinters/containedctx.go index 8f7859af7d6c..ac2d96ef64d4 100644 --- a/pkg/golinters/containedctx.go +++ b/pkg/golinters/containedctx.go @@ -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 { diff --git a/pkg/golinters/contextcheck.go b/pkg/golinters/contextcheck.go index f54192a189d1..0ab5750dad7c 100644 --- a/pkg/golinters/contextcheck.go +++ b/pkg/golinters/contextcheck.go @@ -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" ) diff --git a/pkg/golinters/copyloopvar.go b/pkg/golinters/copyloopvar.go index 02ce5f37a6cd..fa49cbd84b8b 100644 --- a/pkg/golinters/copyloopvar.go +++ b/pkg/golinters/copyloopvar.go @@ -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 { diff --git a/pkg/golinters/cyclop.go b/pkg/golinters/cyclop.go index f76c55552c25..2b4a4a0ba45a 100644 --- a/pkg/golinters/cyclop.go +++ b/pkg/golinters/cyclop.go @@ -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 { diff --git a/pkg/golinters/decorder.go b/pkg/golinters/decorder.go index 5202a03a4f95..e41482ee1005 100644 --- a/pkg/golinters/decorder.go +++ b/pkg/golinters/decorder.go @@ -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 { diff --git a/pkg/golinters/depguard.go b/pkg/golinters/depguard.go index 49e471df824d..484d33d7273c 100644 --- a/pkg/golinters/depguard.go +++ b/pkg/golinters/depguard.go @@ -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" ) diff --git a/pkg/golinters/dogsled.go b/pkg/golinters/dogsled.go index de567ce7cf64..11a3c3a9f4ca 100644 --- a/pkg/golinters/dogsled.go +++ b/pkg/golinters/dogsled.go @@ -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" ) diff --git a/pkg/golinters/dupl.go b/pkg/golinters/dupl.go index eec51eabab72..9ec5d38083ad 100644 --- a/pkg/golinters/dupl.go +++ b/pkg/golinters/dupl.go @@ -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" ) @@ -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 { @@ -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{ diff --git a/pkg/golinters/dupword.go b/pkg/golinters/dupword.go index 6f079ffc895e..3d5242696dc2 100644 --- a/pkg/golinters/dupword.go +++ b/pkg/golinters/dupword.go @@ -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 { diff --git a/pkg/golinters/durationcheck.go b/pkg/golinters/durationcheck.go index 880de5d4200a..c3324776521c 100644 --- a/pkg/golinters/durationcheck.go +++ b/pkg/golinters/durationcheck.go @@ -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 { diff --git a/pkg/golinters/errcheck.go b/pkg/golinters/errcheck.go index 89b18519c91b..b945012edf9e 100644 --- a/pkg/golinters/errcheck.go +++ b/pkg/golinters/errcheck.go @@ -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" ) @@ -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( diff --git a/pkg/golinters/errchkjson.go b/pkg/golinters/errchkjson.go index 578b0e2e0ea2..641e87010483 100644 --- a/pkg/golinters/errchkjson.go +++ b/pkg/golinters/errchkjson.go @@ -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 { diff --git a/pkg/golinters/errname.go b/pkg/golinters/errname.go index 193a7aba755e..ce64f374c8a5 100644 --- a/pkg/golinters/errname.go +++ b/pkg/golinters/errname.go @@ -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 { diff --git a/pkg/golinters/errorlint.go b/pkg/golinters/errorlint.go index cac94159d6f5..adc3eadf270a 100644 --- a/pkg/golinters/errorlint.go +++ b/pkg/golinters/errorlint.go @@ -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 { diff --git a/pkg/golinters/execinquery.go b/pkg/golinters/execinquery.go index 9911d315e0b3..6c5bcb63129c 100644 --- a/pkg/golinters/execinquery.go +++ b/pkg/golinters/execinquery.go @@ -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 { diff --git a/pkg/golinters/exhaustive.go b/pkg/golinters/exhaustive.go index fe58e10f0570..6280cbb5629c 100644 --- a/pkg/golinters/exhaustive.go +++ b/pkg/golinters/exhaustive.go @@ -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 { diff --git a/pkg/golinters/exhaustruct.go b/pkg/golinters/exhaustruct.go index 5272879e1db1..4621b7bf5779 100644 --- a/pkg/golinters/exhaustruct.go +++ b/pkg/golinters/exhaustruct.go @@ -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 { @@ -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( diff --git a/pkg/golinters/exportloopref.go b/pkg/golinters/exportloopref.go index 1131c575b950..30bdeedaa987 100644 --- a/pkg/golinters/exportloopref.go +++ b/pkg/golinters/exportloopref.go @@ -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 { diff --git a/pkg/golinters/forbidigo.go b/pkg/golinters/forbidigo.go index 797484ba2cc4..194d4fa033ed 100644 --- a/pkg/golinters/forbidigo.go +++ b/pkg/golinters/forbidigo.go @@ -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" diff --git a/pkg/golinters/forcetypeassert.go b/pkg/golinters/forcetypeassert.go index 873c833b5666..574e53c71970 100644 --- a/pkg/golinters/forcetypeassert.go +++ b/pkg/golinters/forcetypeassert.go @@ -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 { diff --git a/pkg/golinters/funlen.go b/pkg/golinters/funlen.go index d421e174b7fb..084028a754ad 100644 --- a/pkg/golinters/funlen.go +++ b/pkg/golinters/funlen.go @@ -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" ) diff --git a/pkg/golinters/gci.go b/pkg/golinters/gci.go index 3862267692f4..7f869930c6cd 100644 --- a/pkg/golinters/gci.go +++ b/pkg/golinters/gci.go @@ -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" ) @@ -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) } } @@ -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) @@ -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) } @@ -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" } diff --git a/pkg/golinters/ginkgolinter.go b/pkg/golinters/ginkgolinter.go index 3d20a9f49e9f..182b001d51b3 100644 --- a/pkg/golinters/ginkgolinter.go +++ b/pkg/golinters/ginkgolinter.go @@ -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 { diff --git a/pkg/golinters/gocheckcompilerdirectives.go b/pkg/golinters/gocheckcompilerdirectives.go index 2592c899463b..d2e302a285a0 100644 --- a/pkg/golinters/gocheckcompilerdirectives.go +++ b/pkg/golinters/gocheckcompilerdirectives.go @@ -4,7 +4,7 @@ import ( "4d63.com/gocheckcompilerdirectives/checkcompilerdirectives" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewGoCheckCompilerDirectives() *goanalysis.Linter { diff --git a/pkg/golinters/gochecknoglobals.go b/pkg/golinters/gochecknoglobals.go index e94778a32a50..a35876d995af 100644 --- a/pkg/golinters/gochecknoglobals.go +++ b/pkg/golinters/gochecknoglobals.go @@ -4,7 +4,7 @@ import ( "4d63.com/gochecknoglobals/checknoglobals" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewGochecknoglobals() *goanalysis.Linter { diff --git a/pkg/golinters/gochecknoinits.go b/pkg/golinters/gochecknoinits.go index a51b531b94ad..28f025943156 100644 --- a/pkg/golinters/gochecknoinits.go +++ b/pkg/golinters/gochecknoinits.go @@ -8,7 +8,8 @@ import ( "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/golinters/internal" "github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/result" ) @@ -64,7 +65,7 @@ func checkFileForInits(f *ast.File, fset *token.FileSet) []result.Issue { if name == "init" && funcDecl.Recv.NumFields() == 0 { res = append(res, result.Issue{ Pos: fset.Position(funcDecl.Pos()), - Text: fmt.Sprintf("don't use %s function", formatCode(name, nil)), + Text: fmt.Sprintf("don't use %s function", internal.FormatCode(name, nil)), FromLinter: gochecknoinitsName, }) } diff --git a/pkg/golinters/gochecksumtype.go b/pkg/golinters/gochecksumtype.go index 5516179dfccb..a022abae9709 100644 --- a/pkg/golinters/gochecksumtype.go +++ b/pkg/golinters/gochecksumtype.go @@ -8,7 +8,7 @@ import ( "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/packages" - "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" ) diff --git a/pkg/golinters/gocognit.go b/pkg/golinters/gocognit.go index f5cff840e468..00cd26b091d0 100644 --- a/pkg/golinters/gocognit.go +++ b/pkg/golinters/gocognit.go @@ -9,7 +9,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" "github.com/golangci/golangci-lint/pkg/result" ) @@ -70,7 +71,7 @@ func runGocognit(pass *analysis.Pass, settings *config.GocognitSettings) []goana issues = append(issues, goanalysis.NewIssue(&result.Issue{ Pos: s.Pos, Text: fmt.Sprintf("cognitive complexity %d of func %s is high (> %d)", - s.Complexity, formatCode(s.FuncName, nil), settings.MinComplexity), + s.Complexity, internal.FormatCode(s.FuncName, nil), settings.MinComplexity), FromLinter: gocognitName, }, pass)) } diff --git a/pkg/golinters/goconst.go b/pkg/golinters/goconst.go index 204e2496a661..553f6be9741a 100644 --- a/pkg/golinters/goconst.go +++ b/pkg/golinters/goconst.go @@ -8,7 +8,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" "github.com/golangci/golangci-lint/pkg/result" ) @@ -78,12 +79,12 @@ func runGoconst(pass *analysis.Pass, settings *config.GoConstSettings) ([]goanal res := make([]goanalysis.Issue, 0, len(lintIssues)) for _, i := range lintIssues { - text := fmt.Sprintf("string %s has %d occurrences", formatCode(i.Str, nil), i.OccurrencesCount) + text := fmt.Sprintf("string %s has %d occurrences", internal.FormatCode(i.Str, nil), i.OccurrencesCount) if i.MatchingConst == "" { text += ", make it a constant" } else { - text += fmt.Sprintf(", but such constant %s already exists", formatCode(i.MatchingConst, nil)) + text += fmt.Sprintf(", but such constant %s already exists", internal.FormatCode(i.MatchingConst, nil)) } res = append(res, goanalysis.NewIssue(&result.Issue{ diff --git a/pkg/golinters/gocritic.go b/pkg/golinters/gocritic.go index f78c2cf90998..5f5d34393a6a 100644 --- a/pkg/golinters/gocritic.go +++ b/pkg/golinters/gocritic.go @@ -19,7 +19,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" diff --git a/pkg/golinters/gocyclo.go b/pkg/golinters/gocyclo.go index 63aefb09fe98..cbf05fff0ce4 100644 --- a/pkg/golinters/gocyclo.go +++ b/pkg/golinters/gocyclo.go @@ -8,7 +8,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" "github.com/golangci/golangci-lint/pkg/result" ) @@ -62,7 +63,7 @@ func runGoCyclo(pass *analysis.Pass, settings *config.GoCycloSettings) []goanaly for _, s := range stats { text := fmt.Sprintf("cyclomatic complexity %d of func %s is high (> %d)", - s.Complexity, formatCode(s.FuncName, nil), settings.MinComplexity) + s.Complexity, internal.FormatCode(s.FuncName, nil), settings.MinComplexity) issues = append(issues, goanalysis.NewIssue(&result.Issue{ Pos: s.Pos, diff --git a/pkg/golinters/godot.go b/pkg/golinters/godot.go index 55394b10fe1f..614ea410249e 100644 --- a/pkg/golinters/godot.go +++ b/pkg/golinters/godot.go @@ -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" "github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/result" ) diff --git a/pkg/golinters/godox.go b/pkg/golinters/godox.go index 208bade5764c..afe997bd2887 100644 --- a/pkg/golinters/godox.go +++ b/pkg/golinters/godox.go @@ -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" ) diff --git a/pkg/golinters/goerr113.go b/pkg/golinters/goerr113.go index 10addc57c240..a304cbe54b42 100644 --- a/pkg/golinters/goerr113.go +++ b/pkg/golinters/goerr113.go @@ -4,7 +4,7 @@ import ( "github.com/Djarvur/go-err113" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewGoerr113() *goanalysis.Linter { diff --git a/pkg/golinters/gofmt.go b/pkg/golinters/gofmt.go index d2d0d3ccc5a4..9a00694440ec 100644 --- a/pkg/golinters/gofmt.go +++ b/pkg/golinters/gofmt.go @@ -8,7 +8,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" ) @@ -53,7 +54,7 @@ func NewGofmt(settings *config.GoFmtSettings) *goanalysis.Linter { } func runGofmt(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoFmtSettings) ([]goanalysis.Issue, error) { - fileNames := getFileNames(pass) + fileNames := internal.GetFileNames(pass) var rewriteRules []gofmtAPI.RewriteRule for _, rule := range settings.RewriteRules { @@ -71,7 +72,7 @@ func runGofmt(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoF continue } - is, err := extractIssuesFromPatch(string(diff), lintCtx, gofmtName) + is, err := internal.ExtractIssuesFromPatch(string(diff), lintCtx, gofmtName, getIssuedTextGoFmt) if err != nil { return nil, fmt.Errorf("can't extract issues from gofmt diff output %q: %w", string(diff), err) } @@ -83,3 +84,15 @@ func runGofmt(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoF return issues, nil } + +func getIssuedTextGoFmt(settings *config.LintersSettings) string { + text := "File is not `gofmt`-ed" + if settings.Gofmt.Simplify { + text += " with `-s`" + } + for _, rule := range settings.Gofmt.RewriteRules { + text += fmt.Sprintf(" `-r '%s -> %s'`", rule.Pattern, rule.Replacement) + } + + return text +} diff --git a/pkg/golinters/gofumpt.go b/pkg/golinters/gofumpt.go index c2aaf121de7e..4c6a9cec10fb 100644 --- a/pkg/golinters/gofumpt.go +++ b/pkg/golinters/gofumpt.go @@ -12,7 +12,8 @@ import ( "mvdan.cc/gofumpt/format" "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" ) @@ -72,7 +73,7 @@ func NewGofumpt(settings *config.GofumptSettings) *goanalysis.Linter { } func runGofumpt(lintCtx *linter.Context, pass *analysis.Pass, diff differ, options format.Options) ([]goanalysis.Issue, error) { - fileNames := getFileNames(pass) + fileNames := internal.GetFileNames(pass) var issues []goanalysis.Issue @@ -96,7 +97,7 @@ func runGofumpt(lintCtx *linter.Context, pass *analysis.Pass, diff differ, optio } diff := out.String() - is, err := extractIssuesFromPatch(diff, lintCtx, gofumptName) + is, err := internal.ExtractIssuesFromPatch(diff, lintCtx, gofumptName, getIssuedTextGoFumpt) if err != nil { return nil, fmt.Errorf("can't extract issues from gofumpt diff output %q: %w", diff, err) } @@ -117,3 +118,13 @@ func getLangVersion(settings *config.GofumptSettings) string { } return settings.LangVersion } + +func getIssuedTextGoFumpt(settings *config.LintersSettings) string { + text := "File is not `gofumpt`-ed" + + if settings.Gofumpt.ExtraRules { + text += " with `-extra`" + } + + return text +} diff --git a/pkg/golinters/goheader.go b/pkg/golinters/goheader.go index 5ed5d9d8ded6..b47f0304e65d 100644 --- a/pkg/golinters/goheader.go +++ b/pkg/golinters/goheader.go @@ -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/result" ) diff --git a/pkg/golinters/goimports.go b/pkg/golinters/goimports.go index aac27f38e55f..224970f5ca90 100644 --- a/pkg/golinters/goimports.go +++ b/pkg/golinters/goimports.go @@ -9,7 +9,8 @@ import ( "golang.org/x/tools/imports" "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" ) @@ -56,7 +57,7 @@ func NewGoimports(settings *config.GoImportsSettings) *goanalysis.Linter { } func runGoImports(lintCtx *linter.Context, pass *analysis.Pass) ([]goanalysis.Issue, error) { - fileNames := getFileNames(pass) + fileNames := internal.GetFileNames(pass) var issues []goanalysis.Issue @@ -69,7 +70,7 @@ func runGoImports(lintCtx *linter.Context, pass *analysis.Pass) ([]goanalysis.Is continue } - is, err := extractIssuesFromPatch(string(diff), lintCtx, goimportsName) + is, err := internal.ExtractIssuesFromPatch(string(diff), lintCtx, goimportsName, getIssuedTextGoImports) if err != nil { return nil, fmt.Errorf("can't extract issues from gofmt diff output %q: %w", string(diff), err) } @@ -81,3 +82,13 @@ func runGoImports(lintCtx *linter.Context, pass *analysis.Pass) ([]goanalysis.Is return issues, nil } + +func getIssuedTextGoImports(settings *config.LintersSettings) string { + text := "File is not `goimports`-ed" + + if settings.Goimports.LocalPrefixes != "" { + text += " with -local " + settings.Goimports.LocalPrefixes + } + + return text +} diff --git a/pkg/golinters/gomnd.go b/pkg/golinters/gomnd.go index 2e6d77a8015e..b4bf957a7063 100644 --- a/pkg/golinters/gomnd.go +++ b/pkg/golinters/gomnd.go @@ -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 NewGoMND(settings *config.GoMndSettings) *goanalysis.Linter { diff --git a/pkg/golinters/gomoddirectives.go b/pkg/golinters/gomoddirectives.go index 56afcd465f08..6902b3207e3f 100644 --- a/pkg/golinters/gomoddirectives.go +++ b/pkg/golinters/gomoddirectives.go @@ -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" "github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/result" ) diff --git a/pkg/golinters/gomodguard.go b/pkg/golinters/gomodguard.go index 157bf56c35de..fe880b57fe8b 100644 --- a/pkg/golinters/gomodguard.go +++ b/pkg/golinters/gomodguard.go @@ -7,7 +7,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" "github.com/golangci/golangci-lint/pkg/result" ) @@ -73,7 +74,7 @@ func NewGomodguard(settings *config.GoModGuardSettings) *goanalysis.Linter { } analyzer.Run = func(pass *analysis.Pass) (any, error) { - gomodguardIssues := processor.ProcessFiles(getFileNames(pass)) + gomodguardIssues := processor.ProcessFiles(internal.GetFileNames(pass)) mu.Lock() defer mu.Unlock() diff --git a/pkg/golinters/goprintffuncname.go b/pkg/golinters/goprintffuncname.go index e513718ba8dc..97df64051b41 100644 --- a/pkg/golinters/goprintffuncname.go +++ b/pkg/golinters/goprintffuncname.go @@ -4,7 +4,7 @@ import ( "github.com/jirfag/go-printf-func-name/pkg/analyzer" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewGoPrintfFuncName() *goanalysis.Linter { diff --git a/pkg/golinters/gosec.go b/pkg/golinters/gosec.go index 0c09c5967262..3ce37cac48c2 100644 --- a/pkg/golinters/gosec.go +++ b/pkg/golinters/gosec.go @@ -16,7 +16,7 @@ import ( "golang.org/x/tools/go/packages" "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" ) diff --git a/pkg/golinters/gosimple.go b/pkg/golinters/gosimple.go index de60ded73e2d..b7930f0ee022 100644 --- a/pkg/golinters/gosimple.go +++ b/pkg/golinters/gosimple.go @@ -4,13 +4,14 @@ import ( "honnef.co/go/tools/simple" "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 NewGosimple(settings *config.StaticCheckSettings) *goanalysis.Linter { - cfg := staticCheckConfig(settings) + cfg := internal.StaticCheckConfig(settings) - analyzers := setupStaticCheckAnalyzers(simple.Analyzers, getGoVersion(settings), cfg.Checks) + analyzers := internal.SetupStaticCheckAnalyzers(simple.Analyzers, internal.GetGoVersion(settings), cfg.Checks) return goanalysis.NewLinter( "gosimple", diff --git a/pkg/golinters/gosmopolitan.go b/pkg/golinters/gosmopolitan.go index 2e01fcc70d59..f4c2114706ea 100644 --- a/pkg/golinters/gosmopolitan.go +++ b/pkg/golinters/gosmopolitan.go @@ -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 NewGosmopolitan(s *config.GosmopolitanSettings) *goanalysis.Linter { diff --git a/pkg/golinters/govet.go b/pkg/golinters/govet.go index ecd406e3bf21..30410abae1be 100644 --- a/pkg/golinters/govet.go +++ b/pkg/golinters/govet.go @@ -52,7 +52,7 @@ import ( "golang.org/x/tools/go/analysis/passes/unusedwrite" "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/logutils" ) diff --git a/pkg/golinters/grouper.go b/pkg/golinters/grouper.go index 81afb0c7fca0..f4eb3c4271e9 100644 --- a/pkg/golinters/grouper.go +++ b/pkg/golinters/grouper.go @@ -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 NewGrouper(settings *config.GrouperSettings) *goanalysis.Linter { diff --git a/pkg/golinters/importas.go b/pkg/golinters/importas.go index a426333dbf06..f699edfc877c 100644 --- a/pkg/golinters/importas.go +++ b/pkg/golinters/importas.go @@ -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" ) diff --git a/pkg/golinters/inamedparam.go b/pkg/golinters/inamedparam.go index 887f3db2adb9..293716dfd3b0 100644 --- a/pkg/golinters/inamedparam.go +++ b/pkg/golinters/inamedparam.go @@ -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 NewINamedParam(settings *config.INamedParamSettings) *goanalysis.Linter { diff --git a/pkg/golinters/ineffassign.go b/pkg/golinters/ineffassign.go index ac5eb20adb65..e4c2abf711f0 100644 --- a/pkg/golinters/ineffassign.go +++ b/pkg/golinters/ineffassign.go @@ -4,7 +4,7 @@ import ( "github.com/gordonklaus/ineffassign/pkg/ineffassign" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewIneffassign() *goanalysis.Linter { diff --git a/pkg/golinters/interfacebloat.go b/pkg/golinters/interfacebloat.go index a6dbfe178fe1..93dfe338e9f0 100644 --- a/pkg/golinters/interfacebloat.go +++ b/pkg/golinters/interfacebloat.go @@ -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 NewInterfaceBloat(settings *config.InterfaceBloatSettings) *goanalysis.Linter { diff --git a/pkg/golinters/internal/commons.go b/pkg/golinters/internal/commons.go new file mode 100644 index 000000000000..c21dd0092793 --- /dev/null +++ b/pkg/golinters/internal/commons.go @@ -0,0 +1,6 @@ +package internal + +import "github.com/golangci/golangci-lint/pkg/logutils" + +// LinterLogger must be use only when the context logger is not available. +var LinterLogger = logutils.NewStderrLog(logutils.DebugKeyLinter) diff --git a/pkg/golinters/gofmt_common.go b/pkg/golinters/internal/diff.go similarity index 86% rename from pkg/golinters/gofmt_common.go rename to pkg/golinters/internal/diff.go index afa7afbf899e..b20230dfa9cf 100644 --- a/pkg/golinters/gofmt_common.go +++ b/pkg/golinters/internal/diff.go @@ -1,4 +1,4 @@ -package golinters +package internal import ( "bytes" @@ -27,6 +27,8 @@ const ( diffLineDeleted diffLineType = "deleted" ) +type fmtTextFormatter func(settings *config.LintersSettings) string + type diffLine struct { originalNumber int // 1-based original line number typ diffLineType @@ -217,34 +219,7 @@ func (p *hunkChangesParser) parse(h *diffpkg.Hunk) []Change { return p.ret } -func getErrorTextForLinter(settings *config.LintersSettings, linterName string) string { - text := "File is not formatted" - switch linterName { - case gciName: - text = getErrorTextForGci(settings.Gci) - case gofumptName: - text = "File is not `gofumpt`-ed" - if settings.Gofumpt.ExtraRules { - text += " with `-extra`" - } - case gofmtName: - text = "File is not `gofmt`-ed" - if settings.Gofmt.Simplify { - text += " with `-s`" - } - for _, rule := range settings.Gofmt.RewriteRules { - text += fmt.Sprintf(" `-r '%s -> %s'`", rule.Pattern, rule.Replacement) - } - case goimportsName: - text = "File is not `goimports`-ed" - if settings.Goimports.LocalPrefixes != "" { - text += " with -local " + settings.Goimports.LocalPrefixes - } - } - return text -} - -func extractIssuesFromPatch(patch string, lintCtx *linter.Context, linterName string) ([]result.Issue, error) { +func ExtractIssuesFromPatch(patch string, lintCtx *linter.Context, linterName string, formatter fmtTextFormatter) ([]result.Issue, error) { diffs, err := diffpkg.ParseMultiFileDiff([]byte(patch)) if err != nil { return nil, fmt.Errorf("can't parse patch: %w", err) @@ -274,7 +249,7 @@ func extractIssuesFromPatch(patch string, lintCtx *linter.Context, linterName st Filename: d.NewName, Line: change.LineRange.From, }, - Text: getErrorTextForLinter(lintCtx.Settings(), linterName), + Text: formatter(lintCtx.Settings()), Replacement: &change.Replacement, } if change.LineRange.From != change.LineRange.To { diff --git a/pkg/golinters/gofmt_test.go b/pkg/golinters/internal/diff_test.go similarity index 99% rename from pkg/golinters/gofmt_test.go rename to pkg/golinters/internal/diff_test.go index e017c7978ed0..51946b4ff762 100644 --- a/pkg/golinters/gofmt_test.go +++ b/pkg/golinters/internal/diff_test.go @@ -1,4 +1,4 @@ -package golinters +package internal import ( "testing" diff --git a/pkg/golinters/staticcheck_common.go b/pkg/golinters/internal/staticcheck_common.go similarity index 92% rename from pkg/golinters/staticcheck_common.go rename to pkg/golinters/internal/staticcheck_common.go index 0eb21ec9cfb0..5b5812c318a2 100644 --- a/pkg/golinters/staticcheck_common.go +++ b/pkg/golinters/internal/staticcheck_common.go @@ -1,4 +1,4 @@ -package golinters +package internal import ( "strings" @@ -14,7 +14,7 @@ import ( var debugf = logutils.Debug(logutils.DebugKeyMegacheck) -func getGoVersion(settings *config.StaticCheckSettings) string { +func GetGoVersion(settings *config.StaticCheckSettings) string { var goVersion string if settings != nil { goVersion = settings.GoVersion @@ -27,7 +27,7 @@ func getGoVersion(settings *config.StaticCheckSettings) string { return "1.17" } -func setupStaticCheckAnalyzers(src []*lint.Analyzer, goVersion string, checks []string) []*analysis.Analyzer { +func SetupStaticCheckAnalyzers(src []*lint.Analyzer, goVersion string, checks []string) []*analysis.Analyzer { var names []string for _, a := range src { names = append(names, a.Analyzer.Name) @@ -38,7 +38,7 @@ func setupStaticCheckAnalyzers(src []*lint.Analyzer, goVersion string, checks [] var ret []*analysis.Analyzer for _, a := range src { if filter[a.Analyzer.Name] { - setAnalyzerGoVersion(a.Analyzer, goVersion) + SetAnalyzerGoVersion(a.Analyzer, goVersion) ret = append(ret, a.Analyzer) } } @@ -46,7 +46,7 @@ func setupStaticCheckAnalyzers(src []*lint.Analyzer, goVersion string, checks [] return ret } -func setAnalyzerGoVersion(a *analysis.Analyzer, goVersion string) { +func SetAnalyzerGoVersion(a *analysis.Analyzer, goVersion string) { if v := a.Flags.Lookup("go"); v != nil { if err := v.Value.Set(goVersion); err != nil { debugf("Failed to set go version: %s", err) @@ -54,7 +54,7 @@ func setAnalyzerGoVersion(a *analysis.Analyzer, goVersion string) { } } -func staticCheckConfig(settings *config.StaticCheckSettings) *scconfig.Config { +func StaticCheckConfig(settings *config.StaticCheckSettings) *scconfig.Config { var cfg *scconfig.Config if settings == nil || !settings.HasConfiguration() { diff --git a/pkg/golinters/util.go b/pkg/golinters/internal/util.go similarity index 83% rename from pkg/golinters/util.go rename to pkg/golinters/internal/util.go index 932cbfcf78f6..80b194dd26db 100644 --- a/pkg/golinters/util.go +++ b/pkg/golinters/internal/util.go @@ -1,4 +1,4 @@ -package golinters +package internal import ( "fmt" @@ -10,7 +10,7 @@ import ( "github.com/golangci/golangci-lint/pkg/config" ) -func formatCode(code string, _ *config.Config) string { +func FormatCode(code string, _ *config.Config) string { if strings.Contains(code, "`") { return code // TODO: properly escape or remove } @@ -18,7 +18,7 @@ func formatCode(code string, _ *config.Config) string { return fmt.Sprintf("`%s`", code) } -func getFileNames(pass *analysis.Pass) []string { +func GetFileNames(pass *analysis.Pass) []string { var fileNames []string for _, f := range pass.Files { fileName := pass.Fset.PositionFor(f.Pos(), true).Filename diff --git a/pkg/golinters/intrange.go b/pkg/golinters/intrange.go index 8de956dc129b..e204087f3dd4 100644 --- a/pkg/golinters/intrange.go +++ b/pkg/golinters/intrange.go @@ -4,7 +4,7 @@ import ( "github.com/ckaznocha/intrange" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewIntrange() *goanalysis.Linter { diff --git a/pkg/golinters/ireturn.go b/pkg/golinters/ireturn.go index dc09dad0eef3..44a72e83f92c 100644 --- a/pkg/golinters/ireturn.go +++ b/pkg/golinters/ireturn.go @@ -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 NewIreturn(settings *config.IreturnSettings) *goanalysis.Linter { diff --git a/pkg/golinters/lll.go b/pkg/golinters/lll.go index 84ce61a9ee50..2c9ae9832811 100644 --- a/pkg/golinters/lll.go +++ b/pkg/golinters/lll.go @@ -13,7 +13,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" "github.com/golangci/golangci-lint/pkg/result" ) @@ -58,7 +59,7 @@ func NewLLL(settings *config.LllSettings) *goanalysis.Linter { } func runLll(pass *analysis.Pass, settings *config.LllSettings) ([]goanalysis.Issue, error) { - fileNames := getFileNames(pass) + fileNames := internal.GetFileNames(pass) spaces := strings.Repeat(" ", settings.TabWidth) diff --git a/pkg/golinters/loggercheck.go b/pkg/golinters/loggercheck.go index fc29127c3bb7..a4a63722c8ff 100644 --- a/pkg/golinters/loggercheck.go +++ b/pkg/golinters/loggercheck.go @@ -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 NewLoggerCheck(settings *config.LoggerCheckSettings) *goanalysis.Linter { diff --git a/pkg/golinters/maintidx.go b/pkg/golinters/maintidx.go index 55509d970c19..b5751227bcac 100644 --- a/pkg/golinters/maintidx.go +++ b/pkg/golinters/maintidx.go @@ -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 NewMaintIdx(cfg *config.MaintIdxSettings) *goanalysis.Linter { diff --git a/pkg/golinters/makezero.go b/pkg/golinters/makezero.go index 7a14c8e09dfc..9aeb08a60b98 100644 --- a/pkg/golinters/makezero.go +++ b/pkg/golinters/makezero.go @@ -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/result" ) diff --git a/pkg/golinters/mirror.go b/pkg/golinters/mirror.go index d6e2bb06ac84..3d5766fe8eaa 100644 --- a/pkg/golinters/mirror.go +++ b/pkg/golinters/mirror.go @@ -6,7 +6,7 @@ import ( "github.com/butuzov/mirror" "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" "github.com/golangci/golangci-lint/pkg/result" ) diff --git a/pkg/golinters/misspell.go b/pkg/golinters/misspell.go index 8a97534c58ff..70ee5602c0dc 100644 --- a/pkg/golinters/misspell.go +++ b/pkg/golinters/misspell.go @@ -11,7 +11,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" "github.com/golangci/golangci-lint/pkg/result" ) @@ -62,7 +63,7 @@ func NewMisspell(settings *config.MisspellSettings) *goanalysis.Linter { } func runMisspell(lintCtx *linter.Context, pass *analysis.Pass, replacer *misspell.Replacer, mode string) ([]goanalysis.Issue, error) { - fileNames := getFileNames(pass) + fileNames := internal.GetFileNames(pass) var issues []goanalysis.Issue for _, filename := range fileNames { diff --git a/pkg/golinters/musttag.go b/pkg/golinters/musttag.go index 72d91958287d..9b97ed4f3ac6 100644 --- a/pkg/golinters/musttag.go +++ b/pkg/golinters/musttag.go @@ -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 NewMustTag(setting *config.MustTagSettings) *goanalysis.Linter { diff --git a/pkg/golinters/nakedret.go b/pkg/golinters/nakedret.go index 6153860fb4b2..0831458042b7 100644 --- a/pkg/golinters/nakedret.go +++ b/pkg/golinters/nakedret.go @@ -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 NewNakedret(settings *config.NakedretSettings) *goanalysis.Linter { diff --git a/pkg/golinters/nestif.go b/pkg/golinters/nestif.go index 4125ad9afcd9..4daad31cdeb6 100644 --- a/pkg/golinters/nestif.go +++ b/pkg/golinters/nestif.go @@ -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/result" ) diff --git a/pkg/golinters/nilerr.go b/pkg/golinters/nilerr.go index 2ea16f2f3958..79d86b55a4fc 100644 --- a/pkg/golinters/nilerr.go +++ b/pkg/golinters/nilerr.go @@ -4,7 +4,7 @@ import ( "github.com/gostaticanalysis/nilerr" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewNilErr() *goanalysis.Linter { diff --git a/pkg/golinters/nilnil.go b/pkg/golinters/nilnil.go index 804557b76dc2..539a65768168 100644 --- a/pkg/golinters/nilnil.go +++ b/pkg/golinters/nilnil.go @@ -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 NewNilNil(cfg *config.NilNilSettings) *goanalysis.Linter { diff --git a/pkg/golinters/nlreturn.go b/pkg/golinters/nlreturn.go index a359548f420f..a7a65e2a37c0 100644 --- a/pkg/golinters/nlreturn.go +++ b/pkg/golinters/nlreturn.go @@ -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 NewNLReturn(settings *config.NlreturnSettings) *goanalysis.Linter { diff --git a/pkg/golinters/noctx.go b/pkg/golinters/noctx.go index cff9c97dcf28..e62f6cbf373a 100644 --- a/pkg/golinters/noctx.go +++ b/pkg/golinters/noctx.go @@ -4,7 +4,7 @@ import ( "github.com/sonatard/noctx" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewNoctx() *goanalysis.Linter { diff --git a/pkg/golinters/nolintlint.go b/pkg/golinters/nolintlint.go index 7000620d199b..8ed2dceb9342 100644 --- a/pkg/golinters/nolintlint.go +++ b/pkg/golinters/nolintlint.go @@ -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/golinters/nolintlint" "github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/result" diff --git a/pkg/golinters/nonamedreturns.go b/pkg/golinters/nonamedreturns.go index 7856f6d613ef..ccfd5d6827f7 100644 --- a/pkg/golinters/nonamedreturns.go +++ b/pkg/golinters/nonamedreturns.go @@ -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 NewNoNamedReturns(settings *config.NoNamedReturnsSettings) *goanalysis.Linter { diff --git a/pkg/golinters/nosprintfhostport.go b/pkg/golinters/nosprintfhostport.go index a63b9bb5f567..a4fdcb859a69 100644 --- a/pkg/golinters/nosprintfhostport.go +++ b/pkg/golinters/nosprintfhostport.go @@ -4,7 +4,7 @@ import ( "github.com/stbenjam/no-sprintf-host-port/pkg/analyzer" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewNoSprintfHostPort() *goanalysis.Linter { diff --git a/pkg/golinters/paralleltest.go b/pkg/golinters/paralleltest.go index 8215619c730c..55fc7548d809 100644 --- a/pkg/golinters/paralleltest.go +++ b/pkg/golinters/paralleltest.go @@ -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 NewParallelTest(settings *config.ParallelTestSettings) *goanalysis.Linter { diff --git a/pkg/golinters/perfsprint.go b/pkg/golinters/perfsprint.go index 6fe315fdea4d..8dc3e56aacc5 100644 --- a/pkg/golinters/perfsprint.go +++ b/pkg/golinters/perfsprint.go @@ -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 NewPerfSprint(settings *config.PerfSprintSettings) *goanalysis.Linter { diff --git a/pkg/golinters/prealloc.go b/pkg/golinters/prealloc.go index 4777614939bf..944286ee09a8 100644 --- a/pkg/golinters/prealloc.go +++ b/pkg/golinters/prealloc.go @@ -8,7 +8,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" "github.com/golangci/golangci-lint/pkg/result" ) @@ -55,7 +56,7 @@ func runPreAlloc(pass *analysis.Pass, settings *config.PreallocSettings) []goana for _, hint := range hints { issues = append(issues, goanalysis.NewIssue(&result.Issue{ Pos: pass.Fset.Position(hint.Pos), - Text: fmt.Sprintf("Consider pre-allocating %s", formatCode(hint.DeclaredSliceName, nil)), + Text: fmt.Sprintf("Consider pre-allocating %s", internal.FormatCode(hint.DeclaredSliceName, nil)), FromLinter: preallocName, }, pass)) } diff --git a/pkg/golinters/predeclared.go b/pkg/golinters/predeclared.go index d3c25e274bb6..e9afa792afe5 100644 --- a/pkg/golinters/predeclared.go +++ b/pkg/golinters/predeclared.go @@ -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 NewPredeclared(settings *config.PredeclaredSettings) *goanalysis.Linter { diff --git a/pkg/golinters/promlinter.go b/pkg/golinters/promlinter.go index 381c57489d0e..59eac10141ba 100644 --- a/pkg/golinters/promlinter.go +++ b/pkg/golinters/promlinter.go @@ -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/result" ) diff --git a/pkg/golinters/protogetter.go b/pkg/golinters/protogetter.go index 9a5e7b4db8eb..fdc5b6641e3c 100644 --- a/pkg/golinters/protogetter.go +++ b/pkg/golinters/protogetter.go @@ -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" "github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/result" ) diff --git a/pkg/golinters/reassign.go b/pkg/golinters/reassign.go index a6dd6705308f..43a6ce43afb4 100644 --- a/pkg/golinters/reassign.go +++ b/pkg/golinters/reassign.go @@ -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" ) func NewReassign(settings *config.ReassignSettings) *goanalysis.Linter { diff --git a/pkg/golinters/revive.go b/pkg/golinters/revive.go index fafdedd5d2c0..0715d93700cd 100644 --- a/pkg/golinters/revive.go +++ b/pkg/golinters/revive.go @@ -16,7 +16,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" "github.com/golangci/golangci-lint/pkg/logutils" "github.com/golangci/golangci-lint/pkg/result" @@ -73,7 +74,7 @@ func NewRevive(settings *config.ReviveSettings) *goanalysis.Linter { } func runRevive(lintCtx *linter.Context, pass *analysis.Pass, settings *config.ReviveSettings) ([]goanalysis.Issue, error) { - packages := [][]string{getFileNames(pass)} + packages := [][]string{internal.GetFileNames(pass)} conf, err := getReviveConfig(settings) if err != nil { diff --git a/pkg/golinters/rowserrcheck.go b/pkg/golinters/rowserrcheck.go index d67efd0692a1..17814c7c0e64 100644 --- a/pkg/golinters/rowserrcheck.go +++ b/pkg/golinters/rowserrcheck.go @@ -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 NewRowsErrCheck(settings *config.RowsErrCheckSettings) *goanalysis.Linter { diff --git a/pkg/golinters/sloglint.go b/pkg/golinters/sloglint.go index 67977453e495..788d0c523731 100644 --- a/pkg/golinters/sloglint.go +++ b/pkg/golinters/sloglint.go @@ -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 NewSlogLint(settings *config.SlogLintSettings) *goanalysis.Linter { diff --git a/pkg/golinters/spancheck.go b/pkg/golinters/spancheck.go index 934124477767..426c318a491a 100644 --- a/pkg/golinters/spancheck.go +++ b/pkg/golinters/spancheck.go @@ -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 NewSpancheck(settings *config.SpancheckSettings) *goanalysis.Linter { diff --git a/pkg/golinters/sqlclosecheck.go b/pkg/golinters/sqlclosecheck.go index e63b292a2046..94fd8b2c09f9 100644 --- a/pkg/golinters/sqlclosecheck.go +++ b/pkg/golinters/sqlclosecheck.go @@ -4,7 +4,7 @@ import ( "github.com/ryanrolds/sqlclosecheck/pkg/analyzer" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewSQLCloseCheck() *goanalysis.Linter { diff --git a/pkg/golinters/staticcheck.go b/pkg/golinters/staticcheck.go index 673484630aba..f0a2e6c03c25 100644 --- a/pkg/golinters/staticcheck.go +++ b/pkg/golinters/staticcheck.go @@ -4,12 +4,13 @@ import ( "honnef.co/go/tools/staticcheck" "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 NewStaticcheck(settings *config.StaticCheckSettings) *goanalysis.Linter { - cfg := staticCheckConfig(settings) - analyzers := setupStaticCheckAnalyzers(staticcheck.Analyzers, getGoVersion(settings), cfg.Checks) + cfg := internal.StaticCheckConfig(settings) + analyzers := internal.SetupStaticCheckAnalyzers(staticcheck.Analyzers, internal.GetGoVersion(settings), cfg.Checks) return goanalysis.NewLinter( "staticcheck", diff --git a/pkg/golinters/stylecheck.go b/pkg/golinters/stylecheck.go index d9b0f87c87d1..338326b90576 100644 --- a/pkg/golinters/stylecheck.go +++ b/pkg/golinters/stylecheck.go @@ -6,11 +6,12 @@ import ( "honnef.co/go/tools/stylecheck" "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 NewStylecheck(settings *config.StaticCheckSettings) *goanalysis.Linter { - cfg := staticCheckConfig(settings) + cfg := internal.StaticCheckConfig(settings) // `scconfig.Analyzer` is a singleton, then it's not possible to have more than one instance for all staticcheck "sub-linters". // When we will merge the 4 "sub-linters", the problem will disappear: https://github.com/golangci/golangci-lint/issues/357 @@ -19,7 +20,7 @@ func NewStylecheck(settings *config.StaticCheckSettings) *goanalysis.Linter { return cfg, nil } - analyzers := setupStaticCheckAnalyzers(stylecheck.Analyzers, getGoVersion(settings), cfg.Checks) + analyzers := internal.SetupStaticCheckAnalyzers(stylecheck.Analyzers, internal.GetGoVersion(settings), cfg.Checks) return goanalysis.NewLinter( "stylecheck", diff --git a/pkg/golinters/tagalign.go b/pkg/golinters/tagalign.go index c23838f702b5..4a2e000fee7b 100644 --- a/pkg/golinters/tagalign.go +++ b/pkg/golinters/tagalign.go @@ -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" "github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/result" ) diff --git a/pkg/golinters/tagliatelle.go b/pkg/golinters/tagliatelle.go index 67c14cbd48e3..73186035365b 100644 --- a/pkg/golinters/tagliatelle.go +++ b/pkg/golinters/tagliatelle.go @@ -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 NewTagliatelle(settings *config.TagliatelleSettings) *goanalysis.Linter { diff --git a/pkg/golinters/tenv.go b/pkg/golinters/tenv.go index 6c6bd3186f78..6c102711dae8 100644 --- a/pkg/golinters/tenv.go +++ b/pkg/golinters/tenv.go @@ -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 NewTenv(settings *config.TenvSettings) *goanalysis.Linter { diff --git a/pkg/golinters/testableexamples.go b/pkg/golinters/testableexamples.go index 3333593a62eb..2cb8127d6e67 100644 --- a/pkg/golinters/testableexamples.go +++ b/pkg/golinters/testableexamples.go @@ -4,7 +4,7 @@ import ( "github.com/maratori/testableexamples/pkg/testableexamples" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewTestableexamples() *goanalysis.Linter { diff --git a/pkg/golinters/testifylint.go b/pkg/golinters/testifylint.go index 32b194f00f8b..dd5763a3d9d2 100644 --- a/pkg/golinters/testifylint.go +++ b/pkg/golinters/testifylint.go @@ -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 NewTestifylint(settings *config.TestifylintSettings) *goanalysis.Linter { diff --git a/pkg/golinters/testpackage.go b/pkg/golinters/testpackage.go index b8a867eb60ce..d572ea0fe083 100644 --- a/pkg/golinters/testpackage.go +++ b/pkg/golinters/testpackage.go @@ -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 NewTestpackage(cfg *config.TestpackageSettings) *goanalysis.Linter { diff --git a/pkg/golinters/thelper.go b/pkg/golinters/thelper.go index 1ae85ef42e1f..b1f96d3d6241 100644 --- a/pkg/golinters/thelper.go +++ b/pkg/golinters/thelper.go @@ -8,7 +8,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 NewThelper(cfg *config.ThelperSettings) *goanalysis.Linter { @@ -40,7 +41,7 @@ func NewThelper(cfg *config.ThelperSettings) *goanalysis.Linter { } if len(opts) == 0 { - linterLogger.Fatalf("thelper: at least one option must be enabled") + internal.LinterLogger.Fatalf("thelper: at least one option must be enabled") } args := maps.Keys(opts) diff --git a/pkg/golinters/tparallel.go b/pkg/golinters/tparallel.go index 643f2c271085..80569ced7413 100644 --- a/pkg/golinters/tparallel.go +++ b/pkg/golinters/tparallel.go @@ -4,7 +4,7 @@ import ( "github.com/moricho/tparallel" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewTparallel() *goanalysis.Linter { diff --git a/pkg/golinters/typecheck.go b/pkg/golinters/typecheck.go index e9b26ef485e1..ed403648b182 100644 --- a/pkg/golinters/typecheck.go +++ b/pkg/golinters/typecheck.go @@ -3,7 +3,7 @@ package golinters import ( "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewTypecheck() *goanalysis.Linter { diff --git a/pkg/golinters/unconvert.go b/pkg/golinters/unconvert.go index 08e493aef09f..c6e6bda931ba 100644 --- a/pkg/golinters/unconvert.go +++ b/pkg/golinters/unconvert.go @@ -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" "github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/result" ) diff --git a/pkg/golinters/unparam.go b/pkg/golinters/unparam.go index 4078d94988fb..6ec35a00f83f 100644 --- a/pkg/golinters/unparam.go +++ b/pkg/golinters/unparam.go @@ -9,7 +9,7 @@ import ( "mvdan.cc/unparam/check" "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" ) diff --git a/pkg/golinters/unused.go b/pkg/golinters/unused.go index a93061c96c33..5e3a8dbd7cfa 100644 --- a/pkg/golinters/unused.go +++ b/pkg/golinters/unused.go @@ -11,7 +11,8 @@ import ( "honnef.co/go/tools/unused" "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" "github.com/golangci/golangci-lint/pkg/result" ) @@ -40,7 +41,7 @@ func NewUnused(settings *config.UnusedSettings, scSettings *config.StaticCheckSe }, } - setAnalyzerGoVersion(analyzer, getGoVersion(scSettings)) + internal.SetAnalyzerGoVersion(analyzer, internal.GetGoVersion(scSettings)) return goanalysis.NewLinter( unusedName, diff --git a/pkg/golinters/usestdlibvars.go b/pkg/golinters/usestdlibvars.go index 663a841ac70a..1b2e5e5c7944 100644 --- a/pkg/golinters/usestdlibvars.go +++ b/pkg/golinters/usestdlibvars.go @@ -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 NewUseStdlibVars(cfg *config.UseStdlibVarsSettings) *goanalysis.Linter { diff --git a/pkg/golinters/varnamelen.go b/pkg/golinters/varnamelen.go index 688dfa804680..bf2e8bff6b40 100644 --- a/pkg/golinters/varnamelen.go +++ b/pkg/golinters/varnamelen.go @@ -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" ) func NewVarnamelen(settings *config.VarnamelenSettings) *goanalysis.Linter { diff --git a/pkg/golinters/wastedassign.go b/pkg/golinters/wastedassign.go index 9038c827dc78..8b48a21cc80a 100644 --- a/pkg/golinters/wastedassign.go +++ b/pkg/golinters/wastedassign.go @@ -4,7 +4,7 @@ import ( "github.com/sanposhiho/wastedassign/v2" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewWastedAssign() *goanalysis.Linter { diff --git a/pkg/golinters/whitespace.go b/pkg/golinters/whitespace.go index 5487b1016ab9..7a09e8d90426 100644 --- a/pkg/golinters/whitespace.go +++ b/pkg/golinters/whitespace.go @@ -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/result" ) diff --git a/pkg/golinters/wrapcheck.go b/pkg/golinters/wrapcheck.go index 6d25db42777e..5a40e943c062 100644 --- a/pkg/golinters/wrapcheck.go +++ b/pkg/golinters/wrapcheck.go @@ -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 NewWrapcheck(settings *config.WrapcheckSettings) *goanalysis.Linter { diff --git a/pkg/golinters/wsl.go b/pkg/golinters/wsl.go index 3b090a686ede..cbef76e18b29 100644 --- a/pkg/golinters/wsl.go +++ b/pkg/golinters/wsl.go @@ -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 NewWSL(settings *config.WSLSettings) *goanalysis.Linter { diff --git a/pkg/golinters/zerologlint.go b/pkg/golinters/zerologlint.go index edde726655f3..a1346172af46 100644 --- a/pkg/golinters/zerologlint.go +++ b/pkg/golinters/zerologlint.go @@ -4,7 +4,7 @@ import ( "github.com/ykadowak/zerologlint" "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" + "github.com/golangci/golangci-lint/pkg/goanalysis" ) func NewZerologLint() *goanalysis.Linter { diff --git a/pkg/lint/context.go b/pkg/lint/context.go index 22c95e08af86..160620338f8c 100644 --- a/pkg/lint/context.go +++ b/pkg/lint/context.go @@ -8,7 +8,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/lint/linter" "github.com/golangci/golangci-lint/pkg/logutils" ) diff --git a/pkg/lint/linter/context.go b/pkg/lint/linter/context.go index 81d1560f7d2e..5c03630b26df 100644 --- a/pkg/lint/linter/context.go +++ b/pkg/lint/linter/context.go @@ -8,7 +8,7 @@ import ( "github.com/golangci/golangci-lint/internal/pkgcache" "github.com/golangci/golangci-lint/pkg/config" "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/logutils" ) diff --git a/pkg/lint/lintersdb/builder_plugin_go.go b/pkg/lint/lintersdb/builder_plugin_go.go index 4c6b4b5988f5..2a349c9563c6 100644 --- a/pkg/lint/lintersdb/builder_plugin_go.go +++ b/pkg/lint/lintersdb/builder_plugin_go.go @@ -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/logutils" ) diff --git a/pkg/lint/lintersdb/builder_plugin_module.go b/pkg/lint/lintersdb/builder_plugin_module.go index 904b18bd5e4d..60fb58d8ce3a 100644 --- a/pkg/lint/lintersdb/builder_plugin_module.go +++ b/pkg/lint/lintersdb/builder_plugin_module.go @@ -7,7 +7,7 @@ import ( "github.com/golangci/plugin-module-register/register" "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" ) diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 981660589202..0cd6cec24af9 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -9,7 +9,7 @@ import ( "golang.org/x/exp/maps" "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" ) diff --git a/pkg/lint/lintersdb/manager_test.go b/pkg/lint/lintersdb/manager_test.go index 87fffa82f9cf..856f41558de6 100644 --- a/pkg/lint/lintersdb/manager_test.go +++ b/pkg/lint/lintersdb/manager_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" "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" ) diff --git a/pkg/lint/package.go b/pkg/lint/package.go index e8222a455431..7faa399e9873 100644 --- a/pkg/lint/package.go +++ b/pkg/lint/package.go @@ -15,7 +15,7 @@ import ( "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/exitcodes" - "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/linter" "github.com/golangci/golangci-lint/pkg/logutils"