Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revive: fix default values #2611

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions pkg/golinters/revive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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{}
}
Expand Down