diff --git a/rule/enforce_repeated_arg_type_style.go b/rule/enforce_repeated_arg_type_style.go index d03db6b81..25f9cdf2d 100644 --- a/rule/enforce_repeated_arg_type_style.go +++ b/rule/enforce_repeated_arg_type_style.go @@ -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 { @@ -83,7 +83,7 @@ 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 { @@ -91,7 +91,7 @@ func (r *EnforceRepeatedArgTypeStyleRule) configure(arguments lint.Arguments) er } 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: diff --git a/rule/exported.go b/rule/exported.go index 39929cbec..87bdd4e20 100644 --- a/rule/exported.go +++ b/rule/exported.go @@ -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) diff --git a/rule/import_alias_naming.go b/rule/import_alias_naming.go index ab5563cb0..43bf9d545 100644 --- a/rule/import_alias_naming.go +++ b/rule/import_alias_naming.go @@ -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: diff --git a/rule/receiver_naming.go b/rule/receiver_naming.go index 0dd415b72..54eee4eff 100644 --- a/rule/receiver_naming.go +++ b/rule/receiver_naming.go @@ -26,7 +26,7 @@ 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 { @@ -34,11 +34,11 @@ func (r *ReceiverNamingRule) configure(arguments lint.Arguments) error { 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 diff --git a/rule/unchecked_type_assertion.go b/rule/unchecked_type_assertion.go index dc14afc47..2f25a9a95 100644 --- a/rule/unchecked_type_assertion.go +++ b/rule/unchecked_type_assertion.go @@ -14,21 +14,21 @@ 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 { @@ -36,17 +36,17 @@ func (r *UncheckedTypeAssertionRule) configure(arguments lint.Arguments) error { 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) }) @@ -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) }, @@ -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 } @@ -91,14 +91,14 @@ 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) @@ -106,7 +106,7 @@ func (w *lintUncheckedTypeAssertion) handleIfStmt(n *ast.IfStmt) { } } -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) @@ -114,19 +114,19 @@ func (w *lintUncheckedTypeAssertion) requireBinaryExpressionWithoutTypeAssertion } } -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 } @@ -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) @@ -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", diff --git a/rule/var_naming.go b/rule/var_naming.go index a8e15756c..5d3bf1ad7 100644 --- a/rule/var_naming.go +++ b/rule/var_naming.go @@ -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" @@ -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) }