|
1 | 1 | package config |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "errors" |
5 | | - "strings" |
6 | 4 | "time" |
7 | | - |
8 | | - "github.com/golangci/golangci-lint/pkg/logutils" |
9 | 5 | ) |
10 | 6 |
|
11 | 7 | const ( |
@@ -198,99 +194,6 @@ type PreallocSettings struct { |
198 | 194 | ForLoops bool `mapstructure:"for-loops"` |
199 | 195 | } |
200 | 196 |
|
201 | | -type GocriticCheckSettings map[string]interface{} |
202 | | - |
203 | | -type GocriticSettings struct { |
204 | | - EnabledChecks []string `mapstructure:"enabled-checks"` |
205 | | - DisabledChecks []string `mapstructure:"disabled-checks"` |
206 | | - SettingsPerCheck map[string]GocriticCheckSettings `mapstructure:"settings"` |
207 | | - |
208 | | - inferredEnabledChecks map[string]bool |
209 | | -} |
210 | | - |
211 | | -func (s *GocriticSettings) InferEnabledChecks(log logutils.Log) { |
212 | | - enabledChecks := s.EnabledChecks |
213 | | - if len(enabledChecks) == 0 { |
214 | | - if len(s.DisabledChecks) != 0 { |
215 | | - for _, defaultCheck := range defaultGocriticEnabledChecks { |
216 | | - if !s.isCheckDisabled(defaultCheck) { |
217 | | - enabledChecks = append(enabledChecks, defaultCheck) |
218 | | - } |
219 | | - } |
220 | | - } else { |
221 | | - enabledChecks = defaultGocriticEnabledChecks |
222 | | - } |
223 | | - } |
224 | | - |
225 | | - s.inferredEnabledChecks = map[string]bool{} |
226 | | - for _, check := range enabledChecks { |
227 | | - s.inferredEnabledChecks[strings.ToLower(check)] = true |
228 | | - } |
229 | | - log.Infof("Gocritic enabled checks: %s", enabledChecks) |
230 | | -} |
231 | | - |
232 | | -func (s GocriticSettings) isCheckDisabled(name string) bool { |
233 | | - for _, disabledCheck := range s.DisabledChecks { |
234 | | - if disabledCheck == name { |
235 | | - return true |
236 | | - } |
237 | | - } |
238 | | - |
239 | | - return false |
240 | | -} |
241 | | - |
242 | | -func (s GocriticSettings) Validate(log logutils.Log) error { |
243 | | - if len(s.EnabledChecks) != 0 && len(s.DisabledChecks) != 0 { |
244 | | - return errors.New("both enabled and disabled check aren't allowed for gocritic") |
245 | | - } |
246 | | - |
247 | | - for checkName := range s.SettingsPerCheck { |
248 | | - if !s.IsCheckEnabled(checkName) { |
249 | | - log.Warnf("Gocritic settings were provided for not enabled check %q", checkName) |
250 | | - } |
251 | | - } |
252 | | - |
253 | | - return nil |
254 | | -} |
255 | | - |
256 | | -func (s GocriticSettings) IsCheckEnabled(name string) bool { |
257 | | - return s.inferredEnabledChecks[strings.ToLower(name)] |
258 | | -} |
259 | | - |
260 | | -// Its a good idea to keep this list in sync with the gocritic stable checks list in: |
261 | | -// https://github.com/go-critic/go-critic/blob/master/checkers/checkers_test.go#L63 |
262 | | -var defaultGocriticEnabledChecks = []string{ |
263 | | - "appendAssign", |
264 | | - "appendCombine", |
265 | | - "assignOp", |
266 | | - "builtinShadow", |
267 | | - "captLocal", |
268 | | - "caseOrder", |
269 | | - "defaultCaseOrder", |
270 | | - "dupArg", |
271 | | - "dupBranchBody", |
272 | | - "dupCase", |
273 | | - "elseif", |
274 | | - "flagDeref", |
275 | | - "ifElseChain", |
276 | | - "importShadow", |
277 | | - "indexAlloc", |
278 | | - "paramTypeCombine", |
279 | | - "rangeExprCopy", |
280 | | - "rangeValCopy", |
281 | | - "regexpMust", |
282 | | - "singleCaseSwitch", |
283 | | - "sloppyLen", |
284 | | - "switchTrue", |
285 | | - "typeSwitchVar", |
286 | | - "typeUnparen", |
287 | | - "underef", |
288 | | - "unlambda", |
289 | | - "unslice", |
290 | | - "dupSubExpr", |
291 | | - "hugeParam", |
292 | | -} |
293 | | - |
294 | 197 | var defaultLintersSettings = LintersSettings{ |
295 | 198 | Lll: LllSettings{ |
296 | 199 | LineLength: 120, |
|
0 commit comments