Skip to content
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
23 changes: 23 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,12 @@ linters:
# Default: false
enable-all-rules: true

# By default, the default rules are enabled,
# but if you provide a custom configuration, the default rules will be disabled.
# This option allows you to not explicitly enable the default rules.
# Default: false
enable-default-rules: true

# Enable validation of comment directives.
# See https://github.com/mgechev/revive#comment-directives
directives:
Expand Down Expand Up @@ -2644,6 +2650,11 @@ linters:
severity: warning
disabled: false
exclude: [""]
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#forbidden-call-in-wg-go
- name: forbidden-call-in-wg-go
severity: warning
disabled: false
exclude: [""]
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#function-length
- name: function-length
severity: warning
Expand Down Expand Up @@ -2726,6 +2737,11 @@ linters:
exclude: [""]
arguments:
- "preserve-scope"
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#inefficient-map-lookup
- name: inefficient-map-lookup
severity: warning
disabled: false
exclude: [""]
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#line-length-limit
- name: line-length-limit
severity: warning
Expand Down Expand Up @@ -2844,6 +2860,7 @@ linters:
disabled: false
exclude: [""]
arguments:
- "!validate"
- "json,inline"
- "bson,outline,gnu"
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#superfluous-else
Expand Down Expand Up @@ -2903,6 +2920,11 @@ linters:
severity: warning
disabled: false
exclude: [""]
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#unnecessary-if
- name: unnecessary-if
severity: warning
disabled: false
exclude: [""]
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#unnecessary-stmt
- name: unnecessary-stmt
severity: warning
Expand Down Expand Up @@ -2978,6 +3000,7 @@ linters:
- - skip-initialism-name-checks: true
upper-case-const: true
skip-package-name-checks: true
skip-package-name-collision-with-go-std: true
extra-bad-package-names:
- helpers
- models
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ require (
github.com/maratori/testpackage v1.1.2
github.com/matoous/godox v1.1.0
github.com/mattn/go-colorable v0.1.14
github.com/mgechev/revive v1.12.0
github.com/mgechev/revive v1.13.0
github.com/mitchellh/go-homedir v1.1.0
github.com/moricho/tparallel v0.3.2
github.com/nakabonne/nestif v0.3.1
Expand Down Expand Up @@ -204,7 +204,7 @@ require (
github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/afero v1.14.0 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum

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

7 changes: 7 additions & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@
"file-length-limit",
"filename-format",
"flag-parameter",
"forbidden-call-in-wg-go",
"function-length",
"function-result-limit",
"get-return",
Expand All @@ -636,6 +637,7 @@
"imports-blocklist",
"increment-decrement",
"indent-error-flow",
"inefficient-map-lookup",
"line-length-limit",
"max-control-nesting",
"max-public-structs",
Expand Down Expand Up @@ -666,6 +668,7 @@
"unexported-return",
"unhandled-error",
"unnecessary-format",
"unnecessary-if",
"unnecessary-stmt",
"unreachable-code",
"unsecure-url-scheme",
Expand Down Expand Up @@ -3159,6 +3162,10 @@
"type": "boolean",
"default": false
},
"enable-default-rules": {
"type": "boolean",
"default": false
},
"directives": {
"type": "array",
"items": {
Expand Down
19 changes: 10 additions & 9 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,15 +834,16 @@ type RecvcheckSettings struct {
}

type ReviveSettings struct {
Go string `mapstructure:"-"`
MaxOpenFiles int `mapstructure:"max-open-files"`
Confidence float64 `mapstructure:"confidence"`
Severity string `mapstructure:"severity"`
EnableAllRules bool `mapstructure:"enable-all-rules"`
Rules []ReviveRule `mapstructure:"rules"`
ErrorCode int `mapstructure:"error-code"`
WarningCode int `mapstructure:"warning-code"`
Directives []ReviveDirective `mapstructure:"directives"`
Go string `mapstructure:"-"`
MaxOpenFiles int `mapstructure:"max-open-files"`
Confidence float64 `mapstructure:"confidence"`
Severity string `mapstructure:"severity"`
EnableAllRules bool `mapstructure:"enable-all-rules"`
EnableDefaultRules bool `mapstructure:"enable-default-rules"`
Rules []ReviveRule `mapstructure:"rules"`
ErrorCode int `mapstructure:"error-code"`
WarningCode int `mapstructure:"warning-code"`
Directives []ReviveDirective `mapstructure:"directives"`
}

type ReviveRule struct {
Expand Down
34 changes: 20 additions & 14 deletions pkg/golinters/revive/revive.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ func (w *wrapper) toIssue(pass *analysis.Pass, failure *lint.Failure) *goanalysi
// This function mimics the GetConfig function of revive.
// This allows to get default values and right types.
// https://github.com/golangci/golangci-lint/issues/1745
// https://github.com/mgechev/revive/blob/v1.6.0/config/config.go#L230
// https://github.com/mgechev/revive/blob/v1.6.0/config/config.go#L182-L188
// https://github.com/mgechev/revive/blob/v1.13.0/config/config.go#L249
// https://github.com/mgechev/revive/blob/v1.13.0/config/config.go#L198-L204
func getConfig(cfg *config.ReviveSettings) (*lint.Config, error) {
conf := defaultConfig()

Expand Down Expand Up @@ -269,7 +269,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.12.0/config/config.go#L16
// Extracted from https://github.com/mgechev/revive/blob/v1.13.0/config/config.go#L16
var defaultRules = []lint.Rule{
&rule.VarDeclarationsRule{},
&rule.PackageCommentsRule{},
Expand Down Expand Up @@ -325,6 +325,7 @@ var allRules = append([]lint.Rule{
&rule.FileLengthLimitRule{},
&rule.FilenameFormatRule{},
&rule.FlagParamRule{},
&rule.ForbiddenCallInWgGoRule{},
&rule.FunctionLength{},
&rule.FunctionResultsLimitRule{},
&rule.GetReturnRule{},
Expand All @@ -337,6 +338,7 @@ var allRules = append([]lint.Rule{
&rule.ImportAliasNamingRule{},
&rule.ImportsBlocklistRule{},
&rule.ImportShadowingRule{},
&rule.InefficientMapLookupRule{},
&rule.LineLengthLimitRule{},
&rule.MaxControlNestingRule{},
&rule.MaxPublicStructsRule{},
Expand All @@ -360,6 +362,7 @@ var allRules = append([]lint.Rule{
&rule.UnexportedNamingRule{},
&rule.UnhandledErrorRule{},
&rule.UnnecessaryFormatRule{},
&rule.UnnecessaryIfRule{},
&rule.UnnecessaryStmtRule{},
&rule.UnsecureURLSchemeRule{},
&rule.UnusedReceiverRule{},
Expand All @@ -375,7 +378,7 @@ var allRules = append([]lint.Rule{
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.12.0/config/config.go#L206
// Extracted from https://github.com/mgechev/revive/blob/v1.13.0/config/config.go#L209
func normalizeConfig(cfg *lint.Config) {
// NOTE(ldez): this custom section for golangci-lint should be kept.
// ---
Expand All @@ -386,19 +389,22 @@ func normalizeConfig(cfg *lint.Config) {
if len(cfg.Rules) == 0 {
cfg.Rules = map[string]lint.RuleConfig{}
}
if cfg.EnableAllRules {
// Add to the configuration all rules not yet present in it
for _, r := range allRules {

addRules := func(config *lint.Config, rules []lint.Rule) {
for _, r := range rules {
ruleName := r.Name()
_, alreadyInConf := cfg.Rules[ruleName]
if alreadyInConf {
continue
if _, ok := config.Rules[ruleName]; !ok {
config.Rules[ruleName] = lint.RuleConfig{}
}
// Add the rule with an empty conf for
cfg.Rules[ruleName] = lint.RuleConfig{}
}
}

if cfg.EnableAllRules {
addRules(cfg, allRules)
} else if cfg.EnableDefaultRules {
addRules(cfg, defaultRules)
}

severity := cfg.Severity
if severity != "" {
for k, v := range cfg.Rules {
Expand All @@ -417,7 +423,7 @@ func normalizeConfig(cfg *lint.Config) {
}

// This element is not exported by revive, so we need copy the code.
// Extracted from https://github.com/mgechev/revive/blob/v1.12.0/config/config.go#L274
// Extracted from https://github.com/mgechev/revive/blob/v1.13.0/config/config.go#L280
func defaultConfig() *lint.Config {
defaultConfig := lint.Config{
Confidence: defaultConfidence,
Expand Down Expand Up @@ -463,7 +469,7 @@ func extractRulesName(rules []lint.Rule) []string {
return names
}

// Extracted from https://github.com/mgechev/revive/blob/v1.12.0/formatter/severity.go
// Extracted from https://github.com/mgechev/revive/blob/v1.13.0/formatter/severity.go
// Modified to use pointers (related to hugeParam rule).
func severity(cfg *lint.Config, failure *lint.Failure) lint.Severity {
if cfg, ok := cfg.Rules[failure.RuleName]; ok && cfg.Severity == lint.SeverityError {
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/unsafe/pkg.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package pkg ...
package pkg
// Package pkgunsafe ...
package pkgunsafe

import (
"log"
Expand Down
Loading