github.com/elek/golangci-lint@v1.42.2-0.20211208090441-c05b7fcb3a9a/pkg/config/linters_settings.go (about) 1 package config 2 3 import "github.com/pkg/errors" 4 5 var defaultLintersSettings = LintersSettings{ 6 Lll: LllSettings{ 7 LineLength: 120, 8 TabWidth: 1, 9 }, 10 Unparam: UnparamSettings{ 11 Algo: "cha", 12 }, 13 Nakedret: NakedretSettings{ 14 MaxFuncLines: 30, 15 }, 16 Prealloc: PreallocSettings{ 17 Simple: true, 18 RangeLoops: true, 19 ForLoops: false, 20 }, 21 Gocritic: GocriticSettings{ 22 SettingsPerCheck: map[string]GocriticCheckSettings{}, 23 }, 24 Godox: GodoxSettings{ 25 Keywords: []string{}, 26 }, 27 Dogsled: DogsledSettings{ 28 MaxBlankIdentifiers: 2, 29 }, 30 Gocognit: GocognitSettings{ 31 MinComplexity: 30, 32 }, 33 WSL: WSLSettings{ 34 StrictAppend: true, 35 AllowAssignAndCallCuddle: true, 36 AllowAssignAndAnythingCuddle: false, 37 AllowMultiLineAssignCuddle: true, 38 AllowCuddleDeclaration: false, 39 AllowTrailingComment: false, 40 AllowSeparatedLeadingComment: false, 41 ForceCuddleErrCheckAndAssign: false, 42 ForceExclusiveShortDeclarations: false, 43 ForceCaseTrailingWhitespaceLimit: 0, 44 }, 45 NoLintLint: NoLintLintSettings{ 46 RequireExplanation: false, 47 AllowLeadingSpace: true, 48 RequireSpecific: false, 49 AllowUnused: false, 50 }, 51 Testpackage: TestpackageSettings{ 52 SkipRegexp: `(export|internal)_test\.go`, 53 }, 54 Nestif: NestifSettings{ 55 MinComplexity: 5, 56 }, 57 Exhaustive: ExhaustiveSettings{ 58 CheckGenerated: false, 59 DefaultSignifiesExhaustive: false, 60 }, 61 Gofumpt: GofumptSettings{ 62 LangVersion: "", 63 ExtraRules: false, 64 }, 65 ErrorLint: ErrorLintSettings{ 66 Errorf: true, 67 Asserts: true, 68 Comparison: true, 69 }, 70 Ifshort: IfshortSettings{ 71 MaxDeclLines: 1, 72 MaxDeclChars: 30, 73 }, 74 Predeclared: PredeclaredSettings{ 75 Ignore: "", 76 Qualified: false, 77 }, 78 Forbidigo: ForbidigoSettings{ 79 ExcludeGodocExamples: true, 80 }, 81 } 82 83 type LintersSettings struct { 84 Cyclop Cyclop 85 Depguard DepGuardSettings 86 Dogsled DogsledSettings 87 Dupl DuplSettings 88 Errcheck ErrcheckSettings 89 ErrorLint ErrorLintSettings 90 Exhaustive ExhaustiveSettings 91 ExhaustiveStruct ExhaustiveStructSettings 92 Forbidigo ForbidigoSettings 93 Funlen FunlenSettings 94 Gci GciSettings 95 Gocognit GocognitSettings 96 Goconst GoConstSettings 97 Gocritic GocriticSettings 98 Gocyclo GoCycloSettings 99 Godot GodotSettings 100 Godox GodoxSettings 101 Gofmt GoFmtSettings 102 Gofumpt GofumptSettings 103 Goheader GoHeaderSettings 104 Goimports GoImportsSettings 105 Golint GoLintSettings 106 Gomnd GoMndSettings 107 GoModDirectives GoModDirectivesSettings 108 Gomodguard GoModGuardSettings 109 Gosec GoSecSettings 110 Gosimple StaticCheckSettings 111 Govet GovetSettings 112 Ifshort IfshortSettings 113 ImportAs ImportAsSettings 114 Lll LllSettings 115 Makezero MakezeroSettings 116 Maligned MalignedSettings 117 Misspell MisspellSettings 118 Nakedret NakedretSettings 119 Nestif NestifSettings 120 NoLintLint NoLintLintSettings 121 Prealloc PreallocSettings 122 Predeclared PredeclaredSettings 123 Promlinter PromlinterSettings 124 Revive ReviveSettings 125 RowsErrCheck RowsErrCheckSettings 126 Staticcheck StaticCheckSettings 127 Structcheck StructCheckSettings 128 Stylecheck StaticCheckSettings 129 Tagliatelle TagliatelleSettings 130 Testpackage TestpackageSettings 131 Thelper ThelperSettings 132 Unparam UnparamSettings 133 Unused StaticCheckSettings 134 Varcheck VarCheckSettings 135 Whitespace WhitespaceSettings 136 Wrapcheck WrapcheckSettings 137 WSL WSLSettings 138 139 Custom map[string]CustomLinterSettings 140 } 141 142 type Cyclop struct { 143 MaxComplexity int `mapstructure:"max-complexity"` 144 PackageAverage float64 `mapstructure:"package-average"` 145 SkipTests bool `mapstructure:"skip-tests"` 146 } 147 148 type DepGuardSettings struct { 149 ListType string `mapstructure:"list-type"` 150 Packages []string 151 IncludeGoRoot bool `mapstructure:"include-go-root"` 152 PackagesWithErrorMessage map[string]string `mapstructure:"packages-with-error-message"` 153 } 154 155 type DogsledSettings struct { 156 MaxBlankIdentifiers int `mapstructure:"max-blank-identifiers"` 157 } 158 159 type DuplSettings struct { 160 Threshold int 161 } 162 163 type ErrcheckSettings struct { 164 CheckTypeAssertions bool `mapstructure:"check-type-assertions"` 165 CheckAssignToBlank bool `mapstructure:"check-blank"` 166 Ignore string `mapstructure:"ignore"` 167 ExcludeFunctions []string `mapstructure:"exclude-functions"` 168 169 // Deprecated: use ExcludeFunctions instead 170 Exclude string `mapstructure:"exclude"` 171 } 172 173 type ErrorLintSettings struct { 174 Errorf bool `mapstructure:"errorf"` 175 Asserts bool `mapstructure:"asserts"` 176 Comparison bool `mapstructure:"comparison"` 177 } 178 179 type ExhaustiveSettings struct { 180 CheckGenerated bool `mapstructure:"check-generated"` 181 DefaultSignifiesExhaustive bool `mapstructure:"default-signifies-exhaustive"` 182 IgnorePattern string `mapstructure:"ignore-pattern"` 183 } 184 185 type ExhaustiveStructSettings struct { 186 StructPatterns []string `mapstructure:"struct-patterns"` 187 } 188 189 type ForbidigoSettings struct { 190 Forbid []string `mapstructure:"forbid"` 191 ExcludeGodocExamples bool `mapstructure:"exclude-godoc-examples"` 192 } 193 194 type FunlenSettings struct { 195 Lines int 196 Statements int 197 } 198 199 type GciSettings struct { 200 LocalPrefixes string `mapstructure:"local-prefixes"` 201 } 202 203 type GocognitSettings struct { 204 MinComplexity int `mapstructure:"min-complexity"` 205 } 206 207 type GoConstSettings struct { 208 IgnoreTests bool `mapstructure:"ignore-tests"` 209 MatchWithConstants bool `mapstructure:"match-constant"` 210 MinStringLen int `mapstructure:"min-len"` 211 MinOccurrencesCount int `mapstructure:"min-occurrences"` 212 ParseNumbers bool `mapstructure:"numbers"` 213 NumberMin int `mapstructure:"min"` 214 NumberMax int `mapstructure:"max"` 215 IgnoreCalls bool `mapstructure:"ignore-calls"` 216 } 217 218 type GoCycloSettings struct { 219 MinComplexity int `mapstructure:"min-complexity"` 220 } 221 222 type GodotSettings struct { 223 Scope string `mapstructure:"scope"` 224 Exclude []string `mapstructure:"exclude"` 225 Capital bool `mapstructure:"capital"` 226 227 // Deprecated: use `Scope` instead 228 CheckAll bool `mapstructure:"check-all"` 229 } 230 231 type GodoxSettings struct { 232 Keywords []string 233 } 234 235 type GoFmtSettings struct { 236 Simplify bool 237 } 238 239 type GofumptSettings struct { 240 LangVersion string `mapstructure:"lang-version"` 241 ExtraRules bool `mapstructure:"extra-rules"` 242 } 243 244 type GoHeaderSettings struct { 245 Values map[string]map[string]string `mapstructure:"values"` 246 Template string `mapstructure:"template"` 247 TemplatePath string `mapstructure:"template-path"` 248 } 249 250 type GoImportsSettings struct { 251 LocalPrefixes string `mapstructure:"local-prefixes"` 252 } 253 254 type GoLintSettings struct { 255 MinConfidence float64 `mapstructure:"min-confidence"` 256 } 257 258 type GoMndSettings struct { 259 Settings map[string]map[string]interface{} 260 } 261 262 type GoModDirectivesSettings struct { 263 ReplaceAllowList []string `mapstructure:"replace-allow-list"` 264 ReplaceLocal bool `mapstructure:"replace-local"` 265 ExcludeForbidden bool `mapstructure:"exclude-forbidden"` 266 RetractAllowNoExplanation bool `mapstructure:"retract-allow-no-explanation"` 267 } 268 269 type GoModGuardSettings struct { 270 Allowed struct { 271 Modules []string `mapstructure:"modules"` 272 Domains []string `mapstructure:"domains"` 273 } `mapstructure:"allowed"` 274 Blocked struct { 275 Modules []map[string]struct { 276 Recommendations []string `mapstructure:"recommendations"` 277 Reason string `mapstructure:"reason"` 278 } `mapstructure:"modules"` 279 Versions []map[string]struct { 280 Version string `mapstructure:"version"` 281 Reason string `mapstructure:"reason"` 282 } `mapstructure:"versions"` 283 LocalReplaceDirectives bool `mapstructure:"local_replace_directives"` 284 } `mapstructure:"blocked"` 285 } 286 287 type GoSecSettings struct { 288 Includes []string 289 Excludes []string 290 Config map[string]interface{} `mapstructure:"config"` 291 } 292 293 type GovetSettings struct { 294 CheckShadowing bool `mapstructure:"check-shadowing"` 295 Settings map[string]map[string]interface{} 296 297 Enable []string 298 Disable []string 299 EnableAll bool `mapstructure:"enable-all"` 300 DisableAll bool `mapstructure:"disable-all"` 301 } 302 303 func (cfg GovetSettings) Validate() error { 304 if cfg.EnableAll && cfg.DisableAll { 305 return errors.New("enable-all and disable-all can't be combined") 306 } 307 if cfg.EnableAll && len(cfg.Enable) != 0 { 308 return errors.New("enable-all and enable can't be combined") 309 } 310 if cfg.DisableAll && len(cfg.Disable) != 0 { 311 return errors.New("disable-all and disable can't be combined") 312 } 313 return nil 314 } 315 316 type IfshortSettings struct { 317 MaxDeclLines int `mapstructure:"max-decl-lines"` 318 MaxDeclChars int `mapstructure:"max-decl-chars"` 319 } 320 321 type ImportAsSettings struct { 322 Alias []ImportAsAlias 323 NoUnaliased bool `mapstructure:"no-unaliased"` 324 } 325 326 type ImportAsAlias struct { 327 Pkg string 328 Alias string 329 } 330 331 type LllSettings struct { 332 LineLength int `mapstructure:"line-length"` 333 TabWidth int `mapstructure:"tab-width"` 334 } 335 336 type MakezeroSettings struct { 337 Always bool 338 } 339 340 type MalignedSettings struct { 341 SuggestNewOrder bool `mapstructure:"suggest-new"` 342 } 343 344 type MisspellSettings struct { 345 Locale string 346 IgnoreWords []string `mapstructure:"ignore-words"` 347 } 348 349 type NakedretSettings struct { 350 MaxFuncLines int `mapstructure:"max-func-lines"` 351 } 352 353 type NestifSettings struct { 354 MinComplexity int `mapstructure:"min-complexity"` 355 } 356 357 type NoLintLintSettings struct { 358 RequireExplanation bool `mapstructure:"require-explanation"` 359 AllowLeadingSpace bool `mapstructure:"allow-leading-space"` 360 RequireSpecific bool `mapstructure:"require-specific"` 361 AllowNoExplanation []string `mapstructure:"allow-no-explanation"` 362 AllowUnused bool `mapstructure:"allow-unused"` 363 } 364 365 type PreallocSettings struct { 366 Simple bool 367 RangeLoops bool `mapstructure:"range-loops"` 368 ForLoops bool `mapstructure:"for-loops"` 369 } 370 371 type PredeclaredSettings struct { 372 Ignore string `mapstructure:"ignore"` 373 Qualified bool `mapstructure:"q"` 374 } 375 376 type PromlinterSettings struct { 377 Strict bool `mapstructure:"strict"` 378 DisabledLinters []string `mapstructure:"disabled-linters"` 379 } 380 381 type ReviveSettings struct { 382 IgnoreGeneratedHeader bool `mapstructure:"ignore-generated-header"` 383 Confidence float64 384 Severity string 385 EnableAllRules bool `mapstructure:"enable-all-rules"` 386 Rules []struct { 387 Name string 388 Arguments []interface{} 389 Severity string 390 Disabled bool 391 } 392 ErrorCode int `mapstructure:"error-code"` 393 WarningCode int `mapstructure:"warning-code"` 394 Directives []struct { 395 Name string 396 Severity string 397 } 398 } 399 400 type RowsErrCheckSettings struct { 401 Packages []string 402 } 403 404 type StaticCheckSettings struct { 405 GoVersion string `mapstructure:"go"` 406 407 Checks []string `mapstructure:"checks"` 408 Initialisms []string `mapstructure:"initialisms"` // only for stylecheck 409 DotImportWhitelist []string `mapstructure:"dot-import-whitelist"` // only for stylecheck 410 HTTPStatusCodeWhitelist []string `mapstructure:"http-status-code-whitelist"` // only for stylecheck 411 } 412 413 func (s *StaticCheckSettings) HasConfiguration() bool { 414 return len(s.Initialisms) > 0 || len(s.HTTPStatusCodeWhitelist) > 0 || len(s.DotImportWhitelist) > 0 || len(s.Checks) > 0 415 } 416 417 type StructCheckSettings struct { 418 CheckExportedFields bool `mapstructure:"exported-fields"` 419 } 420 421 type TagliatelleSettings struct { 422 Case struct { 423 Rules map[string]string 424 UseFieldName bool `mapstructure:"use-field-name"` 425 } 426 } 427 428 type TestpackageSettings struct { 429 SkipRegexp string `mapstructure:"skip-regexp"` 430 } 431 432 type ThelperSettings struct { 433 Test struct { 434 First bool `mapstructure:"first"` 435 Name bool `mapstructure:"name"` 436 Begin bool `mapstructure:"begin"` 437 } `mapstructure:"test"` 438 Benchmark struct { 439 First bool `mapstructure:"first"` 440 Name bool `mapstructure:"name"` 441 Begin bool `mapstructure:"begin"` 442 } `mapstructure:"benchmark"` 443 TB struct { 444 First bool `mapstructure:"first"` 445 Name bool `mapstructure:"name"` 446 Begin bool `mapstructure:"begin"` 447 } `mapstructure:"tb"` 448 } 449 450 type UnparamSettings struct { 451 CheckExported bool `mapstructure:"check-exported"` 452 Algo string 453 } 454 455 type VarCheckSettings struct { 456 CheckExportedFields bool `mapstructure:"exported-fields"` 457 } 458 459 type WhitespaceSettings struct { 460 MultiIf bool `mapstructure:"multi-if"` 461 MultiFunc bool `mapstructure:"multi-func"` 462 } 463 464 type WrapcheckSettings struct { 465 IgnoreSigs []string `mapstructure:"ignoreSigs"` 466 IgnorePackageGlobs []string `mapstructure:"ignorePackageGlobs"` 467 } 468 469 type WSLSettings struct { 470 StrictAppend bool `mapstructure:"strict-append"` 471 AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"` 472 AllowAssignAndAnythingCuddle bool `mapstructure:"allow-assign-and-anything"` 473 AllowMultiLineAssignCuddle bool `mapstructure:"allow-multiline-assign"` 474 AllowCuddleDeclaration bool `mapstructure:"allow-cuddle-declarations"` 475 AllowTrailingComment bool `mapstructure:"allow-trailing-comment"` 476 AllowSeparatedLeadingComment bool `mapstructure:"allow-separated-leading-comment"` 477 ForceCuddleErrCheckAndAssign bool `mapstructure:"force-err-cuddling"` 478 ForceExclusiveShortDeclarations bool `mapstructure:"force-short-decl-cuddling"` 479 ForceCaseTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace"` 480 } 481 482 type CustomLinterSettings struct { 483 Path string 484 Description string 485 OriginalURL string `mapstructure:"original-url"` 486 }