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