www.github.com/golangci/golangci-lint.git@v1.10.1/pkg/config/config.go (about) 1 package config 2 3 import ( 4 "time" 5 ) 6 7 const ( 8 OutFormatJSON = "json" 9 OutFormatLineNumber = "line-number" 10 OutFormatColoredLineNumber = "colored-line-number" 11 OutFormatTab = "tab" 12 OutFormatCheckstyle = "checkstyle" 13 ) 14 15 var OutFormats = []string{ 16 OutFormatColoredLineNumber, 17 OutFormatLineNumber, 18 OutFormatJSON, 19 OutFormatTab, 20 OutFormatCheckstyle, 21 } 22 23 type ExcludePattern struct { 24 Pattern string 25 Linter string 26 Why string 27 } 28 29 var DefaultExcludePatterns = []ExcludePattern{ 30 { 31 Pattern: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close" + 32 "|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked", 33 Linter: "errcheck", 34 Why: "Almost all programs ignore errors on these functions and in most cases it's ok", 35 }, 36 { 37 Pattern: "(comment on exported (method|function|type|const)|" + 38 "should have( a package)? comment|comment should be of the form)", 39 Linter: "golint", 40 Why: "Annoying issue about not having a comment. The rare codebase has such comments", 41 }, 42 { 43 Pattern: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this", 44 Linter: "golint", 45 Why: "False positive when tests are defined in package 'test'", 46 }, 47 { 48 Pattern: "Use of unsafe calls should be audited", 49 Linter: "gas", 50 Why: "Too many false-positives on 'unsafe' usage", 51 }, 52 { 53 Pattern: "Subprocess launch(ed with variable|ing should be audited)", 54 Linter: "gas", 55 Why: "Too many false-positives for parametrized shell calls", 56 }, 57 { 58 Pattern: "G104", 59 Linter: "gas", 60 Why: "Duplicated errcheck checks", 61 }, 62 { 63 Pattern: "(Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)", 64 Linter: "gas", 65 Why: "Too many issues in popular repos", 66 }, 67 { 68 Pattern: "Potential file inclusion via variable", 69 Linter: "gas", 70 Why: "False positive is triggered by 'src, err := ioutil.ReadFile(filename)'", 71 }, 72 { 73 Pattern: "(possible misuse of unsafe.Pointer|should have signature)", 74 Linter: "govet", 75 Why: "Common false positives", 76 }, 77 { 78 Pattern: "ineffective break statement. Did you mean to break out of the outer loop", 79 Linter: "megacheck", 80 Why: "Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore", 81 }, 82 } 83 84 func GetDefaultExcludePatternsStrings() []string { 85 var ret []string 86 for _, p := range DefaultExcludePatterns { 87 ret = append(ret, p.Pattern) 88 } 89 90 return ret 91 } 92 93 type Run struct { 94 IsVerbose bool `mapstructure:"verbose"` 95 Silent bool 96 CPUProfilePath string 97 MemProfilePath string 98 Concurrency int 99 PrintResourcesUsage bool `mapstructure:"print-resources-usage"` 100 101 Config string 102 NoConfig bool 103 104 Args []string 105 106 BuildTags []string `mapstructure:"build-tags"` 107 108 ExitCodeIfIssuesFound int `mapstructure:"issues-exit-code"` 109 AnalyzeTests bool `mapstructure:"tests"` 110 Deadline time.Duration 111 PrintVersion bool 112 113 SkipFiles []string `mapstructure:"skip-files"` 114 SkipDirs []string `mapstructure:"skip-dirs"` 115 } 116 117 type LintersSettings struct { 118 Errcheck struct { 119 CheckTypeAssertions bool `mapstructure:"check-type-assertions"` 120 CheckAssignToBlank bool `mapstructure:"check-blank"` 121 } 122 Govet struct { 123 CheckShadowing bool `mapstructure:"check-shadowing"` 124 UseInstalledPackages bool `mapstructure:"use-installed-packages"` 125 } 126 Golint struct { 127 MinConfidence float64 `mapstructure:"min-confidence"` 128 } 129 Gofmt struct { 130 Simplify bool 131 } 132 Gocyclo struct { 133 MinComplexity int `mapstructure:"min-complexity"` 134 } 135 Varcheck struct { 136 CheckExportedFields bool `mapstructure:"exported-fields"` 137 } 138 Structcheck struct { 139 CheckExportedFields bool `mapstructure:"exported-fields"` 140 } 141 Maligned struct { 142 SuggestNewOrder bool `mapstructure:"suggest-new"` 143 } 144 Dupl struct { 145 Threshold int 146 } 147 Goconst struct { 148 MinStringLen int `mapstructure:"min-len"` 149 MinOccurrencesCount int `mapstructure:"min-occurrences"` 150 } 151 Depguard struct { 152 ListType string `mapstructure:"list-type"` 153 Packages []string 154 IncludeGoRoot bool `mapstructure:"include-go-root"` 155 } 156 Misspell struct { 157 Locale string 158 } 159 Unused struct { 160 CheckExported bool `mapstructure:"check-exported"` 161 } 162 163 Lll LllSettings 164 Unparam UnparamSettings 165 Nakedret NakedretSettings 166 Prealloc PreallocSettings 167 } 168 169 type LllSettings struct { 170 LineLength int `mapstructure:"line-length"` 171 TabWidth int `mapstructure:"tab-width"` 172 } 173 174 type UnparamSettings struct { 175 CheckExported bool `mapstructure:"check-exported"` 176 Algo string 177 } 178 179 type NakedretSettings struct { 180 MaxFuncLines int `mapstructure:"max-func-lines"` 181 } 182 183 type PreallocSettings struct { 184 Simple bool 185 RangeLoops bool `mapstructure:"range-loops"` 186 ForLoops bool `mapstructure:"for-loops"` 187 } 188 189 var defaultLintersSettings = LintersSettings{ 190 Lll: LllSettings{ 191 LineLength: 120, 192 TabWidth: 1, 193 }, 194 Unparam: UnparamSettings{ 195 Algo: "cha", 196 }, 197 Nakedret: NakedretSettings{ 198 MaxFuncLines: 30, 199 }, 200 Prealloc: PreallocSettings{ 201 Simple: true, 202 RangeLoops: true, 203 ForLoops: false, 204 }, 205 } 206 207 type Linters struct { 208 Enable []string 209 Disable []string 210 EnableAll bool `mapstructure:"enable-all"` 211 DisableAll bool `mapstructure:"disable-all"` 212 Fast bool 213 214 Presets []string 215 } 216 217 type Issues struct { 218 ExcludePatterns []string `mapstructure:"exclude"` 219 UseDefaultExcludes bool `mapstructure:"exclude-use-default"` 220 221 MaxIssuesPerLinter int `mapstructure:"max-issues-per-linter"` 222 MaxSameIssues int `mapstructure:"max-same-issues"` 223 224 DiffFromRevision string `mapstructure:"new-from-rev"` 225 DiffPatchFilePath string `mapstructure:"new-from-patch"` 226 Diff bool `mapstructure:"new"` 227 } 228 229 type Config struct { //nolint:maligned 230 Run Run 231 232 Output struct { 233 Format string 234 PrintIssuedLine bool `mapstructure:"print-issued-lines"` 235 PrintLinterName bool `mapstructure:"print-linter-name"` 236 PrintWelcomeMessage bool `mapstructure:"print-welcome"` 237 } 238 239 LintersSettings LintersSettings `mapstructure:"linters-settings"` 240 Linters Linters 241 Issues Issues 242 243 InternalTest bool // Option is used only for testing golangci-lint code, don't use it 244 } 245 246 func NewDefault() *Config { 247 return &Config{ 248 LintersSettings: defaultLintersSettings, 249 } 250 }