golangci-lint/pkg/lint/lintersdb/manager.go

647 lines
23 KiB
Go
Raw Normal View History

2018-06-02 11:36:50 +03:00
package lintersdb
import (
"fmt"
"path/filepath"
"plugin"
"github.com/spf13/viper"
"golang.org/x/tools/go/analysis"
"github.com/golangci/golangci-lint/pkg/config"
2018-05-06 19:08:34 +03:00
"github.com/golangci/golangci-lint/pkg/golinters"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
2018-06-02 11:36:50 +03:00
"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/report"
)
type Manager struct {
nameToLCs map[string][]*linter.Config
cfg *config.Config
log logutils.Log
}
func NewManager(cfg *config.Config, log logutils.Log) *Manager {
m := &Manager{cfg: cfg, log: log}
nameToLCs := make(map[string][]*linter.Config)
for _, lc := range m.GetAllSupportedLinterConfigs() {
for _, name := range lc.AllNames() {
nameToLCs[name] = append(nameToLCs[name], lc)
}
}
m.nameToLCs = nameToLCs
return m
}
func (m *Manager) WithCustomLinters() *Manager {
if m.log == nil {
m.log = report.NewLogWrapper(logutils.NewStderrLog(""), &report.Data{})
}
if m.cfg != nil {
for name, settings := range m.cfg.LintersSettings.Custom {
lc, err := m.loadCustomLinterConfig(name, settings)
if err != nil {
m.log.Errorf("Unable to load custom analyzer %s:%s, %v",
name,
settings.Path,
err)
} else {
m.nameToLCs[name] = append(m.nameToLCs[name], lc)
}
}
}
return m
}
func (Manager) AllPresets() []string {
2020-10-02 13:00:46 -07:00
return []string{
2021-03-16 13:33:28 +01:00
linter.PresetBugs,
linter.PresetComment,
linter.PresetComplexity,
linter.PresetError,
linter.PresetFormatting,
linter.PresetImport,
linter.PresetMetaLinter,
linter.PresetModule,
linter.PresetPerformance,
linter.PresetSQL,
linter.PresetStyle,
linter.PresetTest,
linter.PresetUnused,
2020-10-02 13:00:46 -07:00
}
}
func (m Manager) allPresetsSet() map[string]bool {
ret := map[string]bool{}
for _, p := range m.AllPresets() {
ret[p] = true
}
return ret
}
func (m Manager) GetLinterConfigs(name string) []*linter.Config {
return m.nameToLCs[name]
2018-05-06 19:08:34 +03:00
}
func enableLinterConfigs(lcs []*linter.Config, isEnabled func(lc *linter.Config) bool) []*linter.Config {
var ret []*linter.Config
for _, lc := range lcs {
2018-11-05 22:29:45 +03:00
lc := lc
lc.EnabledByDefault = isEnabled(lc)
ret = append(ret, lc)
}
return ret
}
2019-09-09 18:07:09 +03:00
//nolint:funlen
func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
2021-09-17 11:25:37 +03:00
var cyclopCfg *config.Cyclop
var errorlintCfg *config.ErrorLintSettings
var exhaustiveCfg *config.ExhaustiveSettings
var exhaustiveStructCfg *config.ExhaustiveStructSettings
2021-03-09 18:59:06 +01:00
var goModDirectivesCfg *config.GoModDirectivesSettings
2021-04-24 23:20:12 +02:00
var gosecCfg *config.GoSecSettings
var gosimpleCfg *config.StaticCheckSettings
2021-09-17 11:25:37 +03:00
var govetCfg *config.GovetSettings
var ifshortCfg *config.IfshortSettings
var importAsCfg *config.ImportAsSettings
var ireturnCfg *config.IreturnSettings
var nilNilCfg *config.NilNilSettings
var predeclaredCfg *config.PredeclaredSettings
var reviveCfg *config.ReviveSettings
var staticcheckCfg *config.StaticCheckSettings
var stylecheckCfg *config.StaticCheckSettings
2021-09-17 11:25:37 +03:00
var tagliatelleCfg *config.TagliatelleSettings
2021-09-27 02:50:47 +09:00
var tenvCfg *config.TenvSettings
2021-09-17 11:25:37 +03:00
var testpackageCfg *config.TestpackageSettings
var thelperCfg *config.ThelperSettings
var unusedCfg *config.StaticCheckSettings
var wrapcheckCfg *config.WrapcheckSettings
var nlreturnCfg *config.NlreturnSettings
if m.cfg != nil {
2021-09-17 11:25:37 +03:00
cyclopCfg = &m.cfg.LintersSettings.Cyclop
errorlintCfg = &m.cfg.LintersSettings.ErrorLint
exhaustiveCfg = &m.cfg.LintersSettings.Exhaustive
exhaustiveStructCfg = &m.cfg.LintersSettings.ExhaustiveStruct
2021-03-09 18:59:06 +01:00
goModDirectivesCfg = &m.cfg.LintersSettings.GoModDirectives
2021-04-24 23:20:12 +02:00
gosecCfg = &m.cfg.LintersSettings.Gosec
gosimpleCfg = &m.cfg.LintersSettings.Gosimple
2021-09-17 11:25:37 +03:00
govetCfg = &m.cfg.LintersSettings.Govet
ifshortCfg = &m.cfg.LintersSettings.Ifshort
importAsCfg = &m.cfg.LintersSettings.ImportAs
ireturnCfg = &m.cfg.LintersSettings.Ireturn
nilNilCfg = &m.cfg.LintersSettings.NilNil
predeclaredCfg = &m.cfg.LintersSettings.Predeclared
reviveCfg = &m.cfg.LintersSettings.Revive
staticcheckCfg = &m.cfg.LintersSettings.Staticcheck
stylecheckCfg = &m.cfg.LintersSettings.Stylecheck
2021-09-17 11:25:37 +03:00
tagliatelleCfg = &m.cfg.LintersSettings.Tagliatelle
2021-09-27 02:50:47 +09:00
tenvCfg = &m.cfg.LintersSettings.Tenv
2021-09-17 11:25:37 +03:00
testpackageCfg = &m.cfg.LintersSettings.Testpackage
thelperCfg = &m.cfg.LintersSettings.Thelper
unusedCfg = &m.cfg.LintersSettings.Unused
wrapcheckCfg = &m.cfg.LintersSettings.Wrapcheck
nlreturnCfg = &m.cfg.LintersSettings.Nlreturn
}
const megacheckName = "megacheck"
lcs := []*linter.Config{
linter.NewConfig(golinters.NewGovet(govetCfg)).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetBugs, linter.PresetMetaLinter).
WithAlternativeNames("vet", "vetshadow").
2018-06-02 11:36:50 +03:00
WithURL("https://golang.org/cmd/vet/"),
linter.NewConfig(golinters.NewBodyclose()).
WithSince("v1.18.0").
WithLoadForGoAnalysis().
WithPresets(linter.PresetPerformance, linter.PresetBugs).
WithURL("https://github.com/timakin/bodyclose"),
linter.NewConfig(golinters.NewNoctx()).
WithSince("v1.28.0").
WithLoadForGoAnalysis().
WithPresets(linter.PresetPerformance, linter.PresetBugs).
WithURL("https://github.com/sonatard/noctx"),
linter.NewConfig(golinters.NewErrcheck()).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetBugs, linter.PresetError).
2018-06-02 11:36:50 +03:00
WithURL("https://github.com/kisielk/errcheck"),
linter.NewConfig(golinters.NewGolint()).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetStyle).
2021-05-11 00:50:50 +02:00
WithURL("https://github.com/golang/lint").
Deprecated("The repository of the linter has been archived by the owner.", "v1.41.0", "revive"),
linter.NewConfig(golinters.NewRowsErrCheck()).
WithSince("v1.23.0").
WithLoadForGoAnalysis().
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetBugs, linter.PresetSQL).
2020-01-21 21:09:18 -05:00
WithURL("https://github.com/jingyugao/rowserrcheck"),
2018-06-02 11:36:50 +03:00
linter.NewConfig(golinters.NewStaticcheck(staticcheckCfg)).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetBugs, linter.PresetMetaLinter).
WithAlternativeNames(megacheckName).
2018-06-02 11:36:50 +03:00
WithURL("https://staticcheck.io/"),
linter.NewConfig(golinters.NewUnused(unusedCfg)).
WithSince("v1.20.0").
WithLoadForGoAnalysis().
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetUnused).
WithAlternativeNames(megacheckName).
ConsiderSlow().
WithChangeTypes().
WithURL("https://github.com/dominikh/go-tools/tree/master/unused"),
linter.NewConfig(golinters.NewGosimple(gosimpleCfg)).
WithSince("v1.20.0").
WithLoadForGoAnalysis().
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetStyle).
WithAlternativeNames(megacheckName).
WithURL("https://github.com/dominikh/go-tools/tree/master/simple"),
linter.NewConfig(golinters.NewStylecheck(stylecheckCfg)).
WithSince("v1.20.0").
WithLoadForGoAnalysis().
WithPresets(linter.PresetStyle).
WithURL("https://github.com/dominikh/go-tools/tree/master/stylecheck"),
2021-04-24 23:20:12 +02:00
linter.NewConfig(golinters.NewGosec(gosecCfg)).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetBugs).
WithURL("https://github.com/securego/gosec").
WithAlternativeNames("gas"),
linter.NewConfig(golinters.NewStructcheck()).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetUnused).
WithURL("https://github.com/opennota/check"),
linter.NewConfig(golinters.NewVarcheck()).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetUnused).
WithURL("https://github.com/opennota/check"),
linter.NewConfig(golinters.NewInterfacer()).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetStyle).
2021-02-20 18:55:11 -06:00
WithURL("https://github.com/mvdan/interfacer").
Deprecated("The repository of the linter has been archived by the owner.", "v1.38.0", ""),
linter.NewConfig(golinters.NewUnconvert()).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetStyle).
WithURL("https://github.com/mdempsky/unconvert"),
linter.NewConfig(golinters.NewIneffassign()).
WithSince("v1.0.0").
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetUnused).
WithURL("https://github.com/gordonklaus/ineffassign"),
linter.NewConfig(golinters.NewDupl()).
WithSince("v1.0.0").
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetStyle).
WithURL("https://github.com/mibk/dupl"),
linter.NewConfig(golinters.NewGoconst()).
2021-03-21 23:06:40 +01:00
WithSince("v1.0.0").
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetStyle).
WithURL("https://github.com/jgautheron/goconst"),
linter.NewConfig(golinters.NewDeadcode()).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetUnused).
WithURL("https://github.com/remyoudompheng/go-misc/tree/master/deadcode"),
linter.NewConfig(golinters.NewGocyclo()).
WithSince("v1.0.0").
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetComplexity).
WithURL("https://github.com/fzipp/gocyclo"),
2021-02-18 21:17:04 +01:00
linter.NewConfig(golinters.NewCyclop(cyclopCfg)).
WithSince("v1.37.0").
2021-02-17 09:48:29 +01:00
WithLoadForGoAnalysis().
WithPresets(linter.PresetComplexity).
WithURL("https://github.com/bkielbasa/cyclop"),
linter.NewConfig(golinters.NewGocognit()).
WithSince("v1.20.0").
WithPresets(linter.PresetComplexity).
WithURL("https://github.com/uudashr/gocognit"),
linter.NewConfig(golinters.NewTypecheck()).
WithSince("v1.3.0").
WithLoadForGoAnalysis().
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetBugs).
WithURL(""),
2020-04-16 23:19:12 +03:00
linter.NewConfig(golinters.NewAsciicheck()).
WithSince("v1.26.0").
2020-04-16 23:19:12 +03:00
WithPresets(linter.PresetBugs, linter.PresetStyle).
WithURL("https://github.com/tdakkota/asciicheck"),
2018-06-02 11:36:50 +03:00
linter.NewConfig(golinters.NewGofmt()).
WithSince("v1.0.0").
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetFormatting).
WithAutoFix().
2018-06-02 11:36:50 +03:00
WithURL("https://golang.org/cmd/gofmt/"),
2020-06-16 12:05:28 +02:00
linter.NewConfig(golinters.NewGofumpt()).
WithSince("v1.28.0").
2020-06-16 12:05:28 +02:00
WithPresets(linter.PresetFormatting).
WithAutoFix().
2020-06-16 12:05:28 +02:00
WithURL("https://github.com/mvdan/gofumpt"),
linter.NewConfig(golinters.NewGoimports()).
WithSince("v1.20.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetFormatting, linter.PresetImport).
WithAutoFix().
2018-06-02 11:36:50 +03:00
WithURL("https://godoc.org/golang.org/x/tools/cmd/goimports"),
linter.NewConfig(golinters.NewGoHeader()).
WithSince("v1.28.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/denis-tingajkin/go-header"),
linter.NewConfig(golinters.NewGci()).
WithSince("v1.30.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetFormatting, linter.PresetImport).
WithAutoFix().
WithURL("https://github.com/daixiang0/gci"),
linter.NewConfig(golinters.NewMaligned()).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
2018-06-02 11:36:50 +03:00
WithPresets(linter.PresetPerformance).
WithURL("https://github.com/mdempsky/maligned").
Deprecated("The repository of the linter has been archived by the owner.", "v1.38.0", "govet 'fieldalignment'"),
linter.NewConfig(golinters.NewDepguard()).
WithSince("v1.4.0").
WithLoadForGoAnalysis().
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetImport, linter.PresetModule).
2018-06-02 11:36:50 +03:00
WithURL("https://github.com/OpenPeeDeeP/depguard"),
linter.NewConfig(golinters.NewMisspell()).
WithSince("v1.8.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetComment).
WithAutoFix().
2018-06-28 21:27:07 +03:00
WithURL("https://github.com/client9/misspell"),
linter.NewConfig(golinters.NewLLL()).
WithSince("v1.8.0").
2021-03-14 14:15:52 +01:00
WithPresets(linter.PresetStyle),
linter.NewConfig(golinters.NewUnparam()).
WithSince("v1.9.0").
WithPresets(linter.PresetUnused).
WithLoadForGoAnalysis().
WithURL("https://github.com/mvdan/unparam"),
linter.NewConfig(golinters.NewDogsled()).
WithSince("v1.19.0").
2019-09-17 01:44:53 -04:00
WithPresets(linter.PresetStyle).
WithURL("https://github.com/alexkohler/dogsled"),
linter.NewConfig(golinters.NewNakedret()).
WithSince("v1.19.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle).
2018-06-30 13:55:47 +03:00
WithURL("https://github.com/alexkohler/nakedret"),
linter.NewConfig(golinters.NewPrealloc()).
WithSince("v1.19.0").
2018-06-30 21:02:41 +03:00
WithPresets(linter.PresetPerformance).
WithURL("https://github.com/alexkohler/prealloc"),
linter.NewConfig(golinters.NewScopelint()).
WithSince("v1.12.0").
2018-11-05 22:29:45 +03:00
WithPresets(linter.PresetBugs).
WithURL("https://github.com/kyoh86/scopelint").
Deprecated("The repository of the linter has been deprecated by the owner.", "v1.39.0", "exportloopref"),
linter.NewConfig(golinters.NewGocritic()).
WithSince("v1.12.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetMetaLinter).
WithLoadForGoAnalysis().
2018-11-05 18:20:28 +03:00
WithURL("https://github.com/go-critic/go-critic"),
linter.NewConfig(golinters.NewGochecknoinits()).
WithSince("v1.12.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/leighmcculloch/gochecknoinits"),
linter.NewConfig(golinters.NewGochecknoglobals()).
WithSince("v1.12.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/leighmcculloch/gochecknoglobals"),
linter.NewConfig(golinters.NewGodox()).
WithSince("v1.19.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetComment).
WithURL("https://github.com/matoous/godox"),
linter.NewConfig(golinters.NewFunlen()).
WithSince("v1.18.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetComplexity).
2019-09-09 15:56:30 +02:00
WithURL("https://github.com/ultraware/funlen"),
linter.NewConfig(golinters.NewWhitespace()).
WithSince("v1.19.0").
2019-09-10 12:25:01 +02:00
WithPresets(linter.PresetStyle).
WithAutoFix().
2019-09-10 12:25:01 +02:00
WithURL("https://github.com/ultraware/whitespace"),
linter.NewConfig(golinters.NewWSL()).
WithSince("v1.20.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/bombsimon/wsl"),
2020-01-19 16:46:51 +03:00
linter.NewConfig(golinters.NewGoPrintfFuncName()).
WithSince("v1.23.0").
2020-01-19 16:46:51 +03:00
WithPresets(linter.PresetStyle).
WithURL("https://github.com/jirfag/go-printf-func-name"),
linter.NewConfig(golinters.NewGoMND(m.cfg)).
WithSince("v1.22.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/tommy-muehle/go-mnd"),
2020-04-22 20:43:40 +03:00
linter.NewConfig(golinters.NewGoerr113()).
WithSince("v1.26.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetError).
2020-05-13 21:22:52 +03:00
WithLoadForGoAnalysis().
2020-04-22 20:43:40 +03:00
WithURL("https://github.com/Djarvur/go-err113"),
linter.NewConfig(golinters.NewGomodguard()).
WithSince("v1.25.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetImport, linter.PresetModule).
2020-04-10 18:39:44 -04:00
WithURL("https://github.com/ryancurrah/gomodguard"),
2020-03-16 09:03:59 +03:00
linter.NewConfig(golinters.NewGodot()).
WithSince("v1.25.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetComment).
2020-05-18 15:49:58 +03:00
WithAutoFix().
2020-03-16 09:03:59 +03:00
WithURL("https://github.com/tetafro/godot"),
2019-11-10 01:05:27 +03:00
linter.NewConfig(golinters.NewTestpackage(testpackageCfg)).
WithSince("v1.25.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetTest).
2019-11-10 01:05:27 +03:00
WithURL("https://github.com/maratori/testpackage"),
2020-02-02 14:58:38 +09:00
linter.NewConfig(golinters.NewNestif()).
WithSince("v1.25.0").
2020-02-02 14:58:38 +09:00
WithPresets(linter.PresetComplexity).
WithURL("https://github.com/nakabonne/nestif"),
2020-05-24 17:31:32 +10:00
linter.NewConfig(golinters.NewExportLoopRef()).
WithSince("v1.28.0").
2020-05-24 17:31:32 +10:00
WithPresets(linter.PresetBugs).
WithLoadForGoAnalysis().
2020-05-24 17:31:32 +10:00
WithURL("https://github.com/kyoh86/exportloopref"),
linter.NewConfig(golinters.NewExhaustive(exhaustiveCfg)).
WithSince(" v1.28.0").
WithPresets(linter.PresetBugs).
WithLoadForGoAnalysis().
WithURL("https://github.com/nishanths/exhaustive"),
linter.NewConfig(golinters.NewSQLCloseCheck()).
WithSince("v1.28.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetBugs, linter.PresetSQL).
WithLoadForGoAnalysis().
WithURL("https://github.com/ryanrolds/sqlclosecheck"),
linter.NewConfig(golinters.NewNLReturn(nlreturnCfg)).
WithSince("v1.30.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/ssgreg/nlreturn"),
linter.NewConfig(golinters.NewWrapcheck(wrapcheckCfg)).
WithSince("v1.32.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetError).
WithLoadForGoAnalysis().
WithURL("https://github.com/tomarrell/wrapcheck"),
2020-12-13 16:54:26 +03:00
linter.NewConfig(golinters.NewThelper(thelperCfg)).
WithSince("v1.34.0").
2020-12-13 16:54:26 +03:00
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/kulti/thelper"),
2020-10-02 13:00:46 -07:00
linter.NewConfig(golinters.NewTparallel()).
WithSince("v1.32.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetTest).
2020-10-02 13:00:46 -07:00
WithLoadForGoAnalysis().
WithURL("https://github.com/moricho/tparallel"),
linter.NewConfig(golinters.NewExhaustiveStruct(exhaustiveStructCfg)).
WithSince("v1.32.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetTest).
WithLoadForGoAnalysis().
WithURL("https://github.com/mbilski/exhaustivestruct"),
linter.NewConfig(golinters.NewErrorLint(errorlintCfg)).
WithSince("v1.32.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetBugs, linter.PresetError).
WithLoadForGoAnalysis().
WithURL("https://github.com/polyfloyd/go-errorlint"),
2020-11-23 06:28:38 +11:00
linter.NewConfig(golinters.NewParallelTest()).
WithSince("v1.33.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetTest).
2020-11-23 06:28:38 +11:00
WithURL("https://github.com/kunwardeep/paralleltest"),
linter.NewConfig(golinters.NewMakezero()).
WithSince("v1.34.0").
WithPresets(linter.PresetStyle, linter.PresetBugs).
WithLoadForGoAnalysis().
WithURL("https://github.com/ashanbrown/makezero"),
2020-12-24 08:19:32 -08:00
linter.NewConfig(golinters.NewForbidigo()).
WithSince("v1.34.0").
2020-12-24 08:19:32 -08:00
WithPresets(linter.PresetStyle).
WithURL("https://github.com/ashanbrown/forbidigo"),
linter.NewConfig(golinters.NewIfshort(ifshortCfg)).
WithSince("v1.36.0").
2021-01-21 00:07:43 +02:00
WithPresets(linter.PresetStyle).
WithURL("https://github.com/esimonov/ifshort"),
2021-01-07 22:28:04 +05:30
linter.NewConfig(golinters.NewPredeclared(predeclaredCfg)).
WithSince("v1.35.0").
2021-01-07 22:28:04 +05:30
WithPresets(linter.PresetStyle).
WithURL("https://github.com/nishanths/predeclared"),
2021-02-14 07:36:37 -06:00
linter.NewConfig(golinters.NewRevive(reviveCfg)).
WithSince("v1.37.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetMetaLinter).
ConsiderSlow().
2021-02-14 07:36:37 -06:00
WithURL("https://github.com/mgechev/revive"),
linter.NewConfig(golinters.NewDurationCheck()).
WithSince("v1.37.0").
WithPresets(linter.PresetBugs).
WithLoadForGoAnalysis().
WithURL("https://github.com/charithe/durationcheck"),
2021-02-22 06:01:51 +09:00
linter.NewConfig(golinters.NewWastedAssign()).
WithSince("v1.38.0").
2021-02-22 06:01:51 +09:00
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/sanposhiho/wastedassign"),
linter.NewConfig(golinters.NewImportAs(importAsCfg)).
WithSince("v1.38.0").
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/julz/importas"),
2021-02-26 22:12:32 +01:00
linter.NewConfig(golinters.NewNilErr()).
WithSince("v1.38.0").
2021-02-26 22:12:32 +01:00
WithLoadForGoAnalysis().
WithPresets(linter.PresetBugs).
WithURL("https://github.com/gostaticanalysis/nilerr"),
2021-02-26 22:34:12 +01:00
linter.NewConfig(golinters.NewForceTypeAssert()).
WithSince("v1.38.0").
2021-02-26 22:34:12 +01:00
WithPresets(linter.PresetStyle).
WithURL("https://github.com/gostaticanalysis/forcetypeassert"),
2021-03-09 18:59:06 +01:00
linter.NewConfig(golinters.NewGoModDirectives(goModDirectivesCfg)).
WithSince("v1.39.0").
2021-03-16 13:33:28 +01:00
WithPresets(linter.PresetStyle, linter.PresetModule).
2021-03-09 18:59:06 +01:00
WithURL("https://github.com/ldez/gomoddirectives"),
linter.NewConfig(golinters.NewPromlinter()).
WithSince("v1.40.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/yeya24/promlinter"),
2021-04-12 17:59:50 +02:00
linter.NewConfig(golinters.NewTagliatelle(tagliatelleCfg)).
WithSince("v1.40.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/ldez/tagliatelle"),
linter.NewConfig(golinters.NewErrName()).
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/Antonboom/errname").
WithSince("v1.42.0"),
linter.NewConfig(golinters.NewIreturn(ireturnCfg)).
WithSince("v1.43.0").
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/butuzov/ireturn"),
2021-09-17 11:25:37 +03:00
linter.NewConfig(golinters.NewNilNil(nilNilCfg)).
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/Antonboom/nilnil").
WithSince("v1.43.0"),
2021-09-27 02:50:47 +09:00
linter.NewConfig(golinters.NewTenv(tenvCfg)).
WithSince("v1.43.0").
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/sivchari/tenv"),
2021-10-05 05:21:50 +08:00
linter.NewConfig(golinters.NewContextCheck()).
WithPresets(linter.PresetBugs).
WithLoadForGoAnalysis().
WithURL("https://github.com/sylvia7788/contextcheck").
WithSince("v1.43.0"),
2021-04-12 17:59:50 +02:00
// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
linter.NewConfig(golinters.NewNoLintLint()).
WithSince("v1.26.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/golangci/golangci-lint/blob/master/pkg/golinters/nolintlint/README.md"),
}
enabledByDefault := map[string]bool{
golinters.NewGovet(nil).Name(): true,
golinters.NewErrcheck().Name(): true,
golinters.NewStaticcheck(staticcheckCfg).Name(): true,
golinters.NewUnused(unusedCfg).Name(): true,
golinters.NewGosimple(gosimpleCfg).Name(): true,
golinters.NewStructcheck().Name(): true,
golinters.NewVarcheck().Name(): true,
golinters.NewIneffassign().Name(): true,
golinters.NewDeadcode().Name(): true,
golinters.NewTypecheck().Name(): true,
}
2018-06-02 11:36:50 +03:00
return enableLinterConfigs(lcs, func(lc *linter.Config) bool {
return enabledByDefault[lc.Name()]
})
}
func (m Manager) GetAllEnabledByDefaultLinters() []*linter.Config {
var ret []*linter.Config
for _, lc := range m.GetAllSupportedLinterConfigs() {
if lc.EnabledByDefault {
ret = append(ret, lc)
}
}
return ret
}
func linterConfigsToMap(lcs []*linter.Config) map[string]*linter.Config {
2018-06-02 11:36:50 +03:00
ret := map[string]*linter.Config{}
for _, lc := range lcs {
lc := lc // local copy
ret[lc.Name()] = lc
}
return ret
}
func (m Manager) GetAllLinterConfigsForPreset(p string) []*linter.Config {
var ret []*linter.Config
for _, lc := range m.GetAllSupportedLinterConfigs() {
for _, ip := range lc.InPresets {
if p == ip {
ret = append(ret, lc)
break
}
}
}
return ret
}
func (m Manager) loadCustomLinterConfig(name string, settings config.CustomLinterSettings) (*linter.Config, error) {
analyzer, err := m.getAnalyzerPlugin(settings.Path)
if err != nil {
return nil, err
}
m.log.Infof("Loaded %s: %s", settings.Path, name)
customLinter := goanalysis.NewLinter(
name,
settings.Description,
analyzer.GetAnalyzers(),
nil).WithLoadMode(goanalysis.LoadModeTypesInfo)
linterConfig := linter.NewConfig(customLinter)
linterConfig.EnabledByDefault = true
linterConfig.IsSlow = false
linterConfig.WithURL(settings.OriginalURL)
return linterConfig, nil
}
type AnalyzerPlugin interface {
GetAnalyzers() []*analysis.Analyzer
}
func (m Manager) getAnalyzerPlugin(path string) (AnalyzerPlugin, error) {
if !filepath.IsAbs(path) {
// resolve non-absolute paths relative to config file's directory
configFilePath := viper.ConfigFileUsed()
absConfigFilePath, err := filepath.Abs(configFilePath)
if err != nil {
return nil, fmt.Errorf("could not get absolute representation of config file path %q: %v", configFilePath, err)
}
path = filepath.Join(filepath.Dir(absConfigFilePath), path)
}
plug, err := plugin.Open(path)
if err != nil {
return nil, err
}
symbol, err := plug.Lookup("AnalyzerPlugin")
if err != nil {
return nil, err
}
analyzerPlugin, ok := symbol.(AnalyzerPlugin)
if !ok {
return nil, fmt.Errorf("plugin %s does not abide by 'AnalyzerPlugin' interface", path)
}
return analyzerPlugin, nil
}