github.com/chenfeining/golangci-lint@v1.0.2-0.20230730162517-14c6c67868df/pkg/lint/lintersdb/manager.go (about)

     1  package lintersdb
     2  
     3  import (
     4  	"github.com/chenfeining/golangci-lint/pkg/config"
     5  	"github.com/chenfeining/golangci-lint/pkg/golinters"
     6  	"github.com/chenfeining/golangci-lint/pkg/lint/linter"
     7  	"github.com/chenfeining/golangci-lint/pkg/logutils"
     8  )
     9  
    10  type Manager struct {
    11  	cfg *config.Config
    12  	log logutils.Log
    13  
    14  	nameToLCs     map[string][]*linter.Config
    15  	customLinters []*linter.Config
    16  }
    17  
    18  func NewManager(cfg *config.Config, log logutils.Log) *Manager {
    19  	m := &Manager{cfg: cfg, log: log}
    20  	m.customLinters = m.getCustomLinterConfigs()
    21  
    22  	nameToLCs := make(map[string][]*linter.Config)
    23  	for _, lc := range m.GetAllSupportedLinterConfigs() {
    24  		for _, name := range lc.AllNames() {
    25  			nameToLCs[name] = append(nameToLCs[name], lc)
    26  		}
    27  	}
    28  
    29  	m.nameToLCs = nameToLCs
    30  
    31  	return m
    32  }
    33  
    34  func (Manager) AllPresets() []string {
    35  	return []string{
    36  		linter.PresetBugs,
    37  		linter.PresetComment,
    38  		linter.PresetComplexity,
    39  		linter.PresetError,
    40  		linter.PresetFormatting,
    41  		linter.PresetImport,
    42  		linter.PresetMetaLinter,
    43  		linter.PresetModule,
    44  		linter.PresetPerformance,
    45  		linter.PresetSQL,
    46  		linter.PresetStyle,
    47  		linter.PresetTest,
    48  		linter.PresetUnused,
    49  	}
    50  }
    51  
    52  func (m Manager) allPresetsSet() map[string]bool {
    53  	ret := map[string]bool{}
    54  	for _, p := range m.AllPresets() {
    55  		ret[p] = true
    56  	}
    57  	return ret
    58  }
    59  
    60  func (m Manager) GetLinterConfigs(name string) []*linter.Config {
    61  	return m.nameToLCs[name]
    62  }
    63  
    64  //nolint:funlen
    65  func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
    66  	var (
    67  		asasalintCfg        *config.AsasalintSettings
    68  		bidichkCfg          *config.BiDiChkSettings
    69  		cyclopCfg           *config.Cyclop
    70  		decorderCfg         *config.DecorderSettings
    71  		depGuardCfg         *config.DepGuardSettings
    72  		dogsledCfg          *config.DogsledSettings
    73  		duplCfg             *config.DuplSettings
    74  		dupwordCfg          *config.DupWordSettings
    75  		errcheckCfg         *config.ErrcheckSettings
    76  		errchkjsonCfg       *config.ErrChkJSONSettings
    77  		errorlintCfg        *config.ErrorLintSettings
    78  		exhaustiveCfg       *config.ExhaustiveSettings
    79  		exhaustiveStructCfg *config.ExhaustiveStructSettings
    80  		exhaustructCfg      *config.ExhaustructSettings
    81  		forbidigoCfg        *config.ForbidigoSettings
    82  		funlenCfg           *config.FunlenSettings
    83  		gciCfg              *config.GciSettings
    84  		ginkgolinterCfg     *config.GinkgoLinterSettings
    85  		gocognitCfg         *config.GocognitSettings
    86  		goconstCfg          *config.GoConstSettings
    87  		gocriticCfg         *config.GoCriticSettings
    88  		gocycloCfg          *config.GoCycloSettings
    89  		godotCfg            *config.GodotSettings
    90  		godoxCfg            *config.GodoxSettings
    91  		gofmtCfg            *config.GoFmtSettings
    92  		gofumptCfg          *config.GofumptSettings
    93  		goheaderCfg         *config.GoHeaderSettings
    94  		goimportsCfg        *config.GoImportsSettings
    95  		golintCfg           *config.GoLintSettings
    96  		goMndCfg            *config.GoMndSettings
    97  		goModDirectivesCfg  *config.GoModDirectivesSettings
    98  		gomodguardCfg       *config.GoModGuardSettings
    99  		gosecCfg            *config.GoSecSettings
   100  		gosimpleCfg         *config.StaticCheckSettings
   101  		gosmopolitanCfg     *config.GosmopolitanSettings
   102  		govetCfg            *config.GovetSettings
   103  		grouperCfg          *config.GrouperSettings
   104  		ifshortCfg          *config.IfshortSettings
   105  		importAsCfg         *config.ImportAsSettings
   106  		interfaceBloatCfg   *config.InterfaceBloatSettings
   107  		ireturnCfg          *config.IreturnSettings
   108  		lllCfg              *config.LllSettings
   109  		loggerCheckCfg      *config.LoggerCheckSettings
   110  		maintIdxCfg         *config.MaintIdxSettings
   111  		makezeroCfg         *config.MakezeroSettings
   112  		malignedCfg         *config.MalignedSettings
   113  		misspellCfg         *config.MisspellSettings
   114  		musttagCfg          *config.MustTagSettings
   115  		nakedretCfg         *config.NakedretSettings
   116  		nestifCfg           *config.NestifSettings
   117  		nilNilCfg           *config.NilNilSettings
   118  		nlreturnCfg         *config.NlreturnSettings
   119  		noLintLintCfg       *config.NoLintLintSettings
   120  		noNamedReturnsCfg   *config.NoNamedReturnsSettings
   121  		parallelTestCfg     *config.ParallelTestSettings
   122  		preallocCfg         *config.PreallocSettings
   123  		predeclaredCfg      *config.PredeclaredSettings
   124  		promlinterCfg       *config.PromlinterSettings
   125  		reassignCfg         *config.ReassignSettings
   126  		reviveCfg           *config.ReviveSettings
   127  		rowserrcheckCfg     *config.RowsErrCheckSettings
   128  		staticcheckCfg      *config.StaticCheckSettings
   129  		structcheckCfg      *config.StructCheckSettings
   130  		stylecheckCfg       *config.StaticCheckSettings
   131  		tagalignCfg         *config.TagAlignSettings
   132  		tagliatelleCfg      *config.TagliatelleSettings
   133  		tenvCfg             *config.TenvSettings
   134  		testpackageCfg      *config.TestpackageSettings
   135  		thelperCfg          *config.ThelperSettings
   136  		unparamCfg          *config.UnparamSettings
   137  		unusedCfg           *config.StaticCheckSettings
   138  		usestdlibvars       *config.UseStdlibVarsSettings
   139  		varcheckCfg         *config.VarCheckSettings
   140  		varnamelenCfg       *config.VarnamelenSettings
   141  		whitespaceCfg       *config.WhitespaceSettings
   142  		wrapcheckCfg        *config.WrapcheckSettings
   143  		wslCfg              *config.WSLSettings
   144  	)
   145  
   146  	if m.cfg != nil {
   147  		asasalintCfg = &m.cfg.LintersSettings.Asasalint
   148  		bidichkCfg = &m.cfg.LintersSettings.BiDiChk
   149  		cyclopCfg = &m.cfg.LintersSettings.Cyclop
   150  		decorderCfg = &m.cfg.LintersSettings.Decorder
   151  		depGuardCfg = &m.cfg.LintersSettings.Depguard
   152  		dogsledCfg = &m.cfg.LintersSettings.Dogsled
   153  		duplCfg = &m.cfg.LintersSettings.Dupl
   154  		dupwordCfg = &m.cfg.LintersSettings.DupWord
   155  		errcheckCfg = &m.cfg.LintersSettings.Errcheck
   156  		errchkjsonCfg = &m.cfg.LintersSettings.ErrChkJSON
   157  		errorlintCfg = &m.cfg.LintersSettings.ErrorLint
   158  		exhaustiveCfg = &m.cfg.LintersSettings.Exhaustive
   159  		exhaustiveStructCfg = &m.cfg.LintersSettings.ExhaustiveStruct
   160  		exhaustructCfg = &m.cfg.LintersSettings.Exhaustruct
   161  		forbidigoCfg = &m.cfg.LintersSettings.Forbidigo
   162  		funlenCfg = &m.cfg.LintersSettings.Funlen
   163  		gciCfg = &m.cfg.LintersSettings.Gci
   164  		ginkgolinterCfg = &m.cfg.LintersSettings.GinkgoLinter
   165  		gocognitCfg = &m.cfg.LintersSettings.Gocognit
   166  		goconstCfg = &m.cfg.LintersSettings.Goconst
   167  		gocriticCfg = &m.cfg.LintersSettings.Gocritic
   168  		gocycloCfg = &m.cfg.LintersSettings.Gocyclo
   169  		godotCfg = &m.cfg.LintersSettings.Godot
   170  		godoxCfg = &m.cfg.LintersSettings.Godox
   171  		gofmtCfg = &m.cfg.LintersSettings.Gofmt
   172  		gofumptCfg = &m.cfg.LintersSettings.Gofumpt
   173  		goheaderCfg = &m.cfg.LintersSettings.Goheader
   174  		goimportsCfg = &m.cfg.LintersSettings.Goimports
   175  		golintCfg = &m.cfg.LintersSettings.Golint
   176  		goMndCfg = &m.cfg.LintersSettings.Gomnd
   177  		goModDirectivesCfg = &m.cfg.LintersSettings.GoModDirectives
   178  		gomodguardCfg = &m.cfg.LintersSettings.Gomodguard
   179  		gosecCfg = &m.cfg.LintersSettings.Gosec
   180  		gosimpleCfg = &m.cfg.LintersSettings.Gosimple
   181  		gosmopolitanCfg = &m.cfg.LintersSettings.Gosmopolitan
   182  		govetCfg = &m.cfg.LintersSettings.Govet
   183  		grouperCfg = &m.cfg.LintersSettings.Grouper
   184  		ifshortCfg = &m.cfg.LintersSettings.Ifshort
   185  		importAsCfg = &m.cfg.LintersSettings.ImportAs
   186  		interfaceBloatCfg = &m.cfg.LintersSettings.InterfaceBloat
   187  		ireturnCfg = &m.cfg.LintersSettings.Ireturn
   188  		lllCfg = &m.cfg.LintersSettings.Lll
   189  		loggerCheckCfg = &m.cfg.LintersSettings.LoggerCheck
   190  		maintIdxCfg = &m.cfg.LintersSettings.MaintIdx
   191  		makezeroCfg = &m.cfg.LintersSettings.Makezero
   192  		malignedCfg = &m.cfg.LintersSettings.Maligned
   193  		misspellCfg = &m.cfg.LintersSettings.Misspell
   194  		musttagCfg = &m.cfg.LintersSettings.MustTag
   195  		nakedretCfg = &m.cfg.LintersSettings.Nakedret
   196  		nestifCfg = &m.cfg.LintersSettings.Nestif
   197  		nilNilCfg = &m.cfg.LintersSettings.NilNil
   198  		nlreturnCfg = &m.cfg.LintersSettings.Nlreturn
   199  		noLintLintCfg = &m.cfg.LintersSettings.NoLintLint
   200  		noNamedReturnsCfg = &m.cfg.LintersSettings.NoNamedReturns
   201  		preallocCfg = &m.cfg.LintersSettings.Prealloc
   202  		parallelTestCfg = &m.cfg.LintersSettings.ParallelTest
   203  		predeclaredCfg = &m.cfg.LintersSettings.Predeclared
   204  		promlinterCfg = &m.cfg.LintersSettings.Promlinter
   205  		reassignCfg = &m.cfg.LintersSettings.Reassign
   206  		reviveCfg = &m.cfg.LintersSettings.Revive
   207  		rowserrcheckCfg = &m.cfg.LintersSettings.RowsErrCheck
   208  		staticcheckCfg = &m.cfg.LintersSettings.Staticcheck
   209  		structcheckCfg = &m.cfg.LintersSettings.Structcheck
   210  		stylecheckCfg = &m.cfg.LintersSettings.Stylecheck
   211  		tagalignCfg = &m.cfg.LintersSettings.TagAlign
   212  		tagliatelleCfg = &m.cfg.LintersSettings.Tagliatelle
   213  		tenvCfg = &m.cfg.LintersSettings.Tenv
   214  		testpackageCfg = &m.cfg.LintersSettings.Testpackage
   215  		thelperCfg = &m.cfg.LintersSettings.Thelper
   216  		unparamCfg = &m.cfg.LintersSettings.Unparam
   217  		unusedCfg = new(config.StaticCheckSettings)
   218  		usestdlibvars = &m.cfg.LintersSettings.UseStdlibVars
   219  		varcheckCfg = &m.cfg.LintersSettings.Varcheck
   220  		varnamelenCfg = &m.cfg.LintersSettings.Varnamelen
   221  		whitespaceCfg = &m.cfg.LintersSettings.Whitespace
   222  		wrapcheckCfg = &m.cfg.LintersSettings.Wrapcheck
   223  		wslCfg = &m.cfg.LintersSettings.WSL
   224  
   225  		if govetCfg != nil {
   226  			govetCfg.Go = m.cfg.Run.Go
   227  		}
   228  
   229  		if gocriticCfg != nil {
   230  			gocriticCfg.Go = m.cfg.Run.Go
   231  		}
   232  
   233  		if gofumptCfg != nil && gofumptCfg.LangVersion == "" {
   234  			gofumptCfg.LangVersion = m.cfg.Run.Go
   235  		}
   236  
   237  		if staticcheckCfg != nil && staticcheckCfg.GoVersion == "" {
   238  			staticcheckCfg.GoVersion = m.cfg.Run.Go
   239  		}
   240  		if gosimpleCfg != nil && gosimpleCfg.GoVersion == "" {
   241  			gosimpleCfg.GoVersion = m.cfg.Run.Go
   242  		}
   243  		if stylecheckCfg != nil && stylecheckCfg.GoVersion != "" {
   244  			stylecheckCfg.GoVersion = m.cfg.Run.Go
   245  		}
   246  		if unusedCfg != nil && unusedCfg.GoVersion == "" {
   247  			unusedCfg.GoVersion = m.cfg.Run.Go
   248  		}
   249  	}
   250  
   251  	const megacheckName = "megacheck"
   252  
   253  	var linters []*linter.Config
   254  	linters = append(linters, m.customLinters...)
   255  
   256  	// The linters are sorted in the alphabetical order (case-insensitive).
   257  	// When a new linter is added the version in `WithSince(...)` must be the next minor version of golangci-lint.
   258  	linters = append(linters,
   259  		linter.NewConfig(golinters.NewAsasalint(asasalintCfg)).
   260  			WithSince("1.47.0").
   261  			WithPresets(linter.PresetBugs).
   262  			WithLoadForGoAnalysis().
   263  			WithURL("https://github.com/alingse/asasalint"),
   264  
   265  		linter.NewConfig(golinters.NewAsciicheck()).
   266  			WithSince("v1.26.0").
   267  			WithPresets(linter.PresetBugs, linter.PresetStyle).
   268  			WithURL("https://github.com/tdakkota/asciicheck"),
   269  
   270  		linter.NewConfig(golinters.NewBiDiChkFuncName(bidichkCfg)).
   271  			WithSince("1.43.0").
   272  			WithPresets(linter.PresetBugs).
   273  			WithURL("https://github.com/breml/bidichk"),
   274  
   275  		linter.NewConfig(golinters.NewBodyclose()).
   276  			WithSince("v1.18.0").
   277  			WithLoadForGoAnalysis().
   278  			WithPresets(linter.PresetPerformance, linter.PresetBugs).
   279  			WithURL("https://github.com/timakin/bodyclose"),
   280  
   281  		linter.NewConfig(golinters.NewContainedCtx()).
   282  			WithSince("1.44.0").
   283  			WithLoadForGoAnalysis().
   284  			WithPresets(linter.PresetStyle).
   285  			WithURL("https://github.com/sivchari/containedctx"),
   286  
   287  		linter.NewConfig(golinters.NewContextCheck()).
   288  			WithSince("v1.43.0").
   289  			WithPresets(linter.PresetBugs).
   290  			WithLoadForGoAnalysis().
   291  			WithURL("https://github.com/kkHAIKE/contextcheck"),
   292  
   293  		linter.NewConfig(golinters.NewCyclop(cyclopCfg)).
   294  			WithSince("v1.37.0").
   295  			WithLoadForGoAnalysis().
   296  			WithPresets(linter.PresetComplexity).
   297  			WithURL("https://github.com/bkielbasa/cyclop"),
   298  
   299  		linter.NewConfig(golinters.NewDecorder(decorderCfg)).
   300  			WithSince("v1.44.0").
   301  			WithPresets(linter.PresetFormatting, linter.PresetStyle).
   302  			WithURL("https://gitlab.com/bosi/decorder"),
   303  
   304  		linter.NewConfig(golinters.NewDeadcode()).
   305  			WithSince("v1.0.0").
   306  			WithLoadForGoAnalysis().
   307  			WithPresets(linter.PresetUnused).
   308  			WithURL("https://github.com/remyoudompheng/go-misc/tree/master/deadcode").
   309  			Deprecated("The owner seems to have abandoned the linter.", "v1.49.0", "unused"),
   310  
   311  		linter.NewConfig(golinters.NewDepguard(depGuardCfg)).
   312  			WithSince("v1.4.0").
   313  			WithPresets(linter.PresetStyle, linter.PresetImport, linter.PresetModule).
   314  			WithURL("https://github.com/OpenPeeDeeP/depguard"),
   315  
   316  		linter.NewConfig(golinters.NewDogsled(dogsledCfg)).
   317  			WithSince("v1.19.0").
   318  			WithPresets(linter.PresetStyle).
   319  			WithURL("https://github.com/alexkohler/dogsled"),
   320  
   321  		linter.NewConfig(golinters.NewDupl(duplCfg)).
   322  			WithSince("v1.0.0").
   323  			WithPresets(linter.PresetStyle).
   324  			WithURL("https://github.com/mibk/dupl"),
   325  
   326  		linter.NewConfig(golinters.NewDupWord(dupwordCfg)).
   327  			WithSince("1.50.0").
   328  			WithPresets(linter.PresetComment).
   329  			WithAutoFix().
   330  			WithURL("https://github.com/Abirdcfly/dupword"),
   331  
   332  		linter.NewConfig(golinters.NewDurationCheck()).
   333  			WithSince("v1.37.0").
   334  			WithPresets(linter.PresetBugs).
   335  			WithLoadForGoAnalysis().
   336  			WithURL("https://github.com/charithe/durationcheck"),
   337  
   338  		linter.NewConfig(golinters.NewErrcheck(errcheckCfg)).
   339  			WithEnabledByDefault().
   340  			WithSince("v1.0.0").
   341  			WithLoadForGoAnalysis().
   342  			WithPresets(linter.PresetBugs, linter.PresetError).
   343  			WithURL("https://github.com/kisielk/errcheck"),
   344  
   345  		linter.NewConfig(golinters.NewErrChkJSONFuncName(errchkjsonCfg)).
   346  			WithSince("1.44.0").
   347  			WithPresets(linter.PresetBugs).
   348  			WithLoadForGoAnalysis().
   349  			WithURL("https://github.com/breml/errchkjson"),
   350  
   351  		linter.NewConfig(golinters.NewErrName()).
   352  			WithSince("v1.42.0").
   353  			WithPresets(linter.PresetStyle).
   354  			WithLoadForGoAnalysis().
   355  			WithURL("https://github.com/Antonboom/errname"),
   356  
   357  		linter.NewConfig(golinters.NewErrorLint(errorlintCfg)).
   358  			WithSince("v1.32.0").
   359  			WithPresets(linter.PresetBugs, linter.PresetError).
   360  			WithLoadForGoAnalysis().
   361  			WithURL("https://github.com/polyfloyd/go-errorlint"),
   362  
   363  		linter.NewConfig(golinters.NewExecInQuery()).
   364  			WithSince("v1.46.0").
   365  			WithPresets(linter.PresetSQL).
   366  			WithLoadForGoAnalysis().
   367  			WithURL("https://github.com/lufeee/execinquery"),
   368  
   369  		linter.NewConfig(golinters.NewExhaustive(exhaustiveCfg)).
   370  			WithSince(" v1.28.0").
   371  			WithPresets(linter.PresetBugs).
   372  			WithLoadForGoAnalysis().
   373  			WithURL("https://github.com/nishanths/exhaustive"),
   374  
   375  		linter.NewConfig(golinters.NewExhaustiveStruct(exhaustiveStructCfg)).
   376  			WithSince("v1.32.0").
   377  			WithPresets(linter.PresetStyle, linter.PresetTest).
   378  			WithLoadForGoAnalysis().
   379  			WithURL("https://github.com/mbilski/exhaustivestruct").
   380  			Deprecated("The owner seems to have abandoned the linter.", "v1.46.0", "exhaustruct"),
   381  
   382  		linter.NewConfig(golinters.NewExhaustruct(exhaustructCfg)).
   383  			WithSince("v1.46.0").
   384  			WithPresets(linter.PresetStyle, linter.PresetTest).
   385  			WithLoadForGoAnalysis().
   386  			WithURL("https://github.com/GaijinEntertainment/go-exhaustruct"),
   387  
   388  		linter.NewConfig(golinters.NewExportLoopRef()).
   389  			WithSince("v1.28.0").
   390  			WithPresets(linter.PresetBugs).
   391  			WithLoadForGoAnalysis().
   392  			WithURL("https://github.com/kyoh86/exportloopref"),
   393  
   394  		linter.NewConfig(golinters.NewForbidigo(forbidigoCfg)).
   395  			WithSince("v1.34.0").
   396  			WithPresets(linter.PresetStyle).
   397  			// Strictly speaking,
   398  			// the additional information is only needed when forbidigoCfg.AnalyzeTypes is chosen by the user.
   399  			// But we don't know that here in all cases (sometimes config is not loaded),
   400  			// so we have to assume that it is needed to be on the safe side.
   401  			WithLoadForGoAnalysis().
   402  			WithURL("https://github.com/ashanbrown/forbidigo"),
   403  
   404  		linter.NewConfig(golinters.NewForceTypeAssert()).
   405  			WithSince("v1.38.0").
   406  			WithPresets(linter.PresetStyle).
   407  			WithURL("https://github.com/gostaticanalysis/forcetypeassert"),
   408  
   409  		linter.NewConfig(golinters.NewFunlen(funlenCfg)).
   410  			WithSince("v1.18.0").
   411  			WithPresets(linter.PresetComplexity).
   412  			WithURL("https://github.com/ultraware/funlen"),
   413  
   414  		linter.NewConfig(golinters.NewGci(gciCfg)).
   415  			WithSince("v1.30.0").
   416  			WithPresets(linter.PresetFormatting, linter.PresetImport).
   417  			WithURL("https://github.com/daixiang0/gci"),
   418  
   419  		linter.NewConfig(golinters.NewGinkgoLinter(ginkgolinterCfg)).
   420  			WithSince("v1.51.0").
   421  			WithLoadForGoAnalysis().
   422  			WithPresets(linter.PresetStyle).
   423  			WithURL("https://github.com/nunnatsa/ginkgolinter"),
   424  
   425  		linter.NewConfig(golinters.NewGoCheckCompilerDirectives()).
   426  			WithSince("v1.51.0").
   427  			WithPresets(linter.PresetBugs).
   428  			WithURL("https://github.com/leighmcculloch/gocheckcompilerdirectives"),
   429  
   430  		linter.NewConfig(golinters.NewGochecknoglobals()).
   431  			WithSince("v1.12.0").
   432  			WithPresets(linter.PresetStyle).
   433  			WithLoadForGoAnalysis().
   434  			WithURL("https://github.com/leighmcculloch/gochecknoglobals"),
   435  
   436  		linter.NewConfig(golinters.NewGochecknoinits()).
   437  			WithSince("v1.12.0").
   438  			WithPresets(linter.PresetStyle),
   439  
   440  		linter.NewConfig(golinters.NewGocognit(gocognitCfg)).
   441  			WithSince("v1.20.0").
   442  			WithPresets(linter.PresetComplexity).
   443  			WithURL("https://github.com/uudashr/gocognit"),
   444  
   445  		linter.NewConfig(golinters.NewGoconst(goconstCfg)).
   446  			WithSince("v1.0.0").
   447  			WithPresets(linter.PresetStyle).
   448  			WithURL("https://github.com/jgautheron/goconst"),
   449  
   450  		linter.NewConfig(golinters.NewGoCritic(gocriticCfg, m.cfg)).
   451  			WithSince("v1.12.0").
   452  			WithPresets(linter.PresetStyle, linter.PresetMetaLinter).
   453  			WithLoadForGoAnalysis().
   454  			WithURL("https://github.com/go-critic/go-critic"),
   455  
   456  		linter.NewConfig(golinters.NewGocyclo(gocycloCfg)).
   457  			WithSince("v1.0.0").
   458  			WithPresets(linter.PresetComplexity).
   459  			WithURL("https://github.com/fzipp/gocyclo"),
   460  
   461  		linter.NewConfig(golinters.NewGodot(godotCfg)).
   462  			WithSince("v1.25.0").
   463  			WithPresets(linter.PresetStyle, linter.PresetComment).
   464  			WithAutoFix().
   465  			WithURL("https://github.com/tetafro/godot"),
   466  
   467  		linter.NewConfig(golinters.NewGodox(godoxCfg)).
   468  			WithSince("v1.19.0").
   469  			WithPresets(linter.PresetStyle, linter.PresetComment).
   470  			WithURL("https://github.com/matoous/godox"),
   471  
   472  		linter.NewConfig(golinters.NewGoerr113()).
   473  			WithSince("v1.26.0").
   474  			WithPresets(linter.PresetStyle, linter.PresetError).
   475  			WithLoadForGoAnalysis().
   476  			WithURL("https://github.com/Djarvur/go-err113"),
   477  
   478  		linter.NewConfig(golinters.NewGofmt(gofmtCfg)).
   479  			WithSince("v1.0.0").
   480  			WithPresets(linter.PresetFormatting).
   481  			WithAutoFix().
   482  			WithURL("https://pkg.go.dev/cmd/gofmt"),
   483  
   484  		linter.NewConfig(golinters.NewGofumpt(gofumptCfg)).
   485  			WithSince("v1.28.0").
   486  			WithPresets(linter.PresetFormatting).
   487  			WithAutoFix().
   488  			WithURL("https://github.com/mvdan/gofumpt"),
   489  
   490  		linter.NewConfig(golinters.NewGoHeader(goheaderCfg)).
   491  			WithSince("v1.28.0").
   492  			WithPresets(linter.PresetStyle).
   493  			WithURL("https://github.com/denis-tingaikin/go-header"),
   494  
   495  		linter.NewConfig(golinters.NewGoimports(goimportsCfg)).
   496  			WithSince("v1.20.0").
   497  			WithPresets(linter.PresetFormatting, linter.PresetImport).
   498  			WithAutoFix().
   499  			WithURL("https://pkg.go.dev/golang.org/x/tools/cmd/goimports"),
   500  
   501  		linter.NewConfig(golinters.NewGolint(golintCfg)).
   502  			WithSince("v1.0.0").
   503  			WithLoadForGoAnalysis().
   504  			WithPresets(linter.PresetStyle).
   505  			WithURL("https://github.com/golang/lint").
   506  			Deprecated("The repository of the linter has been archived by the owner.", "v1.41.0", "revive"),
   507  
   508  		linter.NewConfig(golinters.NewGoMND(goMndCfg)).
   509  			WithSince("v1.22.0").
   510  			WithPresets(linter.PresetStyle).
   511  			WithURL("https://github.com/tommy-muehle/go-mnd"),
   512  
   513  		linter.NewConfig(golinters.NewGoModDirectives(goModDirectivesCfg)).
   514  			WithSince("v1.39.0").
   515  			WithPresets(linter.PresetStyle, linter.PresetModule).
   516  			WithURL("https://github.com/ldez/gomoddirectives"),
   517  
   518  		linter.NewConfig(golinters.NewGomodguard(gomodguardCfg)).
   519  			WithSince("v1.25.0").
   520  			WithPresets(linter.PresetStyle, linter.PresetImport, linter.PresetModule).
   521  			WithURL("https://github.com/ryancurrah/gomodguard"),
   522  
   523  		linter.NewConfig(golinters.NewGoPrintfFuncName()).
   524  			WithSince("v1.23.0").
   525  			WithPresets(linter.PresetStyle).
   526  			WithURL("https://github.com/jirfag/go-printf-func-name"),
   527  
   528  		linter.NewConfig(golinters.NewGosec(gosecCfg)).
   529  			WithSince("v1.0.0").
   530  			WithLoadForGoAnalysis().
   531  			WithPresets(linter.PresetBugs).
   532  			WithURL("https://github.com/securego/gosec").
   533  			WithAlternativeNames("gas"),
   534  
   535  		linter.NewConfig(golinters.NewGosimple(gosimpleCfg)).
   536  			WithEnabledByDefault().
   537  			WithSince("v1.20.0").
   538  			WithLoadForGoAnalysis().
   539  			WithPresets(linter.PresetStyle).
   540  			WithAlternativeNames(megacheckName).
   541  			WithURL("https://github.com/dominikh/go-tools/tree/master/simple"),
   542  
   543  		linter.NewConfig(golinters.NewGosmopolitan(gosmopolitanCfg)).
   544  			WithSince("v1.53.0").
   545  			WithLoadForGoAnalysis().
   546  			WithPresets(linter.PresetBugs).
   547  			WithURL("https://github.com/xen0n/gosmopolitan"),
   548  
   549  		linter.NewConfig(golinters.NewGovet(govetCfg)).
   550  			WithEnabledByDefault().
   551  			WithSince("v1.0.0").
   552  			WithLoadForGoAnalysis().
   553  			WithPresets(linter.PresetBugs, linter.PresetMetaLinter).
   554  			WithAlternativeNames("vet", "vetshadow").
   555  			WithURL("https://pkg.go.dev/cmd/vet"),
   556  
   557  		linter.NewConfig(golinters.NewGrouper(grouperCfg)).
   558  			WithSince("v1.44.0").
   559  			WithPresets(linter.PresetStyle).
   560  			WithURL("https://github.com/leonklingele/grouper"),
   561  
   562  		linter.NewConfig(golinters.NewIfshort(ifshortCfg)).
   563  			WithSince("v1.36.0").
   564  			WithPresets(linter.PresetStyle).
   565  			WithURL("https://github.com/esimonov/ifshort").
   566  			Deprecated("The repository of the linter has been deprecated by the owner.", "v1.48.0", ""),
   567  
   568  		linter.NewConfig(golinters.NewImportAs(importAsCfg)).
   569  			WithSince("v1.38.0").
   570  			WithPresets(linter.PresetStyle).
   571  			WithLoadForGoAnalysis().
   572  			WithURL("https://github.com/julz/importas"),
   573  
   574  		linter.NewConfig(golinters.NewIneffassign()).
   575  			WithEnabledByDefault().
   576  			WithSince("v1.0.0").
   577  			WithPresets(linter.PresetUnused).
   578  			WithURL("https://github.com/gordonklaus/ineffassign"),
   579  
   580  		linter.NewConfig(golinters.NewInterfaceBloat(interfaceBloatCfg)).
   581  			WithSince("v1.49.0").
   582  			WithPresets(linter.PresetStyle).
   583  			WithURL("https://github.com/sashamelentyev/interfacebloat"),
   584  
   585  		linter.NewConfig(golinters.NewInterfacer()).
   586  			WithSince("v1.0.0").
   587  			WithLoadForGoAnalysis().
   588  			WithPresets(linter.PresetStyle).
   589  			WithURL("https://github.com/mvdan/interfacer").
   590  			Deprecated("The repository of the linter has been archived by the owner.", "v1.38.0", ""),
   591  
   592  		linter.NewConfig(golinters.NewIreturn(ireturnCfg)).
   593  			WithSince("v1.43.0").
   594  			WithPresets(linter.PresetStyle).
   595  			WithLoadForGoAnalysis().
   596  			WithURL("https://github.com/butuzov/ireturn"),
   597  
   598  		linter.NewConfig(golinters.NewLLL(lllCfg)).
   599  			WithSince("v1.8.0").
   600  			WithPresets(linter.PresetStyle),
   601  
   602  		linter.NewConfig(golinters.NewLoggerCheck(loggerCheckCfg)).
   603  			WithSince("v1.49.0").
   604  			WithLoadForGoAnalysis().
   605  			WithPresets(linter.PresetStyle, linter.PresetBugs).
   606  			WithAlternativeNames("logrlint").
   607  			WithURL("https://github.com/timonwong/loggercheck"),
   608  
   609  		linter.NewConfig(golinters.NewMaintIdx(maintIdxCfg)).
   610  			WithSince("v1.44.0").
   611  			WithPresets(linter.PresetComplexity).
   612  			WithURL("https://github.com/yagipy/maintidx"),
   613  
   614  		linter.NewConfig(golinters.NewMakezero(makezeroCfg)).
   615  			WithSince("v1.34.0").
   616  			WithPresets(linter.PresetStyle, linter.PresetBugs).
   617  			WithLoadForGoAnalysis().
   618  			WithURL("https://github.com/ashanbrown/makezero"),
   619  
   620  		linter.NewConfig(golinters.NewMaligned(malignedCfg)).
   621  			WithSince("v1.0.0").
   622  			WithLoadForGoAnalysis().
   623  			WithPresets(linter.PresetPerformance).
   624  			WithURL("https://github.com/mdempsky/maligned").
   625  			Deprecated("The repository of the linter has been archived by the owner.", "v1.38.0", "govet 'fieldalignment'"),
   626  
   627  		linter.NewConfig(golinters.NewMirror()).
   628  			WithSince("v1.53.0").
   629  			WithPresets(linter.PresetStyle).
   630  			WithLoadForGoAnalysis().
   631  			WithURL("https://github.com/butuzov/mirror"),
   632  
   633  		linter.NewConfig(golinters.NewMisspell(misspellCfg)).
   634  			WithSince("v1.8.0").
   635  			WithPresets(linter.PresetStyle, linter.PresetComment).
   636  			WithAutoFix().
   637  			WithURL("https://github.com/client9/misspell"),
   638  
   639  		linter.NewConfig(golinters.NewMustTag(musttagCfg)).
   640  			WithSince("v1.51.0").
   641  			WithLoadForGoAnalysis().
   642  			WithPresets(linter.PresetStyle, linter.PresetBugs).
   643  			WithURL("https://github.com/tmzane/musttag"),
   644  
   645  		linter.NewConfig(golinters.NewNakedret(nakedretCfg)).
   646  			WithSince("v1.19.0").
   647  			WithPresets(linter.PresetStyle).
   648  			WithURL("https://github.com/alexkohler/nakedret"),
   649  
   650  		linter.NewConfig(golinters.NewNestif(nestifCfg)).
   651  			WithSince("v1.25.0").
   652  			WithPresets(linter.PresetComplexity).
   653  			WithURL("https://github.com/nakabonne/nestif"),
   654  
   655  		linter.NewConfig(golinters.NewNilErr()).
   656  			WithSince("v1.38.0").
   657  			WithLoadForGoAnalysis().
   658  			WithPresets(linter.PresetBugs).
   659  			WithURL("https://github.com/gostaticanalysis/nilerr"),
   660  
   661  		linter.NewConfig(golinters.NewNilNil(nilNilCfg)).
   662  			WithSince("v1.43.0").
   663  			WithPresets(linter.PresetStyle).
   664  			WithLoadForGoAnalysis().
   665  			WithURL("https://github.com/Antonboom/nilnil"),
   666  
   667  		linter.NewConfig(golinters.NewNLReturn(nlreturnCfg)).
   668  			WithSince("v1.30.0").
   669  			WithPresets(linter.PresetStyle).
   670  			WithURL("https://github.com/ssgreg/nlreturn"),
   671  
   672  		linter.NewConfig(golinters.NewNoctx()).
   673  			WithSince("v1.28.0").
   674  			WithLoadForGoAnalysis().
   675  			WithPresets(linter.PresetPerformance, linter.PresetBugs).
   676  			WithURL("https://github.com/sonatard/noctx"),
   677  
   678  		linter.NewConfig(golinters.NewNoNamedReturns(noNamedReturnsCfg)).
   679  			WithSince("v1.46.0").
   680  			WithLoadForGoAnalysis().
   681  			WithPresets(linter.PresetStyle).
   682  			WithURL("https://github.com/firefart/nonamedreturns"),
   683  
   684  		linter.NewConfig(golinters.NewNoSnakeCase()).
   685  			WithSince("v1.47.0").
   686  			WithPresets(linter.PresetStyle).
   687  			WithURL("https://github.com/sivchari/nosnakecase").
   688  			Deprecated("The repository of the linter has been deprecated by the owner.", "v1.48.1", "revive(var-naming)"),
   689  
   690  		linter.NewConfig(golinters.NewNoSprintfHostPort()).
   691  			WithSince("v1.46.0").
   692  			WithPresets(linter.PresetStyle).
   693  			WithURL("https://github.com/stbenjam/no-sprintf-host-port"),
   694  
   695  		linter.NewConfig(golinters.NewParallelTest(parallelTestCfg)).
   696  			WithSince("v1.33.0").
   697  			WithLoadForGoAnalysis().
   698  			WithPresets(linter.PresetStyle, linter.PresetTest).
   699  			WithURL("https://github.com/kunwardeep/paralleltest"),
   700  
   701  		linter.NewConfig(golinters.NewPreAlloc(preallocCfg)).
   702  			WithSince("v1.19.0").
   703  			WithPresets(linter.PresetPerformance).
   704  			WithURL("https://github.com/alexkohler/prealloc"),
   705  
   706  		linter.NewConfig(golinters.NewPredeclared(predeclaredCfg)).
   707  			WithSince("v1.35.0").
   708  			WithPresets(linter.PresetStyle).
   709  			WithURL("https://github.com/nishanths/predeclared"),
   710  
   711  		linter.NewConfig(golinters.NewPromlinter(promlinterCfg)).
   712  			WithSince("v1.40.0").
   713  			WithPresets(linter.PresetStyle).
   714  			WithURL("https://github.com/yeya24/promlinter"),
   715  
   716  		linter.NewConfig(golinters.NewReassign(reassignCfg)).
   717  			WithSince("1.49.0").
   718  			WithPresets(linter.PresetBugs).
   719  			WithLoadForGoAnalysis().
   720  			WithURL("https://github.com/curioswitch/go-reassign"),
   721  
   722  		linter.NewConfig(golinters.NewRevive(reviveCfg)).
   723  			WithSince("v1.37.0").
   724  			WithPresets(linter.PresetStyle, linter.PresetMetaLinter).
   725  			ConsiderSlow().
   726  			WithURL("https://github.com/mgechev/revive"),
   727  
   728  		linter.NewConfig(golinters.NewRowsErrCheck(rowserrcheckCfg)).
   729  			WithSince("v1.23.0").
   730  			WithLoadForGoAnalysis().
   731  			WithPresets(linter.PresetBugs, linter.PresetSQL).
   732  			WithURL("https://github.com/jingyugao/rowserrcheck"),
   733  
   734  		linter.NewConfig(golinters.NewScopelint()).
   735  			WithSince("v1.12.0").
   736  			WithPresets(linter.PresetBugs).
   737  			WithURL("https://github.com/kyoh86/scopelint").
   738  			Deprecated("The repository of the linter has been deprecated by the owner.", "v1.39.0", "exportloopref"),
   739  
   740  		linter.NewConfig(golinters.NewSQLCloseCheck()).
   741  			WithSince("v1.28.0").
   742  			WithPresets(linter.PresetBugs, linter.PresetSQL).
   743  			WithLoadForGoAnalysis().
   744  			WithURL("https://github.com/ryanrolds/sqlclosecheck"),
   745  
   746  		linter.NewConfig(golinters.NewStaticcheck(staticcheckCfg)).
   747  			WithEnabledByDefault().
   748  			WithSince("v1.0.0").
   749  			WithLoadForGoAnalysis().
   750  			WithPresets(linter.PresetBugs, linter.PresetMetaLinter).
   751  			WithAlternativeNames(megacheckName).
   752  			WithURL("https://staticcheck.io/"),
   753  
   754  		linter.NewConfig(golinters.NewStructcheck(structcheckCfg)).
   755  			WithSince("v1.0.0").
   756  			WithLoadForGoAnalysis().
   757  			WithPresets(linter.PresetUnused).
   758  			WithURL("https://github.com/opennota/check").
   759  			Deprecated("The owner seems to have abandoned the linter.", "v1.49.0", "unused"),
   760  
   761  		linter.NewConfig(golinters.NewStylecheck(stylecheckCfg)).
   762  			WithSince("v1.20.0").
   763  			WithLoadForGoAnalysis().
   764  			WithPresets(linter.PresetStyle).
   765  			WithURL("https://github.com/dominikh/go-tools/tree/master/stylecheck"),
   766  
   767  		linter.NewConfig(golinters.NewTagAlign(tagalignCfg)).
   768  			WithSince("v1.53.0").
   769  			WithPresets(linter.PresetStyle, linter.PresetFormatting).
   770  			WithAutoFix().
   771  			WithURL("https://github.com/4meepo/tagalign"),
   772  
   773  		linter.NewConfig(golinters.NewTagliatelle(tagliatelleCfg)).
   774  			WithSince("v1.40.0").
   775  			WithPresets(linter.PresetStyle).
   776  			WithURL("https://github.com/ldez/tagliatelle"),
   777  
   778  		linter.NewConfig(golinters.NewTenv(tenvCfg)).
   779  			WithSince("v1.43.0").
   780  			WithPresets(linter.PresetStyle).
   781  			WithLoadForGoAnalysis().
   782  			WithURL("https://github.com/sivchari/tenv"),
   783  
   784  		linter.NewConfig(golinters.NewTestableexamples()).
   785  			WithSince("v1.50.0").
   786  			WithPresets(linter.PresetTest).
   787  			WithURL("https://github.com/maratori/testableexamples"),
   788  
   789  		linter.NewConfig(golinters.NewTestpackage(testpackageCfg)).
   790  			WithSince("v1.25.0").
   791  			WithPresets(linter.PresetStyle, linter.PresetTest).
   792  			WithURL("https://github.com/maratori/testpackage"),
   793  
   794  		linter.NewConfig(golinters.NewThelper(thelperCfg)).
   795  			WithSince("v1.34.0").
   796  			WithPresets(linter.PresetStyle).
   797  			WithLoadForGoAnalysis().
   798  			WithURL("https://github.com/kulti/thelper"),
   799  
   800  		linter.NewConfig(golinters.NewTparallel()).
   801  			WithSince("v1.32.0").
   802  			WithPresets(linter.PresetStyle, linter.PresetTest).
   803  			WithLoadForGoAnalysis().
   804  			WithURL("https://github.com/moricho/tparallel"),
   805  
   806  		linter.NewConfig(golinters.NewTypecheck()).
   807  			WithInternal().
   808  			WithEnabledByDefault().
   809  			WithSince("v1.3.0").
   810  			WithLoadForGoAnalysis().
   811  			WithPresets(linter.PresetBugs).
   812  			WithURL(""),
   813  
   814  		linter.NewConfig(golinters.NewUnconvert()).
   815  			WithSince("v1.0.0").
   816  			WithLoadForGoAnalysis().
   817  			WithPresets(linter.PresetStyle).
   818  			WithURL("https://github.com/mdempsky/unconvert"),
   819  
   820  		linter.NewConfig(golinters.NewUnparam(unparamCfg)).
   821  			WithSince("v1.9.0").
   822  			WithPresets(linter.PresetUnused).
   823  			WithLoadForGoAnalysis().
   824  			WithURL("https://github.com/mvdan/unparam"),
   825  
   826  		linter.NewConfig(golinters.NewUnused(unusedCfg)).
   827  			WithEnabledByDefault().
   828  			WithSince("v1.20.0").
   829  			WithLoadForGoAnalysis().
   830  			WithPresets(linter.PresetUnused).
   831  			WithAlternativeNames(megacheckName).
   832  			ConsiderSlow().
   833  			WithChangeTypes().
   834  			WithURL("https://github.com/dominikh/go-tools/tree/master/unused"),
   835  
   836  		linter.NewConfig(golinters.NewUseStdlibVars(usestdlibvars)).
   837  			WithSince("v1.48.0").
   838  			WithPresets(linter.PresetStyle).
   839  			WithURL("https://github.com/sashamelentyev/usestdlibvars"),
   840  
   841  		linter.NewConfig(golinters.NewVarcheck(varcheckCfg)).
   842  			WithSince("v1.0.0").
   843  			WithLoadForGoAnalysis().
   844  			WithPresets(linter.PresetUnused).
   845  			WithURL("https://github.com/opennota/check").
   846  			Deprecated("The owner seems to have abandoned the linter.", "v1.49.0", "unused"),
   847  
   848  		linter.NewConfig(golinters.NewVarnamelen(varnamelenCfg)).
   849  			WithSince("v1.43.0").
   850  			WithPresets(linter.PresetStyle).
   851  			WithLoadForGoAnalysis().
   852  			WithURL("https://github.com/blizzy78/varnamelen"),
   853  
   854  		linter.NewConfig(golinters.NewWastedAssign()).
   855  			WithSince("v1.38.0").
   856  			WithPresets(linter.PresetStyle).
   857  			WithLoadForGoAnalysis().
   858  			WithURL("https://github.com/sanposhiho/wastedassign"),
   859  
   860  		linter.NewConfig(golinters.NewWhitespace(whitespaceCfg)).
   861  			WithSince("v1.19.0").
   862  			WithPresets(linter.PresetStyle).
   863  			WithAutoFix().
   864  			WithURL("https://github.com/ultraware/whitespace"),
   865  
   866  		linter.NewConfig(golinters.NewWrapcheck(wrapcheckCfg)).
   867  			WithSince("v1.32.0").
   868  			WithPresets(linter.PresetStyle, linter.PresetError).
   869  			WithLoadForGoAnalysis().
   870  			WithURL("https://github.com/tomarrell/wrapcheck"),
   871  
   872  		linter.NewConfig(golinters.NewWSL(wslCfg)).
   873  			WithSince("v1.20.0").
   874  			WithPresets(linter.PresetStyle).
   875  			WithURL("https://github.com/bombsimon/wsl"),
   876  
   877  		linter.NewConfig(golinters.NewZerologLint()).
   878  			WithSince("v1.53.0").
   879  			WithPresets(linter.PresetBugs).
   880  			WithLoadForGoAnalysis().
   881  			WithURL("https://github.com/ykadowak/zerologlint"),
   882  
   883  		linter.NewConfig(golinters.NewNilPointerReferenceCheck()).
   884  			WithSince("v1.53.1").
   885  			WithLoadForGoAnalysis().
   886  			WithPresets(linter.PresetBugs).
   887  			WithURL("https://github.com/chenfeining/go-npecheck"),
   888  
   889  		// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
   890  		linter.NewConfig(golinters.NewNoLintLint(noLintLintCfg)).
   891  			WithSince("v1.26.0").
   892  			WithPresets(linter.PresetStyle).
   893  			WithURL("https://github.com/chenfeining/golangci-lint/blob/master/pkg/golinters/nolintlint/README.md"),
   894  	)
   895  
   896  	return linters
   897  }
   898  
   899  func (m Manager) GetAllEnabledByDefaultLinters() []*linter.Config {
   900  	var ret []*linter.Config
   901  	for _, lc := range m.GetAllSupportedLinterConfigs() {
   902  		if lc.EnabledByDefault {
   903  			ret = append(ret, lc)
   904  		}
   905  	}
   906  
   907  	return ret
   908  }
   909  
   910  func linterConfigsToMap(lcs []*linter.Config) map[string]*linter.Config {
   911  	ret := map[string]*linter.Config{}
   912  	for _, lc := range lcs {
   913  		lc := lc // local copy
   914  		ret[lc.Name()] = lc
   915  	}
   916  
   917  	return ret
   918  }
   919  
   920  func (m Manager) GetAllLinterConfigsForPreset(p string) []*linter.Config {
   921  	var ret []*linter.Config
   922  	for _, lc := range m.GetAllSupportedLinterConfigs() {
   923  		if lc.IsDeprecated() {
   924  			continue
   925  		}
   926  
   927  		for _, ip := range lc.InPresets {
   928  			if p == ip {
   929  				ret = append(ret, lc)
   930  				break
   931  			}
   932  		}
   933  	}
   934  
   935  	return ret
   936  }