diff --git a/.golangci.yml b/.golangci.yml index c2b9388a..c58a1801 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,11 +4,10 @@ linters: enable-all: true disable: - cyclop - - deadcode - dupword + - err113 - errname - exhaustruct - - exhaustivestruct - forbidigo - forcetypeassert - funlen @@ -16,29 +15,22 @@ linters: - gochecknoinits - goconst - godox - - goerr113 - - golint - - gomnd - gosec - - ifshort + - iface - inamedparam - - interfacer - ireturn - lll - - maligned + - mnd - nlreturn - nonamedreturns - - nosnakecase - paralleltest - - prealloc - perfsprint + - prealloc + - recvcheck - rowserrcheck - - scopelint - - structcheck - tagliatelle - testpackage - unparam - - varcheck - varnamelen - wastedassign - wrapcheck diff --git a/build/error.go b/build/error.go index d6f3be64..417a5d94 100644 --- a/build/error.go +++ b/build/error.go @@ -73,13 +73,13 @@ func (e ErrorList) Error() string { } // LogError logs a list of errors, one error per line, if the err parameter is -// an ErrorList. Otherwise it just logs the err string. Reports at most max -// errors, or unlimited if max is 0. -func LogError(l *log.Logger, err error, max int) { +// an ErrorList. Otherwise it just logs the err string. Reports at most mx +// errors, or unlimited if mx is 0. +func LogError(l *log.Logger, err error, mx int) { var list ErrorList if errors.As(err, &list) { for i, e := range list { - if max > 0 && i == max { + if mx > 0 && i == mx { l.Print("too many errors") return } diff --git a/gotypes/components.go b/gotypes/components.go index fe0c9733..c5e6fada 100644 --- a/gotypes/components.go +++ b/gotypes/components.go @@ -190,7 +190,7 @@ func (c *component) Field(n string) Component { // } // fields := make([]*types.Var, s.NumFields()) - for i := 0; i < s.NumFields(); i++ { + for i := range s.NumFields() { fields[i] = s.Field(i) } offsets := Sizes.Offsetsof(fields) diff --git a/gotypes/components_test.go b/gotypes/components_test.go index 2de74916..7f5c97ba 100644 --- a/gotypes/components_test.go +++ b/gotypes/components_test.go @@ -192,7 +192,7 @@ func TestComponentDeconstruction(t *testing.T) { // For every test case, generate the same case but when the type is wrapped in // a named type. n := len(cases) - for i := 0; i < n; i++ { + for i := range n { wrapped := cases[i] wrapped.Name += "_wrapped" wrapped.Type = types.NewNamed( @@ -204,7 +204,6 @@ func TestComponentDeconstruction(t *testing.T) { } for _, c := range cases { - c := c // avoid scopelint error t.Run(c.Name, func(t *testing.T) { t.Log(c.Type) base := operand.NewParamAddr("test", 0) diff --git a/gotypes/signature.go b/gotypes/signature.go index a96b056e..9e90ce64 100644 --- a/gotypes/signature.go +++ b/gotypes/signature.go @@ -131,7 +131,7 @@ func newTuple(t *types.Tuple, offsets []int64, size int64, defaultprefix string) byname: map[string]Component{}, size: int(size), } - for i := 0; i < t.Len(); i++ { + for i := range t.Len() { v := t.At(i) name := v.Name() if name == "" { @@ -172,7 +172,7 @@ func (t *Tuple) Bytes() int { return t.size } func tuplevars(t *types.Tuple) []*types.Var { vs := make([]*types.Var, t.Len()) - for i := 0; i < t.Len(); i++ { + for i := range t.Len() { vs[i] = t.At(i) } return vs diff --git a/gotypes/signature_test.go b/gotypes/signature_test.go index 07a95c58..6fab939b 100644 --- a/gotypes/signature_test.go +++ b/gotypes/signature_test.go @@ -143,7 +143,7 @@ func TypesTuplesEqual(a, b *types.Tuple) bool { return false } n := a.Len() - for i := 0; i < n; i++ { + for i := range n { if !TypesVarsEqual(a.At(i), b.At(i)) { return false } diff --git a/internal/api/function.go b/internal/api/function.go index 1ae795cc..5b3fad47 100644 --- a/internal/api/function.go +++ b/internal/api/function.go @@ -97,7 +97,7 @@ func (f *Function) Signature() Signature { n := f.Arity() ops := make([]string, n) count := map[string]int{} - for j := 0; j < n; j++ { + for j := range n { // Collect unique lowercase bytes from first characters of operand types. s := map[byte]bool{} for _, form := range f.Forms { diff --git a/internal/api/function_test.go b/internal/api/function_test.go index 0c348b62..3e4b31fc 100644 --- a/internal/api/function_test.go +++ b/internal/api/function_test.go @@ -12,7 +12,6 @@ func TestFunctionsDuplicateFormSignatures(t *testing.T) { // manifest as duplicate case statements in generated code. fns := InstructionsFunctions(inst.Instructions) for _, fn := range fns { - fn := fn // scopelint t.Run(fn.Name(), func(t *testing.T) { seen := map[string]bool{} for _, f := range fn.Forms { @@ -36,7 +35,7 @@ func TestFunctionsUniqueArgNames(t *testing.T) { continue } names := map[string]bool{} - for j := 0; j < n; j++ { + for j := range n { names[s.ParameterName(j)] = true } if len(names) != n { diff --git a/internal/gen/optab.go b/internal/gen/optab.go index ca51c33a..34e37eca 100644 --- a/internal/gen/optab.go +++ b/internal/gen/optab.go @@ -58,18 +58,18 @@ func (t *optab) Generate(is []inst.Instruction) ([]byte, error) { } func (t *optab) maxOperands(is []inst.Instruction) { - max := 0 + mx := 0 for _, i := range inst.Instructions { for _, f := range i.Forms { a := len(f.Operands) + len(f.ImplicitOperands) - if a > max { - max = a + if a > mx { + mx = a } } } t.Comment("maxoperands is the maximum number of operands in an instruction form, including implicit operands.") - t.Printf("const maxoperands = %d\n\n", max) + t.Printf("const maxoperands = %d\n\n", mx) } func (t *optab) operandTypeEnum(is []inst.Instruction) { @@ -109,17 +109,17 @@ func (t *optab) implicitRegisterEnum(is []inst.Instruction) { func (t *optab) suffixesType(is []inst.Instruction) { // Declare the type as an array. This requires us to know the maximum number // of suffixes an instruction can have. - max := 0 + mx := 0 for _, class := range inst.SuffixesClasses(is) { for _, suffixes := range class { - if len(suffixes) > max { - max = len(suffixes) + if len(suffixes) > mx { + mx = len(suffixes) } } } t.Comment("maxsuffixes is the maximum number of suffixes an instruction can have.") - t.Printf("const maxsuffixes = %d\n\n", max) + t.Printf("const maxsuffixes = %d\n\n", mx) name := t.table.SuffixesTypeName() t.Printf("type %s [maxsuffixes]%s\n", name, t.table.Suffix().Name()) diff --git a/internal/inst/table_test.go b/internal/inst/table_test.go index d0eec144..38c2fa5f 100644 --- a/internal/inst/table_test.go +++ b/internal/inst/table_test.go @@ -44,7 +44,7 @@ func TestFormDupes(t *testing.T) { func HasFormDupe(i inst.Instruction) bool { n := len(i.Forms) - for a := 0; a < n; a++ { + for a := range n { for b := a + 1; b < n; b++ { if reflect.DeepEqual(i.Forms[a], i.Forms[b]) { return true diff --git a/internal/stack/stack.go b/internal/stack/stack.go index 1d327d9d..f86d4122 100644 --- a/internal/stack/stack.go +++ b/internal/stack/stack.go @@ -7,10 +7,10 @@ import ( "strings" ) -// Frames returns at most max callstack Frames, starting with its caller and +// Frames returns at most m callstack Frames, starting with its caller and // skipping skip Frames. -func Frames(skip, max int) []runtime.Frame { - pc := make([]uintptr, max) +func Frames(skip, m int) []runtime.Frame { + pc := make([]uintptr, m) n := runtime.Callers(skip+2, pc) if n == 0 { return nil diff --git a/internal/stack/stack_test.go b/internal/stack/stack_test.go index 4b833d16..eb48f26a 100644 --- a/internal/stack/stack_test.go +++ b/internal/stack/stack_test.go @@ -25,6 +25,7 @@ func TestMatchFirst(t *testing.T) { first := stack.Match(0, func(_ runtime.Frame) bool { return true }) if first == nil { t.Fatalf("nil match") + return } got := first.Function expect := pkg + ".TestMatchFirst" diff --git a/pass/alloc_test.go b/pass/alloc_test.go index cee9a9ef..0cc9b7ca 100644 --- a/pass/alloc_test.go +++ b/pass/alloc_test.go @@ -78,7 +78,7 @@ func TestAllocatorPriority(t *testing.T) { a.Add(x[i].ID()) } - for i := 0; i < n; i++ { + for i := range n { for j := i + 1; j < n; j++ { a.AddInterference(x[i].ID(), x[j].ID()) } diff --git a/pass/cfg.go b/pass/cfg.go index d5f6ea4e..687584f1 100644 --- a/pass/cfg.go +++ b/pass/cfg.go @@ -39,7 +39,7 @@ func CFG(fn *ir.Function) error { n := len(is) // Populate successors. - for i := 0; i < n; i++ { + for i := range n { cur := is[i] var nxt *ir.Instruction if i+1 < n { diff --git a/pass/reg_test.go b/pass/reg_test.go index 5c6b9c02..c4ec3698 100644 --- a/pass/reg_test.go +++ b/pass/reg_test.go @@ -120,7 +120,7 @@ func TestAllocateRegistersBasePointerDeprioritized(t *testing.T) { ctx.SignatureExpr("func() uint64") x := make([]reg.GPVirtual, n) - for i := 0; i < n; i++ { + for i := range n { x[i] = ctx.GP64() ctx.MOVQ(operand.U64(i), x[i]) } diff --git a/script/bootstrap b/script/bootstrap index 49af434b..4867e871 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -4,7 +4,7 @@ go install ./internal/cmd/asmvet # golangci-lint for linting -golangci_lint_version='v1.55.2' +golangci_lint_version='v1.62.2' golangci_install_script="https://raw.githubusercontent.com/golangci/golangci-lint/${golangci_lint_version}/install.sh" curl -sfL "${golangci_install_script}" | sh -s -- -b "$(go env GOPATH)/bin" "${golangci_lint_version}" diff --git a/tests/alloc/zeroing/zeroing_test.go b/tests/alloc/zeroing/zeroing_test.go index e28b3722..0dd2994b 100644 --- a/tests/alloc/zeroing/zeroing_test.go +++ b/tests/alloc/zeroing/zeroing_test.go @@ -21,7 +21,7 @@ func TestZeroing(t *testing.T) { var got [8]uint64 Zeroing(&got) - for i := 0; i < 8; i++ { + for i := range 8 { if got[i] != expect { t.Errorf("got[%d] = %d; expect %d", i, got[i], expect) } diff --git a/tests/fixedbugs/issue387/issue387_test.go b/tests/fixedbugs/issue387/issue387_test.go index 545a827f..410d1912 100644 --- a/tests/fixedbugs/issue387/issue387_test.go +++ b/tests/fixedbugs/issue387/issue387_test.go @@ -7,7 +7,7 @@ import ( //go:generate go run asm.go -out issue387.s -stubs stub.go func TestFloat32(t *testing.T) { - for i := 0; i < 10; i++ { + for i := range 10 { got := Float32(i) expect := float32(i) if got != expect { @@ -17,7 +17,7 @@ func TestFloat32(t *testing.T) { } func TestFloat64(t *testing.T) { - for i := 0; i < 10; i++ { + for i := range 10 { got := Float64(i) expect := float64(i) if got != expect { diff --git a/tests/thirdparty/config_test.go b/tests/thirdparty/config_test.go index 27a4e405..23b68961 100644 --- a/tests/thirdparty/config_test.go +++ b/tests/thirdparty/config_test.go @@ -94,7 +94,6 @@ func TestValidateErrors(t *testing.T) { }, } for _, c := range cases { - c := c // scopelint t.Run(c.Name, func(t *testing.T) { err := c.Item.Validate() if err == nil { diff --git a/tests/thirdparty/packages_test.go b/tests/thirdparty/packages_test.go index d34b9ceb..fce1fe6f 100644 --- a/tests/thirdparty/packages_test.go +++ b/tests/thirdparty/packages_test.go @@ -34,7 +34,6 @@ func TestPackages(t *testing.T) { } for _, tst := range s.Projects.Tests() { - tst := tst // scopelint t.Run(tst.ID(), func(t *testing.T) { if tst.Project.Skip() { t.Skipf("skip: %s", tst.Project.Reason()) diff --git a/x86/inst_test.go b/x86/inst_test.go index fb5b0f48..295a0fd8 100644 --- a/x86/inst_test.go +++ b/x86/inst_test.go @@ -78,7 +78,6 @@ func TestCases(t *testing.T) { } for _, c := range cases { - c := c // scopelint t.Run(c.Name, func(t *testing.T) { if !reflect.DeepEqual(c.Instruction, c.Expect) { t.Logf(" got = %#v", c.Instruction)