1
0
mirror of https://github.com/mgechev/revive.git synced 2025-11-23 22:04:49 +02:00

refactor: remove unused checkNumberOfArguments (#1581)

This commit is contained in:
Oleksandr Redko
2025-11-15 19:35:57 +02:00
committed by GitHub
parent 6ff1fc5f12
commit d1dd6ee961
6 changed files with 1 additions and 28 deletions

View File

@@ -18,6 +18,7 @@ linters:
- revive - revive
- thelper - thelper
- staticcheck - staticcheck
- unparam
- unused - unused
exclusions: exclusions:

View File

@@ -20,10 +20,6 @@ const bannedCharsRuleName = "banned-characters"
// Configuration implements the [lint.ConfigurableRule] interface. // Configuration implements the [lint.ConfigurableRule] interface.
func (r *BannedCharsRule) Configure(arguments lint.Arguments) error { func (r *BannedCharsRule) Configure(arguments lint.Arguments) error {
if len(arguments) > 0 { if len(arguments) > 0 {
err := checkNumberOfArguments(1, arguments, bannedCharsRuleName)
if err != nil {
return err
}
list, err := r.getBannedCharsList(arguments) list, err := r.getBannedCharsList(arguments)
if err != nil { if err != nil {
return err return err

View File

@@ -112,11 +112,6 @@ func (r *MaxControlNestingRule) Configure(arguments lint.Arguments) error {
return nil return nil
} }
check := checkNumberOfArguments(1, arguments, r.Name())
if check != nil {
return check
}
maxNesting, ok := arguments[0].(int64) // Alt. non panicking version maxNesting, ok := arguments[0].(int64) // Alt. non panicking version
if !ok { if !ok {
return errors.New(`invalid value passed as argument number to the "max-control-nesting" rule`) return errors.New(`invalid value passed as argument number to the "max-control-nesting" rule`)

View File

@@ -25,11 +25,6 @@ func (r *MaxPublicStructsRule) Configure(arguments lint.Arguments) error {
return nil return nil
} }
err := checkNumberOfArguments(1, arguments, r.Name())
if err != nil {
return err
}
maxStructs, ok := arguments[0].(int64) // Alt. non panicking version maxStructs, ok := arguments[0].(int64) // Alt. non panicking version
if !ok { if !ok {
return errors.New(`invalid value passed as argument number to the "max-public-structs" rule`) return errors.New(`invalid value passed as argument number to the "max-public-structs" rule`)

View File

@@ -105,11 +105,6 @@ func (r *StructTagRule) Configure(arguments lint.Arguments) error {
return nil return nil
} }
err := checkNumberOfArguments(1, arguments, r.Name())
if err != nil {
return err
}
r.userDefined = map[tagKey][]string{} r.userDefined = map[tagKey][]string{}
r.omittedTags = map[tagKey]struct{}{} r.omittedTags = map[tagKey]struct{}{}
for _, arg := range arguments { for _, arg := range arguments {

View File

@@ -1,7 +1,6 @@
package rule package rule
import ( import (
"fmt"
"go/ast" "go/ast"
"go/token" "go/token"
"regexp" "regexp"
@@ -51,14 +50,6 @@ func srcLine(src []byte, p token.Position) string {
return string(src[lo:hi]) return string(src[lo:hi])
} }
// checkNumberOfArguments fails if the given number of arguments is not, at least, the expected one.
func checkNumberOfArguments(expected int, args lint.Arguments, ruleName string) error {
if len(args) < expected {
return fmt.Errorf("not enough arguments for %s rule, expected %d, got %d. Please check the rule's documentation", ruleName, expected, len(args))
}
return nil
}
// isRuleOption returns true if arg and name are the same after normalization. // isRuleOption returns true if arg and name are the same after normalization.
func isRuleOption(arg, name string) bool { func isRuleOption(arg, name string) bool {
return normalizeRuleOption(arg) == normalizeRuleOption(name) return normalizeRuleOption(arg) == normalizeRuleOption(name)