diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index b973f866d2a8..8ea0db6d8d86 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -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: @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/go.mod b/go.mod index 59b1f3a425e8..d92e2aa46fb1 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 8bb3d2460788..9d289bb4ef30 100644 --- a/go.sum +++ b/go.sum @@ -424,8 +424,8 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 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.12.0 h1:Q+/kkbbwerrVYPv9d9efaPGmAO/NsxwW/nE6ahpQaCU= -github.com/mgechev/revive v1.12.0/go.mod h1:VXsY2LsTigk8XU9BpZauVLjVrhICMOV3k1lpB3CXrp8= +github.com/mgechev/revive v1.13.0 h1:yFbEVliCVKRXY8UgwEO7EOYNopvjb1BFbmYqm9hZjBM= +github.com/mgechev/revive v1.13.0/go.mod h1:efJfeBVCX2JUumNQ7dtOLDja+QKj9mYGgEZA7rt5u+0= 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/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -547,8 +547,8 @@ github.com/sonatard/noctx v0.4.0 h1:7MC/5Gg4SQ4lhLYR6mvOP6mQVSxCrdyiExo7atBs27o= github.com/sonatard/noctx v0.4.0/go.mod h1:64XdbzFb18XL4LporKXp8poqZtPKbCrqQ402CV+kJas= github.com/sourcegraph/go-diff v0.7.0 h1:9uLlrd5T46OXs5qpp8L/MTltk0zikUGi0sNNyCpA8G0= github.com/sourcegraph/go-diff v0.7.0/go.mod h1:iBszgVvyxdc8SFZ7gm69go2KDdt3ag071iBaWPF6cjs= -github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA= -github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo= +github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= +github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 459f5d5775da..39a8045eaefa 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -622,6 +622,7 @@ "file-length-limit", "filename-format", "flag-parameter", + "forbidden-call-in-wg-go", "function-length", "function-result-limit", "get-return", @@ -636,6 +637,7 @@ "imports-blocklist", "increment-decrement", "indent-error-flow", + "inefficient-map-lookup", "line-length-limit", "max-control-nesting", "max-public-structs", @@ -666,6 +668,7 @@ "unexported-return", "unhandled-error", "unnecessary-format", + "unnecessary-if", "unnecessary-stmt", "unreachable-code", "unsecure-url-scheme", @@ -3159,6 +3162,10 @@ "type": "boolean", "default": false }, + "enable-default-rules": { + "type": "boolean", + "default": false + }, "directives": { "type": "array", "items": { diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index ba60dd2c63ce..fefa94ca397b 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -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 { diff --git a/pkg/golinters/revive/revive.go b/pkg/golinters/revive/revive.go index 8e5a7835defc..6799e1a4283f 100644 --- a/pkg/golinters/revive/revive.go +++ b/pkg/golinters/revive/revive.go @@ -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() @@ -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{}, @@ -325,6 +325,7 @@ var allRules = append([]lint.Rule{ &rule.FileLengthLimitRule{}, &rule.FilenameFormatRule{}, &rule.FlagParamRule{}, + &rule.ForbiddenCallInWgGoRule{}, &rule.FunctionLength{}, &rule.FunctionResultsLimitRule{}, &rule.GetReturnRule{}, @@ -337,6 +338,7 @@ var allRules = append([]lint.Rule{ &rule.ImportAliasNamingRule{}, &rule.ImportsBlocklistRule{}, &rule.ImportShadowingRule{}, + &rule.InefficientMapLookupRule{}, &rule.LineLengthLimitRule{}, &rule.MaxControlNestingRule{}, &rule.MaxPublicStructsRule{}, @@ -360,6 +362,7 @@ var allRules = append([]lint.Rule{ &rule.UnexportedNamingRule{}, &rule.UnhandledErrorRule{}, &rule.UnnecessaryFormatRule{}, + &rule.UnnecessaryIfRule{}, &rule.UnnecessaryStmtRule{}, &rule.UnsecureURLSchemeRule{}, &rule.UnusedReceiverRule{}, @@ -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. // --- @@ -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 { @@ -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, @@ -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 { diff --git a/test/testdata/unsafe/pkg.go b/test/testdata/unsafe/pkg.go index 1df14f16923b..70f9b4caac2a 100644 --- a/test/testdata/unsafe/pkg.go +++ b/test/testdata/unsafe/pkg.go @@ -1,5 +1,5 @@ -// Package pkg ... -package pkg +// Package pkgunsafe ... +package pkgunsafe import ( "log"