diff --git a/.golangci.yaml b/.golangci.yaml index fa4be358c0..8823e469bd 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,6 +1,9 @@ run: timeout: 5m +issues: + max-same-issues: 0 # don't hide issues in CI runs because they are the same type + linter-settings: lll: line-length: 200 diff --git a/Makefile b/Makefile index f11f569e37..cff542a0c2 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ ifeq ($(WASM_ENABLED),1) GO_TAGS = -tags=opa_wasm endif -GOLANGCI_LINT_VERSION := v1.59.1 +GOLANGCI_LINT_VERSION := v1.60.1 YAML_LINT_VERSION := 0.29.0 YAML_LINT_FORMAT ?= auto diff --git a/ast/check.go b/ast/check.go index 03d31123cf..ea0089df91 100644 --- a/ast/check.go +++ b/ast/check.go @@ -293,7 +293,7 @@ func (tc *typeChecker) checkRule(env *TypeEnv, as *AnnotationSet, rule *Rule) { var err error tpe, err = nestedObject(cpy, objPath, typeV) if err != nil { - tc.err([]*Error{NewError(TypeErr, rule.Head.Location, err.Error())}) + tc.err([]*Error{NewError(TypeErr, rule.Head.Location, err.Error())}) //nolint:govet tpe = nil } } else { @@ -1310,7 +1310,7 @@ func processAnnotation(ss *SchemaSet, annot *SchemaAnnotation, rule *Rule, allow tpe, err := loadSchema(schema, allowNet) if err != nil { - return nil, NewError(TypeErr, rule.Location, err.Error()) + return nil, NewError(TypeErr, rule.Location, err.Error()) //nolint:govet } return tpe, nil diff --git a/ast/compile.go b/ast/compile.go index 014a720ab0..b26490f193 100644 --- a/ast/compile.go +++ b/ast/compile.go @@ -840,7 +840,7 @@ func (c *Compiler) PassesTypeCheckRules(rules []*Rule) Errors { tpe, err := loadSchema(schema, allowNet) if err != nil { - return Errors{NewError(TypeErr, nil, err.Error())} + return Errors{NewError(TypeErr, nil, err.Error())} //nolint:govet } c.inputType = tpe } @@ -1171,7 +1171,7 @@ func (c *Compiler) checkRuleConflicts() { continue // don't self-conflict } msg := fmt.Sprintf("%v conflicts with rule %v defined at %v", childMod.Package, rule.Head.Ref(), rule.Loc()) - c.err(NewError(TypeErr, mod.Package.Loc(), msg)) + c.err(NewError(TypeErr, mod.Package.Loc(), msg)) //nolint:govet } } } @@ -1652,7 +1652,7 @@ func (c *Compiler) init() { if schema := c.schemaSet.Get(SchemaRootRef); schema != nil { tpe, err := loadSchema(schema, c.capabilities.AllowNet) if err != nil { - c.err(NewError(TypeErr, nil, err.Error())) + c.err(NewError(TypeErr, nil, err.Error())) //nolint:govet } else { c.inputType = tpe } @@ -1774,7 +1774,7 @@ func (c *Compiler) resolveAllRefs() { WalkRules(mod, func(rule *Rule) bool { err := resolveRefsInRule(globals, rule) if err != nil { - c.err(NewError(CompileErr, rule.Location, err.Error())) + c.err(NewError(CompileErr, rule.Location, err.Error())) //nolint:govet } return false }) @@ -1799,7 +1799,7 @@ func (c *Compiler) resolveAllRefs() { parsed, err := c.moduleLoader(c.Modules) if err != nil { - c.err(NewError(CompileErr, nil, err.Error())) + c.err(NewError(CompileErr, nil, err.Error())) //nolint:govet return } @@ -2690,7 +2690,7 @@ func (vis *ruleArgLocalRewriter) Visit(x interface{}) Visitor { Walk(vis, vcpy) return k, vcpy, nil }); err != nil { - vis.errs = append(vis.errs, NewError(CompileErr, t.Location, err.Error())) + vis.errs = append(vis.errs, NewError(CompileErr, t.Location, err.Error())) //nolint:govet } else { t.Value = cpy } @@ -5271,7 +5271,7 @@ func rewriteEveryStatement(g *localVarGenerator, stack *localDeclaredVars, expr if v := every.Key.Value.(Var); !v.IsWildcard() { gv, err := rewriteDeclaredVar(g, stack, v, declaredVar) if err != nil { - return nil, append(errs, NewError(CompileErr, every.Loc(), err.Error())) + return nil, append(errs, NewError(CompileErr, every.Loc(), err.Error())) //nolint:govet } every.Key.Value = gv } @@ -5283,7 +5283,7 @@ func rewriteEveryStatement(g *localVarGenerator, stack *localDeclaredVars, expr if v := every.Value.Value.(Var); !v.IsWildcard() { gv, err := rewriteDeclaredVar(g, stack, v, declaredVar) if err != nil { - return nil, append(errs, NewError(CompileErr, every.Loc(), err.Error())) + return nil, append(errs, NewError(CompileErr, every.Loc(), err.Error())) //nolint:govet } every.Value.Value = gv } @@ -5301,7 +5301,7 @@ func rewriteSomeDeclStatement(g *localVarGenerator, stack *localDeclaredVars, ex switch v := decl.Symbols[i].Value.(type) { case Var: if _, err := rewriteDeclaredVar(g, stack, v, declaredVar); err != nil { - return nil, append(errs, NewError(CompileErr, decl.Loc(), err.Error())) + return nil, append(errs, NewError(CompileErr, decl.Loc(), err.Error())) //nolint:govet } case Call: var key, val, container *Term @@ -5329,7 +5329,7 @@ func rewriteSomeDeclStatement(g *localVarGenerator, stack *localDeclaredVars, ex for _, v0 := range outputVarsForExprEq(e, container.Vars()).Sorted() { if _, err := rewriteDeclaredVar(g, stack, v0, declaredVar); err != nil { - return nil, append(errs, NewError(CompileErr, decl.Loc(), err.Error())) + return nil, append(errs, NewError(CompileErr, decl.Loc(), err.Error())) //nolint:govet } } return rewriteDeclaredVarsInExpr(g, stack, e, errs, strict) @@ -5383,7 +5383,7 @@ func rewriteDeclaredAssignment(g *localVarGenerator, stack *localDeclaredVars, e switch v := t.Value.(type) { case Var: if gv, err := rewriteDeclaredVar(g, stack, v, assignedVar); err != nil { - errs = append(errs, NewError(CompileErr, t.Location, err.Error())) + errs = append(errs, NewError(CompileErr, t.Location, err.Error())) //nolint:govet } else { t.Value = gv } @@ -5398,7 +5398,7 @@ func rewriteDeclaredAssignment(g *localVarGenerator, stack *localDeclaredVars, e case Ref: if RootDocumentRefs.Contains(t) { if gv, err := rewriteDeclaredVar(g, stack, v[0].Value.(Var), assignedVar); err != nil { - errs = append(errs, NewError(CompileErr, t.Location, err.Error())) + errs = append(errs, NewError(CompileErr, t.Location, err.Error())) //nolint:govet } else { t.Value = gv } diff --git a/ast/parser.go b/ast/parser.go index 71ccd2101c..f2a5a24b9b 100644 --- a/ast/parser.go +++ b/ast/parser.go @@ -2094,7 +2094,7 @@ func (p *Parser) genwildcard() string { } func (p *Parser) error(loc *location.Location, reason string) { - p.errorf(loc, reason) + p.errorf(loc, reason) //nolint:govet } func (p *Parser) errorf(loc *location.Location, f string, a ...interface{}) { diff --git a/ast/parser_ext.go b/ast/parser_ext.go index 83c87e47b1..10187a5825 100644 --- a/ast/parser_ext.go +++ b/ast/parser_ext.go @@ -704,7 +704,7 @@ func parseModule(filename string, stmts []Statement, comments []*Comment, regoCo case Body: rule, err := ParseRuleFromBody(mod, stmt) if err != nil { - errs = append(errs, NewError(ParseErr, stmt[0].Location, err.Error())) + errs = append(errs, NewError(ParseErr, stmt[0].Location, err.Error())) //nolint:govet continue } rule.generatedBody = true diff --git a/ast/rego_v1.go b/ast/rego_v1.go index b64dfce7be..488cf45537 100644 --- a/ast/rego_v1.go +++ b/ast/rego_v1.go @@ -192,7 +192,7 @@ func checkRegoV1Rule(rule *Rule, opts RegoCheckOptions) Errors { var errs Errors if opts.NoKeywordsAsRuleNames && IsKeywordInRegoVersion(rule.Head.Name.String(), RegoV1) { - errs = append(errs, NewError(ParseErr, rule.Location, fmt.Sprintf("%s keyword cannot be used for rule name", rule.Head.Name.String()))) + errs = append(errs, NewError(ParseErr, rule.Location, "%s keyword cannot be used for rule name", rule.Head.Name.String())) } if opts.RequireRuleBodyOrValue && rule.generatedBody && rule.Head.generatedValue { errs = append(errs, NewError(ParseErr, rule.Location, "%s must have value assignment and/or body declaration", t)) diff --git a/ast/term_test.go b/ast/term_test.go index f8ee09916b..cca535d0e5 100644 --- a/ast/term_test.go +++ b/ast/term_test.go @@ -723,13 +723,11 @@ func TestSetEqual(t *testing.T) { a := MustParseTerm(tc.a) b := MustParseTerm(tc.b) if a.Equal(b) != tc.expected { - var msg string if tc.expected { - msg = fmt.Sprintf("Expected %v to equal %v", a, b) + t.Errorf("Expected %v to equal %v", a, b) } else { - msg = fmt.Sprintf("Expected %v to NOT equal %v", a, b) + t.Errorf("Expected %v to NOT equal %v", a, b) } - t.Errorf(msg) } } } diff --git a/cmd/eval.go b/cmd/eval.go index 89bfead2af..ecaa8a731b 100644 --- a/cmd/eval.go +++ b/cmd/eval.go @@ -392,7 +392,7 @@ func eval(args []string, params evalCommandParams, w io.Writer) (bool, error) { for _, t := range timers { val, ok := t[name].(int64) if !ok { - return false, fmt.Errorf("missing timer for %s" + name) + return false, fmt.Errorf("missing timer for %s", name) } vals = append(vals, val) } diff --git a/cmd/eval_test.go b/cmd/eval_test.go index ffeb1348a2..0601350b47 100755 --- a/cmd/eval_test.go +++ b/cmd/eval_test.go @@ -9,6 +9,7 @@ import ( "bufio" "bytes" "context" + "errors" "fmt" "net/http" "net/http/httptest" @@ -506,7 +507,7 @@ func testEvalWithSchemasAnnotationButNoSchemaFlag(policy string) error { var defined bool defined, err = eval([]string{query}, params, &buf) if !defined || err != nil { - err = fmt.Errorf(buf.String()) + err = errors.New(buf.String()) } }) diff --git a/cmd/fmt.go b/cmd/fmt.go index fb8353f380..303f34a28b 100644 --- a/cmd/fmt.go +++ b/cmd/fmt.go @@ -223,9 +223,9 @@ func formatStdin(params *fmtCommandParams, r io.Reader, w io.Writer) error { return err } -func doDiff(old, new []byte) (diffString string) { +func doDiff(a, b []byte) (diffString string) { // "a" is old, "b" is new dmp := diffmatchpatch.New() - diffs := dmp.DiffMain(string(old), string(new), false) + diffs := dmp.DiffMain(string(a), string(b), false) return dmp.DiffPrettyText(diffs) } diff --git a/cmd/fmt_test.go b/cmd/fmt_test.go index fd66c4ad8e..04e0e0ebde 100644 --- a/cmd/fmt_test.go +++ b/cmd/fmt_test.go @@ -2,6 +2,7 @@ package cmd import ( "bytes" + "errors" "fmt" "io" "os" @@ -98,8 +99,8 @@ type errorWriter struct { ErrMsg string } -func (ew errorWriter) Write(_ []byte) (n int, err error) { - return 0, fmt.Errorf(ew.ErrMsg) +func (ew errorWriter) Write([]byte) (int, error) { + return 0, errors.New(ew.ErrMsg) } func TestFmtFormatFile(t *testing.T) { diff --git a/cmd/test.go b/cmd/test.go index 7b7dfefe97..1ad3e3ac07 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -6,6 +6,7 @@ package cmd import ( "context" + "errors" "fmt" "io" "os" @@ -373,7 +374,7 @@ func compileAndSetupTests(ctx context.Context, testParams testCommandParams, sto if testParams.benchmark { errMsg := "coverage reporting is not supported when benchmarking tests" fmt.Fprintln(testParams.errOutput, errMsg) - return nil, nil, fmt.Errorf(errMsg) + return nil, nil, errors.New(errMsg) } cov = cover.New() coverTracer = cov diff --git a/dependencies/deps_test.go b/dependencies/deps_test.go index dd4a350502..8eada4cafb 100644 --- a/dependencies/deps_test.go +++ b/dependencies/deps_test.go @@ -358,7 +358,7 @@ func TestDependencies(t *testing.T) { }) mod := compiler.Modules["test"] - min, full := runDeps(t, mod) + minOfAll, full := runDeps(t, mod) // Test that we get the same result by analyzing all the // rules separately. @@ -369,7 +369,7 @@ func TestDependencies(t *testing.T) { fullRules = append(fullRules, f...) } - assertRefSliceEq(t, exp, min) + assertRefSliceEq(t, exp, minOfAll) assertRefSliceEq(t, exp, minRules) for _, full := range test.full { diff --git a/format/format.go b/format/format.go index dcef3a2e7b..75626fff61 100644 --- a/format/format.go +++ b/format/format.go @@ -1036,7 +1036,7 @@ func (w *writer) writeObjectComprehension(object *ast.ObjectComprehension, loc * return w.writeComprehension('{', '}', object.Value, object.Body, loc, comments) } -func (w *writer) writeComprehension(open, close byte, term *ast.Term, body ast.Body, loc *ast.Location, comments []*ast.Comment) []*ast.Comment { +func (w *writer) writeComprehension(openChar, closeChar byte, term *ast.Term, body ast.Body, loc *ast.Location, comments []*ast.Comment) []*ast.Comment { if term.Location.Row-loc.Row >= 1 { w.endLine() w.startLine() @@ -1050,10 +1050,10 @@ func (w *writer) writeComprehension(open, close byte, term *ast.Term, body ast.B comments = w.writeTermParens(parens, term, comments) w.write(" |") - return w.writeComprehensionBody(open, close, body, term.Location, loc, comments) + return w.writeComprehensionBody(openChar, closeChar, body, term.Location, loc, comments) } -func (w *writer) writeComprehensionBody(open, close byte, body ast.Body, term, compr *ast.Location, comments []*ast.Comment) []*ast.Comment { +func (w *writer) writeComprehensionBody(openChar, closeChar byte, body ast.Body, term, compr *ast.Location, comments []*ast.Comment) []*ast.Comment { exprs := make([]interface{}, 0, len(body)) for _, expr := range body { exprs = append(exprs, expr) @@ -1077,7 +1077,7 @@ func (w *writer) writeComprehensionBody(open, close byte, body ast.Body, term, c comments = w.writeExpr(body[i], comments) } - return w.insertComments(comments, closingLoc(0, 0, open, close, compr)) + return w.insertComments(comments, closingLoc(0, 0, openChar, closeChar, compr)) } func (w *writer) writeImports(imports []*ast.Import, comments []*ast.Comment) []*ast.Comment { @@ -1403,7 +1403,7 @@ func getLoc(x interface{}) *ast.Location { } } -func closingLoc(skipOpen, skipClose, open, close byte, loc *ast.Location) *ast.Location { +func closingLoc(skipOpen, skipClose, openChar, closeChar byte, loc *ast.Location) *ast.Location { i, offset := 0, 0 // Skip past parens/brackets/braces in rule heads. @@ -1412,7 +1412,7 @@ func closingLoc(skipOpen, skipClose, open, close byte, loc *ast.Location) *ast.L } for ; i < len(loc.Text); i++ { - if loc.Text[i] == open { + if loc.Text[i] == openChar { break } } @@ -1429,9 +1429,9 @@ func closingLoc(skipOpen, skipClose, open, close byte, loc *ast.Location) *ast.L } switch loc.Text[i] { - case open: + case openChar: state++ - case close: + case closeChar: state-- case '\n': offset++ @@ -1441,10 +1441,10 @@ func closingLoc(skipOpen, skipClose, open, close byte, loc *ast.Location) *ast.L return &ast.Location{Row: loc.Row + offset} } -func skipPast(open, close byte, loc *ast.Location) (int, int) { +func skipPast(openChar, closeChar byte, loc *ast.Location) (int, int) { i := 0 for ; i < len(loc.Text); i++ { - if loc.Text[i] == open { + if loc.Text[i] == openChar { break } } @@ -1458,9 +1458,9 @@ func skipPast(open, close byte, loc *ast.Location) (int, int) { } switch loc.Text[i] { - case open: + case openChar: state++ - case close: + case closeChar: state-- case '\n': offset++ diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 25beebfec7..ca571d2d86 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -311,7 +311,7 @@ discovery: configBytes, err := Load(configFile, configOverrides, nil) if err != nil { - t.Errorf("unexpected error loading config: " + err.Error()) + t.Errorf("unexpected error loading config: %s", err.Error()) } config := map[string]interface{}{} @@ -367,7 +367,7 @@ discovery: configBytes, err := Load(configFile, nil, overrideFiles) if err != nil { - t.Errorf("unexpected error loading config: " + err.Error()) + t.Errorf("unexpected error loading config: %s", err.Error()) } config := map[string]interface{}{} @@ -409,7 +409,7 @@ func TestLoadConfigWithParamOverrideNoConfigFile(t *testing.T) { configBytes, err := Load("", configOverrides, nil) if err != nil { - t.Errorf("unexpected error loading config: " + err.Error()) + t.Errorf("unexpected error loading config: %s", err.Error()) } config := map[string]interface{}{} @@ -451,7 +451,7 @@ func TestLoadConfigWithParamOverrideNoConfigFileWithEmptyObject(t *testing.T) { configBytes, err := Load("", configOverrides, nil) if err != nil { - t.Errorf("unexpected error loading config: " + err.Error()) + t.Errorf("unexpected error loading config: %s", err.Error()) } config := map[string]interface{}{} diff --git a/internal/gojsonschema/schemaReferencePool.go b/internal/gojsonschema/schemaReferencePool.go index 876419f56c..515702095b 100644 --- a/internal/gojsonschema/schemaReferencePool.go +++ b/internal/gojsonschema/schemaReferencePool.go @@ -25,10 +25,6 @@ package gojsonschema -import ( - "fmt" -) - type schemaReferencePool struct { documents map[string]*SubSchema } @@ -44,7 +40,7 @@ func newSchemaReferencePool() *schemaReferencePool { func (p *schemaReferencePool) Get(ref string) (r *SubSchema, o bool) { if internalLogEnabled { - internalLog(fmt.Sprintf("Schema Reference ( %s )", ref)) + internalLog("Schema Reference ( %s )", ref) } if sch, ok := p.documents[ref]; ok { @@ -60,7 +56,7 @@ func (p *schemaReferencePool) Get(ref string) (r *SubSchema, o bool) { func (p *schemaReferencePool) Add(ref string, sch *SubSchema) { if internalLogEnabled { - internalLog(fmt.Sprintf("Add Schema Reference %s to pool", ref)) + internalLog("Add Schema Reference %s to pool", ref) } if _, ok := p.documents[ref]; !ok { p.documents[ref] = sch diff --git a/internal/gojsonschema/validation.go b/internal/gojsonschema/validation.go index 7c86e37245..efdea58b6b 100644 --- a/internal/gojsonschema/validation.go +++ b/internal/gojsonschema/validation.go @@ -348,7 +348,7 @@ func (v *SubSchema) validateSchema(currentSubSchema *SubSchema, currentNode inte } } - if currentSubSchema.dependencies != nil && len(currentSubSchema.dependencies) > 0 { + if len(currentSubSchema.dependencies) > 0 { if currentNodeMap, ok := currentNode.(map[string]interface{}); ok { for elementKey := range currentNodeMap { if dependency, ok := currentSubSchema.dependencies[elementKey]; ok { @@ -469,7 +469,7 @@ func (v *SubSchema) validateArray(currentSubSchema *SubSchema, value []interface result.mergeErrors(validationResult) } } else { - if currentSubSchema.ItemsChildren != nil && len(currentSubSchema.ItemsChildren) > 0 { + if len(currentSubSchema.ItemsChildren) > 0 { nbItems := len(currentSubSchema.ItemsChildren) diff --git a/internal/gqlparser/validator/rules/fields_on_correct_type.go b/internal/gqlparser/validator/rules/fields_on_correct_type.go index d536e5e5f4..f681767475 100644 --- a/internal/gqlparser/validator/rules/fields_on_correct_type.go +++ b/internal/gqlparser/validator/rules/fields_on_correct_type.go @@ -27,7 +27,7 @@ func init() { } addError( - Message(message), + Message(message), //nolint:govet At(field.Position), ) }) diff --git a/internal/gqlparser/validator/rules/fragments_on_composite_types.go b/internal/gqlparser/validator/rules/fragments_on_composite_types.go index 66bd348c47..861e3b16cf 100644 --- a/internal/gqlparser/validator/rules/fragments_on_composite_types.go +++ b/internal/gqlparser/validator/rules/fragments_on_composite_types.go @@ -20,7 +20,7 @@ func init() { message := fmt.Sprintf(`Fragment cannot condition on non composite type "%s".`, inlineFragment.TypeCondition) addError( - Message(message), + Message(message), //nolint:govet At(inlineFragment.Position), ) }) @@ -33,7 +33,7 @@ func init() { message := fmt.Sprintf(`Fragment "%s" cannot condition on non composite type "%s".`, fragment.Name, fragment.TypeCondition) addError( - Message(message), + Message(message), //nolint:govet At(fragment.Position), ) }) diff --git a/internal/oracle/oracle.go b/internal/oracle/oracle.go index baa74fae7f..4fa36fcd07 100644 --- a/internal/oracle/oracle.go +++ b/internal/oracle/oracle.go @@ -198,9 +198,9 @@ func findContainingNodeStack(module *ast.Module, pos int) []ast.Node { ast.WalkNodes(module, func(x ast.Node) bool { - min, max := getLocMinMax(x) + minLoc, maxLoc := getLocMinMax(x) - if pos < min || pos >= max { + if pos < minLoc || pos >= maxLoc { return true } @@ -218,7 +218,7 @@ func getLocMinMax(x ast.Node) (int, int) { } loc := x.Loc() - min := loc.Offset + minOff := loc.Offset // Special case bodies because location text is only for the first expr. if body, ok := x.(ast.Body); ok { @@ -227,10 +227,10 @@ func getLocMinMax(x ast.Node) (int, int) { if extraLoc == nil { return -1, -1 } - return min, extraLoc.Offset + len(extraLoc.Text) + return minOff, extraLoc.Offset + len(extraLoc.Text) } - return min, min + len(loc.Text) + return minOff, minOff + len(loc.Text) } // findLastExpr returns the last expression in an ast.Body that has not been generated diff --git a/internal/wasm/encoding/reader.go b/internal/wasm/encoding/reader.go index 35e6059c72..7120392ce2 100644 --- a/internal/wasm/encoding/reader.go +++ b/internal/wasm/encoding/reader.go @@ -809,19 +809,19 @@ func readLimits(r io.Reader, l *module.Limit) error { return err } - min, err := leb128.ReadVarUint32(r) + minLim, err := leb128.ReadVarUint32(r) if err != nil { return err } - l.Min = min + l.Min = minLim if b == 1 { - max, err := leb128.ReadVarUint32(r) + maxLim, err := leb128.ReadVarUint32(r) if err != nil { return err } - l.Max = &max + l.Max = &maxLim } else if b != 0 { return fmt.Errorf("illegal limit flag") } diff --git a/internal/wasm/sdk/internal/wasm/bindings.go b/internal/wasm/sdk/internal/wasm/bindings.go index f90031c532..1c5a7ffefa 100644 --- a/internal/wasm/sdk/internal/wasm/bindings.go +++ b/internal/wasm/sdk/internal/wasm/bindings.go @@ -222,8 +222,8 @@ func getExports(c *wasmtime.Caller) exports { return e } -func (e exports) Malloc(caller *wasmtime.Caller, len int32) (int32, error) { - ptr, err := e.mallocFn.Call(caller, len) +func (e exports) Malloc(caller *wasmtime.Caller, length int32) (int32, error) { + ptr, err := e.mallocFn.Call(caller, length) if err != nil { return 0, err } @@ -238,8 +238,8 @@ func (e exports) ValueDump(caller *wasmtime.Caller, addr int32) (int32, error) { return result.(int32), nil } -func (e exports) ValueParse(caller *wasmtime.Caller, addr int32, len int32) (int32, error) { - result, err := e.valueParseFn.Call(caller, addr, len) +func (e exports) ValueParse(caller *wasmtime.Caller, addr int32, length int32) (int32, error) { + result, err := e.valueParseFn.Call(caller, addr, length) if err != nil { return 0, err } diff --git a/logging/logging_test.go b/logging/logging_test.go index 9c6d643360..6738c578a2 100644 --- a/logging/logging_test.go +++ b/logging/logging_test.go @@ -56,10 +56,10 @@ func TestNoFormattingForSingleString(t *testing.T) { // a format string but no args, the golang linters would yell. The indirection // taken here is enough to not trigger linters. x := url.PathEscape("/foo/bar/bar") - logger.Debug(x) - logger.Info(x) - logger.Warn(x) - logger.Error(x) + logger.Debug(x) //nolint:govet + logger.Info(x) //nolint:govet + logger.Warn(x) //nolint:govet + logger.Error(x) //nolint:govet exp := `"%2Ffoo%2Fbar%2Fbar"` expected := []string{ diff --git a/plugins/logs/mask_test.go b/plugins/logs/mask_test.go index 0585bc4333..f27f0641f8 100644 --- a/plugins/logs/mask_test.go +++ b/plugins/logs/mask_test.go @@ -711,7 +711,7 @@ func TestMaskRuleSetMask(t *testing.T) { } } else { ptr.OnRuleError = func(mRule *maskRule, err error) { - t.Fatalf(fmt.Sprintf("unexpected rule error, rule: %s, error: %s", mRule.String(), err.Error())) + t.Fatalf("unexpected rule error, rule: %s, error: %s", mRule.String(), err.Error()) } } for _, rule := range tc.rules { diff --git a/plugins/rest/rest_test.go b/plugins/rest/rest_test.go index 4255262b1a..61cf7d041e 100644 --- a/plugins/rest/rest_test.go +++ b/plugins/rest/rest_test.go @@ -2378,7 +2378,7 @@ func (t *testServer) handle(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte(errMsg)) return } - t.t.Fatalf(errMsg) + t.t.Fatal(errMsg) } if t.expBearerToken != "" && !strings.HasSuffix(auth, t.expBearerToken) { errMsg := fmt.Sprintf("Expected bearer token %q, got authorization header %q", t.expBearerToken, auth) @@ -2387,7 +2387,7 @@ func (t *testServer) handle(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte(errMsg)) return } - t.t.Fatalf(errMsg) + t.t.Fatal(errMsg) } } if t.expectClientCert { diff --git a/runtime/plugins_test.go b/runtime/plugins_test.go index af7042f42e..fd20cb1798 100644 --- a/runtime/plugins_test.go +++ b/runtime/plugins_test.go @@ -70,7 +70,7 @@ func TestRegisterPlugin(t *testing.T) { rt, err := NewRuntime(context.Background(), params) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } if err := rt.Manager.Start(context.Background()); err != nil { @@ -102,7 +102,7 @@ func TestRegisterPluginNotStartedWithoutConfig(t *testing.T) { rt, err := NewRuntime(context.Background(), params) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } if err := rt.Manager.Start(context.Background()); err != nil { @@ -155,7 +155,7 @@ func TestWaitPluginsReady(t *testing.T) { rt, err := NewRuntime(context.Background(), params) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } if err := rt.Manager.Start(context.Background()); err != nil { diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index e8bfcd0fb4..2b9dec460b 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -1564,7 +1564,7 @@ func TestRuntimeWithExplicitMetricConfiguration(t *testing.T) { _, err := NewRuntime(context.Background(), params) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } }) } diff --git a/server/authorizer/authorizer.go b/server/authorizer/authorizer.go index 4240f40377..f641e3bcef 100644 --- a/server/authorizer/authorizer.go +++ b/server/authorizer/authorizer.go @@ -146,7 +146,7 @@ func (h *Basic) ServeHTTP(w http.ResponseWriter, r *http.Request) { if reason, ok := allowed["reason"]; ok { message, ok := reason.(string) if ok { - writer.Error(w, http.StatusUnauthorized, types.NewErrorV1(types.CodeUnauthorized, message)) + writer.Error(w, http.StatusUnauthorized, types.NewErrorV1(types.CodeUnauthorized, message)) //nolint:govet return } } diff --git a/server/server.go b/server/server.go index bb5c70767e..018686f5d9 100644 --- a/server/server.go +++ b/server/server.go @@ -1154,7 +1154,7 @@ func (s *Server) v0QueryPath(w http.ResponseWriter, r *http.Request, urlPath str if len(s.getCompiler().GetRulesForVirtualDocument(ref)) > 0 { messageType = types.MsgFoundUndefinedError } - err := types.NewErrorV1(types.CodeUndefinedDocument, fmt.Sprintf("%v: %v", messageType, ref)) + err := types.NewErrorV1(types.CodeUndefinedDocument, "%v: %v", messageType, ref) if err := logger.Log(ctx, txn, urlPath, "", goInput, input, nil, ndbCache, err, m); err != nil { writer.ErrorAuto(w, err) return diff --git a/server/writer/writer.go b/server/writer/writer.go index 09cda5fb77..64dc81241e 100644 --- a/server/writer/writer.go +++ b/server/writer/writer.go @@ -44,7 +44,7 @@ func ErrorAuto(w http.ResponseWriter, err error) { // ErrorString writes a response with specified status, code, and message set to // the err's string representation. func ErrorString(w http.ResponseWriter, status int, code string, err error) { - Error(w, status, types.NewErrorV1(code, err.Error())) + Error(w, status, types.NewErrorV1(code, err.Error())) //nolint:govet } // Error writes a response with specified status and error response. diff --git a/storage/path.go b/storage/path.go index 02ef4cab40..715c7dde51 100644 --- a/storage/path.go +++ b/storage/path.go @@ -84,11 +84,7 @@ func NewPathForRef(ref ast.Ref) (path Path, err error) { // is less than other, 0 if p is equal to other, or 1 if p is greater than // other. func (p Path) Compare(other Path) (cmp int) { - min := len(p) - if len(other) < min { - min = len(other) - } - for i := 0; i < min; i++ { + for i := 0; i < min(len(p), len(other)); i++ { if cmp := strings.Compare(p[i], other[i]); cmp != 0 { return cmp } diff --git a/tester/runner.go b/tester/runner.go index 25c23abf4a..4b1d6a1a7f 100644 --- a/tester/runner.go +++ b/tester/runner.go @@ -317,7 +317,7 @@ func (r *Runner) runTests(ctx context.Context, txn storage.Transaction, enablePr r.store = inmem.NewWithOpts(inmem.OptRoundTripOnWrite(false)) } - if r.bundles != nil && len(r.bundles) > 0 { + if len(r.bundles) > 0 { if txn == nil { return nil, fmt.Errorf("unable to activate bundles: storage transaction is nil") } diff --git a/topdown/http_test.go b/topdown/http_test.go index accb328463..fcda1adfea 100644 --- a/topdown/http_test.go +++ b/topdown/http_test.go @@ -3073,7 +3073,7 @@ func TestCertSelectionLogic(t *testing.T) { tlsConfig := getClientTLSConfig(obj) if tc.expected == nil { if tlsConfig != nil { - t.Fatalf(tc.msg) + t.Fatal(tc.msg) } } else { // nolint:staticcheck // ignoring the deprecated (*CertPool).Subjects() call here because it's in a test. diff --git a/util/backoff.go b/util/backoff.go index 6fbf63ef77..36d57f14e2 100644 --- a/util/backoff.go +++ b/util/backoff.go @@ -22,24 +22,24 @@ func init() { // DefaultBackoff returns a delay with an exponential backoff based on the // number of retries. -func DefaultBackoff(base, max float64, retries int) time.Duration { - return Backoff(base, max, .2, 1.6, retries) +func DefaultBackoff(base, maxNS float64, retries int) time.Duration { + return Backoff(base, maxNS, .2, 1.6, retries) } // Backoff returns a delay with an exponential backoff based on the number of // retries. Same algorithm used in gRPC. -func Backoff(base, max, jitter, factor float64, retries int) time.Duration { +func Backoff(base, maxNS, jitter, factor float64, retries int) time.Duration { if retries == 0 { return 0 } - backoff, max := base, max - for backoff < max && retries > 0 { + backoff, maxNS := base, maxNS + for backoff < maxNS && retries > 0 { backoff *= factor retries-- } - if backoff > max { - backoff = max + if backoff > maxNS { + backoff = maxNS } // Randomize backoff delays so that if a cluster of requests start at