From 874eabd55c0cb52e41ec2541423d85c190422ce6 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Wed, 23 Feb 2022 09:28:49 +0100 Subject: [PATCH] revive: fix default values (#2611) --- go.mod | 1 - go.sum | 1 - pkg/golinters/revive.go | 18 +++++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 63f62d79da30..238533e9e9f3 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,6 @@ require ( github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 // v1.0 github.com/mattn/go-colorable v0.1.12 github.com/mbilski/exhaustivestruct v1.2.0 - github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517 github.com/mgechev/revive v1.1.4 github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-ps v1.0.0 diff --git a/go.sum b/go.sum index 7bb64756badc..1d2ab740044f 100644 --- a/go.sum +++ b/go.sum @@ -537,7 +537,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mbilski/exhaustivestruct v1.2.0 h1:wCBmUnSYufAHO6J4AVWY6ff+oxWxsVFrwgOdMUQePUo= github.com/mbilski/exhaustivestruct v1.2.0/go.mod h1:OeTBVxQWoEmB2J2JCHmXWPJ0aksxSUOUy+nvtVEfzXc= -github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517 h1:zpIH83+oKzcpryru8ceC6BxnoG8TBrhgAvRg8obzup0= github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg= github.com/mgechev/revive v1.1.4 h1:sZOjY6GU35Kr9jKa/wsKSHgrFz8eASIB5i3tqWZMp0A= github.com/mgechev/revive v1.1.4/go.mod h1:ZZq2bmyssGh8MSPz3VVziqRNIMYTJXzP8MUKG90vZ9A= diff --git a/pkg/golinters/revive.go b/pkg/golinters/revive.go index d8165f3cede7..64fe20d2f98e 100644 --- a/pkg/golinters/revive.go +++ b/pkg/golinters/revive.go @@ -9,7 +9,6 @@ import ( "reflect" "github.com/BurntSushi/toml" - "github.com/mgechev/dots" reviveConfig "github.com/mgechev/revive/config" "github.com/mgechev/revive/lint" "github.com/mgechev/revive/rule" @@ -50,10 +49,10 @@ func NewRevive(cfg *config.ReviveSettings) *goanalysis.Linter { ).WithContextSetter(func(lintCtx *linter.Context) { analyzer.Run = func(pass *analysis.Pass) (interface{}, error) { var files []string - for _, file := range pass.Files { files = append(files, pass.Fset.PositionFor(file.Pos(), false).Filename) } + packages := [][]string{files} conf, err := getReviveConfig(cfg) if err != nil { @@ -72,11 +71,6 @@ func NewRevive(cfg *config.ReviveSettings) *goanalysis.Linter { return nil, err } - packages, err := dots.ResolvePackages(files, []string{}) - if err != nil { - return nil, err - } - failures, err := revive.Lint(packages, lintingRules, *conf) if err != nil { return nil, err @@ -315,6 +309,16 @@ const defaultConfidence = 0.8 // This element is not exported by revive, so we need copy the code. // Extracted from https://github.com/mgechev/revive/blob/v1.1.4/config/config.go#L145 func normalizeConfig(cfg *lint.Config) { + // NOTE(ldez): this custom section for golangci-lint should be kept. + // --- + if cfg.Confidence == 0 { + cfg.Confidence = defaultConfidence + } + if cfg.Severity == "" { + cfg.Severity = lint.SeverityWarning + } + // --- + if len(cfg.Rules) == 0 { cfg.Rules = map[string]lint.RuleConfig{} }