From f91e0f37c91b9c1bbb31ca256864d1669338425e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 28 Jul 2024 11:11:24 +0000 Subject: [PATCH 1/4] build(deps): bump github.com/mgechev/revive from 1.3.7 to 1.3.9 Bumps [github.com/mgechev/revive](https://github.com/mgechev/revive) from 1.3.7 to 1.3.9. - [Release notes](https://github.com/mgechev/revive/releases) - [Changelog](https://github.com/mgechev/revive/blob/master/.goreleaser.yml) - [Commits](https://github.com/mgechev/revive/compare/v1.3.7...v1.3.9) --- updated-dependencies: - dependency-name: github.com/mgechev/revive dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index eeb410aedc99..f103663f94d5 100644 --- a/go.mod +++ b/go.mod @@ -75,7 +75,7 @@ require ( github.com/maratori/testpackage v1.1.1 github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26 github.com/mattn/go-colorable v0.1.13 - github.com/mgechev/revive v1.3.7 + github.com/mgechev/revive v1.3.9 github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-ps v1.0.0 github.com/moricho/tparallel v0.3.2 diff --git a/go.sum b/go.sum index 2a0060345876..e76f2950ea43 100644 --- a/go.sum +++ b/go.sum @@ -370,8 +370,8 @@ github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/Qd github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mgechev/revive v1.3.7 h1:502QY0vQGe9KtYJ9FpxMz9rL+Fc/P13CI5POL4uHCcE= -github.com/mgechev/revive v1.3.7/go.mod h1:RJ16jUbF0OWC3co/+XTxmFNgEpUPwnnA0BRllX2aDNA= +github.com/mgechev/revive v1.3.9 h1:18Y3R4a2USSBF+QZKFQwVkBROUda7uoBlkEuBD+YD1A= +github.com/mgechev/revive v1.3.9/go.mod h1:+uxEIr5UH0TjXWHTno3xh4u7eg6jDpXKzQccA9UGhHU= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= From b512c364eaefa92687752c642435e5a4702b0c8d Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 28 Jul 2024 13:39:29 +0200 Subject: [PATCH 2/4] chore: add new rule --- .golangci.next.reference.yml | 6 ++++++ jsonschema/golangci.next.jsonschema.json | 1 + pkg/golinters/revive/revive.go | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index ad01b36078ac..72b2d158ff9c 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -1612,6 +1612,12 @@ linters-settings: arguments: - mypragma - otherpragma + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#comments-density + - name: comments-density + severity: warning + disabled: false + exclude: [""] + arguments: [ 15 ] # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#confusing-naming - name: confusing-naming severity: warning diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 0999c278efe7..9acf00dcb04b 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -217,6 +217,7 @@ "call-to-gc", "cognitive-complexity", "comment-spacings", + "comments-density", "confusing-naming", "confusing-results", "constant-logical-expr", diff --git a/pkg/golinters/revive/revive.go b/pkg/golinters/revive/revive.go index 3a76cee27e32..011331c1befe 100644 --- a/pkg/golinters/revive/revive.go +++ b/pkg/golinters/revive/revive.go @@ -275,7 +275,7 @@ func safeTomlSlice(r []any) []any { } // This element is not exported by revive, so we need copy the code. -// Extracted from https://github.com/mgechev/revive/blob/v1.3.7/config/config.go#L15 +// Extracted from https://github.com/mgechev/revive/blob/v1.3.9/config/config.go#L15 var defaultRules = []lint.Rule{ &rule.VarDeclarationsRule{}, &rule.PackageCommentsRule{}, @@ -358,6 +358,7 @@ var allRules = append([]lint.Rule{ &rule.EnforceRepeatedArgTypeStyleRule{}, &rule.EnforceSliceStyleRule{}, &rule.MaxControlNestingRule{}, + &rule.CommentsDensityRule{}, }, defaultRules...) const defaultConfidence = 0.8 From 3aede8ce2613b474d2ac6c8132b8744d92b07b87 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 28 Jul 2024 13:52:48 +0200 Subject: [PATCH 3/4] chore: use Go version --- pkg/config/linters_settings.go | 5 +++-- pkg/config/loader.go | 2 ++ pkg/golinters/revive/revive.go | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index f159db2a96d8..2be146715ba5 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -791,8 +791,9 @@ type ReassignSettings struct { } type ReviveSettings struct { - MaxOpenFiles int `mapstructure:"max-open-files"` - IgnoreGeneratedHeader bool `mapstructure:"ignore-generated-header"` + Go string `mapstructure:"-"` + MaxOpenFiles int `mapstructure:"max-open-files"` + IgnoreGeneratedHeader bool `mapstructure:"ignore-generated-header"` Confidence float64 Severity string EnableAllRules bool `mapstructure:"enable-all-rules"` diff --git a/pkg/config/loader.go b/pkg/config/loader.go index ea4cae2d5542..03b7425a09d8 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -292,6 +292,8 @@ func (l *Loader) handleGoVersion() { trimmedGoVersion := trimGoVersion(l.cfg.Run.Go) + l.cfg.LintersSettings.Revive.Go = trimmedGoVersion + l.cfg.LintersSettings.Gocritic.Go = trimmedGoVersion // staticcheck related linters. diff --git a/pkg/golinters/revive/revive.go b/pkg/golinters/revive/revive.go index 011331c1befe..99f77ce9810f 100644 --- a/pkg/golinters/revive/revive.go +++ b/pkg/golinters/revive/revive.go @@ -10,6 +10,7 @@ import ( "sync" "github.com/BurntSushi/toml" + hcversion "github.com/hashicorp/go-version" reviveConfig "github.com/mgechev/revive/config" "github.com/mgechev/revive/lint" "github.com/mgechev/revive/rule" @@ -89,6 +90,11 @@ func newWrapper(settings *config.ReviveSettings) (*wrapper, error) { return nil, err } + conf.GoVersion, err = hcversion.NewVersion(settings.Go) + if err != nil { + return nil, err + } + formatter, err := reviveConfig.GetFormatter("json") if err != nil { return nil, err From 66de059360213b13e1a593fc1ca46e7bc96fd0fc Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 28 Jul 2024 14:38:27 +0200 Subject: [PATCH 4/4] chore: fix default configuration --- pkg/golinters/revive/revive.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/golinters/revive/revive.go b/pkg/golinters/revive/revive.go index 99f77ce9810f..90ce15db6307 100644 --- a/pkg/golinters/revive/revive.go +++ b/pkg/golinters/revive/revive.go @@ -189,7 +189,10 @@ func toIssue(pass *analysis.Pass, object *jsonObject) goanalysis.Issue { func getConfig(cfg *config.ReviveSettings) (*lint.Config, error) { conf := defaultConfig() - if !reflect.DeepEqual(cfg, &config.ReviveSettings{}) { + // Since the Go version is dynamic, this value must be neutralized in order to compare with a "zero value" of the configuration structure. + zero := &config.ReviveSettings{Go: cfg.Go} + + if !reflect.DeepEqual(cfg, zero) { rawRoot := createConfigMap(cfg) buf := bytes.NewBuffer(nil)