Skip to content

Commit

Permalink
lowercase in error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
mfederowicz committed Dec 8, 2024
1 parent 3191797 commit f6c7ee0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions rule/enforce_repeated_arg_type_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (r *EnforceRepeatedArgTypeStyleRule) configure(arguments lint.Arguments) er
case "funcArgStyle":
val, ok := v.(string)
if !ok {
return fmt.Errorf("Invalid map value type for 'enforce-repeated-arg-type-style' rule. Expecting string, got %T", v)
return fmt.Errorf("invalid map value type for 'enforce-repeated-arg-type-style' rule. Expecting string, got %T", v)
}
valstyle, err := repeatedArgTypeStyleFromString(val)
if err != nil {
Expand All @@ -83,15 +83,15 @@ func (r *EnforceRepeatedArgTypeStyleRule) configure(arguments lint.Arguments) er
case "funcRetValStyle":
val, ok := v.(string)
if !ok {
return fmt.Errorf("Invalid map value '%v' for 'enforce-repeated-arg-type-style' rule. Expecting string, got %T", v, v)
return fmt.Errorf("invalid map value '%v' for 'enforce-repeated-arg-type-style' rule. Expecting string, got %T", v, v)
}
argstyle, err := repeatedArgTypeStyleFromString(val)
if err != nil {
return err
}
r.funcRetValStyle = argstyle
default:
return fmt.Errorf("Invalid map key for 'enforce-repeated-arg-type-style' rule. Expecting 'funcArgStyle' or 'funcRetValStyle', got %v", k)
return fmt.Errorf("invalid map key for 'enforce-repeated-arg-type-style' rule. Expecting 'funcArgStyle' or 'funcRetValStyle', got %v", k)
}
}
default:
Expand Down
2 changes: 1 addition & 1 deletion rule/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (r *ExportedRule) configure(arguments lint.Arguments) error {
case "disableChecksOnVariables":
r.disabledChecks.Var = true
default:
return fmt.Errorf("Unknown configuration flag %s for %s rule", flag, r.Name())
return fmt.Errorf("unknown configuration flag %s for %s rule", flag, r.Name())
}
default:
return fmt.Errorf("invalid argument for the %s rule: expecting a string, got %T", r.Name(), flag)
Expand Down
2 changes: 1 addition & 1 deletion rule/import_alias_naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (r *ImportAliasNamingRule) configure(arguments lint.Arguments) error {
}

default:
return fmt.Errorf("Invalid map key for 'import-alias-naming' rule. Expecting 'allowRegex' or 'denyRegex', got %v", k)
return fmt.Errorf("invalid map key for 'import-alias-naming' rule. Expecting 'allowRegex' or 'denyRegex', got %v", k)
}
}
default:
Expand Down
6 changes: 3 additions & 3 deletions rule/receiver_naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ func (r *ReceiverNamingRule) configure(arguments lint.Arguments) error {

args, ok := arguments[0].(map[string]any)
if !ok {
return fmt.Errorf("Unable to get arguments for rule %s. Expected object of key-value-pairs", r.Name())
return fmt.Errorf("unable to get arguments for rule %s. Expected object of key-value-pairs", r.Name())
}

for k, v := range args {
switch k {
case "maxLength":
value, ok := v.(int64)
if !ok {
return fmt.Errorf("Invalid value %v for argument %s of rule %s, expected integer value got %T", v, k, r.Name(), v)
return fmt.Errorf("invalid value %v for argument %s of rule %s, expected integer value got %T", v, k, r.Name(), v)
}
r.receiverNameMaxLength = int(value)
default:
return fmt.Errorf("Unknown argument %s for %s rule", k, r.Name())
return fmt.Errorf("unknown argument %s for %s rule", k, r.Name())
}
}
return nil
Expand Down
42 changes: 21 additions & 21 deletions rule/unchecked_type_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,39 @@ const (
ruleUTAMessageIgnored = "type assertion result ignored"
)

// UncheckedTypeAssertionRule lints missing or ignored `ok`-value in dynamic type casts.
type UncheckedTypeAssertionRule struct {
// uncheckedTypeAssertionRule lints missing or ignored `ok`-value in dynamic type casts.
type uncheckedTypeAssertionRule struct {
acceptIgnoredAssertionResult bool

configureOnce sync.Once
}

func (r *UncheckedTypeAssertionRule) configure(arguments lint.Arguments) error {
func (r *uncheckedTypeAssertionRule) configure(arguments lint.Arguments) error {
if len(arguments) == 0 {
return nil
}

args, ok := arguments[0].(map[string]any)
if !ok {
return errors.New("Unable to get arguments. Expected object of key-value-pairs")
return errors.New("unable to get arguments. Expected object of key-value-pairs")
}

for k, v := range args {
switch k {
case "acceptIgnoredAssertionResult":
r.acceptIgnoredAssertionResult, ok = v.(bool)
if !ok {
return fmt.Errorf("Unable to parse argument '%s'. Expected boolean", k)
return fmt.Errorf("unable to parse argument '%s'. Expected boolean", k)
}
default:
return fmt.Errorf("Unknown argument: %s", k)
return fmt.Errorf("unknown argument: %s", k)
}
}
return nil
}

// Apply applies the rule to given file.
func (r *UncheckedTypeAssertionRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
func (r *uncheckedTypeAssertionRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
var configureErr error
r.configureOnce.Do(func() { configureErr = r.configure(arguments) })

Expand All @@ -56,7 +56,7 @@ func (r *UncheckedTypeAssertionRule) Apply(file *lint.File, arguments lint.Argum

var failures []lint.Failure

walker := &lintUncheckedTypeAssertion{
walker := &lintuncheckedTypeAssertion{
onFailure: func(failure lint.Failure) {
failures = append(failures, failure)
},
Expand All @@ -69,11 +69,11 @@ func (r *UncheckedTypeAssertionRule) Apply(file *lint.File, arguments lint.Argum
}

// Name returns the rule name.
func (*UncheckedTypeAssertionRule) Name() string {
func (*uncheckedTypeAssertionRule) Name() string {
return "unchecked-type-assertion"
}

type lintUncheckedTypeAssertion struct {
type lintuncheckedTypeAssertion struct {
onFailure func(lint.Failure)
acceptIgnoredTypeAssertionResult bool
}
Expand All @@ -91,42 +91,42 @@ func isTypeSwitch(e *ast.TypeAssertExpr) bool {
return e.Type == nil
}

func (w *lintUncheckedTypeAssertion) requireNoTypeAssert(expr ast.Expr) {
func (w *lintuncheckedTypeAssertion) requireNoTypeAssert(expr ast.Expr) {
e, ok := expr.(*ast.TypeAssertExpr)
if ok && !isTypeSwitch(e) {
w.addFailure(e, ruleUTAMessagePanic)
}
}

func (w *lintUncheckedTypeAssertion) handleIfStmt(n *ast.IfStmt) {
func (w *lintuncheckedTypeAssertion) handleIfStmt(n *ast.IfStmt) {
ifCondition, ok := n.Cond.(*ast.BinaryExpr)
if ok {
w.requireNoTypeAssert(ifCondition.X)
w.requireNoTypeAssert(ifCondition.Y)
}
}

func (w *lintUncheckedTypeAssertion) requireBinaryExpressionWithoutTypeAssertion(expr ast.Expr) {
func (w *lintuncheckedTypeAssertion) requireBinaryExpressionWithoutTypeAssertion(expr ast.Expr) {
binaryExpr, ok := expr.(*ast.BinaryExpr)
if ok {
w.requireNoTypeAssert(binaryExpr.X)
w.requireNoTypeAssert(binaryExpr.Y)
}
}

func (w *lintUncheckedTypeAssertion) handleCaseClause(n *ast.CaseClause) {
func (w *lintuncheckedTypeAssertion) handleCaseClause(n *ast.CaseClause) {
for _, expr := range n.List {
w.requireNoTypeAssert(expr)
w.requireBinaryExpressionWithoutTypeAssertion(expr)
}
}

func (w *lintUncheckedTypeAssertion) handleSwitch(n *ast.SwitchStmt) {
func (w *lintuncheckedTypeAssertion) handleSwitch(n *ast.SwitchStmt) {
w.requireNoTypeAssert(n.Tag)
w.requireBinaryExpressionWithoutTypeAssertion(n.Tag)
}

func (w *lintUncheckedTypeAssertion) handleAssignment(n *ast.AssignStmt) {
func (w *lintuncheckedTypeAssertion) handleAssignment(n *ast.AssignStmt) {
if len(n.Rhs) == 0 {
return
}
Expand All @@ -150,21 +150,21 @@ func (w *lintUncheckedTypeAssertion) handleAssignment(n *ast.AssignStmt) {
}

// handles "return foo(.*bar)" - one of them is enough to fail as golang does not forward the type cast tuples in return statements
func (w *lintUncheckedTypeAssertion) handleReturn(n *ast.ReturnStmt) {
func (w *lintuncheckedTypeAssertion) handleReturn(n *ast.ReturnStmt) {
for _, r := range n.Results {
w.requireNoTypeAssert(r)
}
}

func (w *lintUncheckedTypeAssertion) handleRange(n *ast.RangeStmt) {
func (w *lintuncheckedTypeAssertion) handleRange(n *ast.RangeStmt) {
w.requireNoTypeAssert(n.X)
}

func (w *lintUncheckedTypeAssertion) handleChannelSend(n *ast.SendStmt) {
func (w *lintuncheckedTypeAssertion) handleChannelSend(n *ast.SendStmt) {
w.requireNoTypeAssert(n.Value)
}

func (w *lintUncheckedTypeAssertion) Visit(node ast.Node) ast.Visitor {
func (w *lintuncheckedTypeAssertion) Visit(node ast.Node) ast.Visitor {
switch n := node.(type) {
case *ast.RangeStmt:
w.handleRange(n)
Expand All @@ -185,7 +185,7 @@ func (w *lintUncheckedTypeAssertion) Visit(node ast.Node) ast.Visitor {
return w
}

func (w *lintUncheckedTypeAssertion) addFailure(n *ast.TypeAssertExpr, why string) {
func (w *lintuncheckedTypeAssertion) addFailure(n *ast.TypeAssertExpr, why string) {
s := fmt.Sprintf("type cast result is unchecked in %v - %s", gofmt(n), why)
w.onFailure(lint.Failure{
Category: "bad practice",
Expand Down
8 changes: 4 additions & 4 deletions rule/var_naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ func (r *VarNamingRule) configure(arguments lint.Arguments) error {
thirdArgument := arguments[2]
asSlice, ok := thirdArgument.([]any)
if !ok {
return fmt.Errorf("Invalid third argument to the var-naming rule. Expecting a %s of type slice, got %T", "options", arguments[2])
return fmt.Errorf("invalid third argument to the var-naming rule. Expecting a %s of type slice, got %T", "options", arguments[2])
}
if len(asSlice) != 1 {
return fmt.Errorf("Invalid third argument to the var-naming rule. Expecting a %s of type slice, of len==1, but %d", "options", len(asSlice))
return fmt.Errorf("invalid third argument to the var-naming rule. Expecting a %s of type slice, of len==1, but %d", "options", len(asSlice))
}
args, ok := asSlice[0].(map[string]any)
if !ok {
return fmt.Errorf("Invalid third argument to the var-naming rule. Expecting a %s of type slice, of len==1, with map, but %T", "options", asSlice[0])
return fmt.Errorf("invalid third argument to the var-naming rule. Expecting a %s of type slice, of len==1, with map, but %T", "options", asSlice[0])
}
r.allowUpperCaseConst = fmt.Sprint(args["upperCaseConst"]) == "true"
r.skipPackageNameChecks = fmt.Sprint(args["skipPackageNameChecks"]) == "true"
Expand Down Expand Up @@ -286,7 +286,7 @@ func getList(arg any, argName string) ([]string, error) {
for _, v := range args {
val, ok := v.(string)
if !ok {
return nil, fmt.Errorf("Invalid %s values of the var-naming rule. Expecting slice of strings but got element of type %T", val, arg)
return nil, fmt.Errorf("invalid %s values of the var-naming rule. Expecting slice of strings but got element of type %T", val, arg)
}
list = append(list, val)
}
Expand Down

0 comments on commit f6c7ee0

Please sign in to comment.