From 6e7c5bdc1ebf9c96ff6ee24ed27db742d897f784 Mon Sep 17 00:00:00 2001 From: ccoVeille <3875889+ccoVeille@users.noreply.github.com> Date: Wed, 15 Jan 2025 15:03:05 +0100 Subject: [PATCH 1/5] dev: update GL_DEBUG=revive to see enabled analyzers --- pkg/golinters/revive/revive.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/pkg/golinters/revive/revive.go b/pkg/golinters/revive/revive.go index ec621ccfba28..bce6bcfdb224 100644 --- a/pkg/golinters/revive/revive.go +++ b/pkg/golinters/revive/revive.go @@ -8,6 +8,7 @@ import ( "go/token" "os" "reflect" + "sort" "sync" "github.com/BurntSushi/toml" @@ -27,7 +28,10 @@ import ( const linterName = "revive" -var debugf = logutils.Debug(logutils.DebugKeyRevive) +var ( + debugf = logutils.Debug(logutils.DebugKeyRevive) + isDebug = logutils.HaveDebugTag(logutils.DebugKeyRevive) +) // jsonObject defines a JSON object of a failure type jsonObject struct { @@ -228,14 +232,23 @@ func getConfig(cfg *config.ReviveSettings) (*lint.Config, error) { normalizeConfig(conf) + rulesEnabledByConfig := []string{} for k, r := range conf.Rules { err := r.Initialize() if err != nil { return nil, fmt.Errorf("error in config of rule %q: %w", k, err) } conf.Rules[k] = r + + if !r.Disabled { + rulesEnabledByConfig = append(rulesEnabledByConfig, k) + } } + debugChecksListf(extractRulesName(allRules), "All available analyzers") + debugChecksListf(extractRulesName(defaultRules), "Default analyzers") + debugChecksListf(rulesEnabledByConfig, "Enabled by config analyzers") + debugf("revive configuration: %#v", conf) return conf, nil @@ -447,3 +460,20 @@ func defaultConfig() *lint.Config { } return &defaultConfig } + +func extractRulesName(rules []lint.Rule) []string { + names := []string{} + for _, r := range rules { + names = append(names, r.Name()) + } + return names +} + +func debugChecksListf(checks []string, format string, args ...any) { + if !isDebug { + return + } + sort.Strings(checks) + + debugf("%s checks (%d): %s", fmt.Sprintf(format, args...), len(checks), fmt.Sprint(checks)) +} From 808e1bfd8e04daa69a10832734ce3fbc192bbd69 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 15 Jan 2025 15:54:53 +0100 Subject: [PATCH 2/5] review --- pkg/golinters/revive/revive.go | 48 ++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/pkg/golinters/revive/revive.go b/pkg/golinters/revive/revive.go index bce6bcfdb224..c957d953e0e7 100644 --- a/pkg/golinters/revive/revive.go +++ b/pkg/golinters/revive/revive.go @@ -9,6 +9,7 @@ import ( "os" "reflect" "sort" + "strings" "sync" "github.com/BurntSushi/toml" @@ -95,6 +96,8 @@ func newWrapper(settings *config.ReviveSettings) (*wrapper, error) { return nil, err } + displayRules(conf) + conf.GoVersion, err = hcversion.NewVersion(settings.Go) if err != nil { return nil, err @@ -232,25 +235,14 @@ func getConfig(cfg *config.ReviveSettings) (*lint.Config, error) { normalizeConfig(conf) - rulesEnabledByConfig := []string{} for k, r := range conf.Rules { err := r.Initialize() if err != nil { return nil, fmt.Errorf("error in config of rule %q: %w", k, err) } conf.Rules[k] = r - - if !r.Disabled { - rulesEnabledByConfig = append(rulesEnabledByConfig, k) - } } - debugChecksListf(extractRulesName(allRules), "All available analyzers") - debugChecksListf(extractRulesName(defaultRules), "Default analyzers") - debugChecksListf(rulesEnabledByConfig, "Enabled by config analyzers") - - debugf("revive configuration: %#v", conf) - return conf, nil } @@ -461,19 +453,35 @@ func defaultConfig() *lint.Config { return &defaultConfig } +func displayRules(conf *lint.Config) { + if !isDebug { + return + } + + var enabledRules []string + for k, r := range conf.Rules { + if !r.Disabled { + enabledRules = append(enabledRules, k) + } + } + + sort.Strings(enabledRules) + + debugf("All available rules (%d): %s.", len(allRules), strings.Join(extractRulesName(allRules), ", ")) + debugf("Default rules (%d): %s.", len(allRules), strings.Join(extractRulesName(allRules), ", ")) + debugf("Enabled by config rules (%d): %s.", len(enabledRules), strings.Join(enabledRules, ", ")) + + debugf("revive configuration: %#v", conf) +} + func extractRulesName(rules []lint.Rule) []string { - names := []string{} + var names []string + for _, r := range rules { names = append(names, r.Name()) } - return names -} -func debugChecksListf(checks []string, format string, args ...any) { - if !isDebug { - return - } - sort.Strings(checks) + sort.Strings(names) - debugf("%s checks (%d): %s", fmt.Sprintf(format, args...), len(checks), fmt.Sprint(checks)) + return names } From 9c270ed1570c78772f3cb00ad2822476b8a666c7 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 15 Jan 2025 16:09:58 +0100 Subject: [PATCH 3/5] review --- .golangci.next.reference.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index c8ffc45edfca..aeda8070e4ae 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -2371,7 +2371,7 @@ linters-settings: # This means that linting errors with less than 0.8 confidence will be ignored. # Default: 0.8 confidence: 0.1 - + # Run `GL_DEBUG=revive golangci-lint run --enable-only=revive` to see default, all available rules, and enabled rules. rules: # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#add-constant - name: add-constant From 2f56030972d78f027229261366eb150baf15fb65 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 15 Jan 2025 16:30:36 +0100 Subject: [PATCH 4/5] review: 1ns optimization --- pkg/golinters/revive/revive.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/golinters/revive/revive.go b/pkg/golinters/revive/revive.go index c957d953e0e7..feac8532fdb5 100644 --- a/pkg/golinters/revive/revive.go +++ b/pkg/golinters/revive/revive.go @@ -8,6 +8,7 @@ import ( "go/token" "os" "reflect" + "slices" "sort" "strings" "sync" @@ -481,7 +482,7 @@ func extractRulesName(rules []lint.Rule) []string { names = append(names, r.Name()) } - sort.Strings(names) + slices.Sort(names) return names } From 6ea3bf81c3643eeda9988e60a1c3c6886e7a183a Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 15 Jan 2025 16:37:01 +0100 Subject: [PATCH 5/5] review: 1ns optimization --- pkg/golinters/revive/revive.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/golinters/revive/revive.go b/pkg/golinters/revive/revive.go index feac8532fdb5..00b5c8c417e6 100644 --- a/pkg/golinters/revive/revive.go +++ b/pkg/golinters/revive/revive.go @@ -9,7 +9,6 @@ import ( "os" "reflect" "slices" - "sort" "strings" "sync" @@ -466,7 +465,7 @@ func displayRules(conf *lint.Config) { } } - sort.Strings(enabledRules) + slices.Sort(enabledRules) debugf("All available rules (%d): %s.", len(allRules), strings.Join(extractRulesName(allRules), ", ")) debugf("Default rules (%d): %s.", len(allRules), strings.Join(extractRulesName(allRules), ", "))