Skip to content

Commit 68f7418

Browse files
committed
Update golangci-lint
1 parent e4f2594 commit 68f7418

File tree

10 files changed

+302
-336
lines changed

10 files changed

+302
-336
lines changed

.golangci.yml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
linters-settings:
2+
custom:
3+
noprint:
4+
type: module
5+
nodebug:
6+
type: module
7+
rangevarref:
8+
type: module
9+
10+
goheader:
11+
values:
12+
const:
13+
AUTHOR: The Accumulate Authors
14+
template: |-
15+
Copyright {{ YEAR }} {{ AUTHOR }}
16+
17+
Use of this source code is governed by an MIT-style
18+
license that can be found in the LICENSE file or at
19+
https://opensource.org/licenses/MIT.
20+
121
linters:
222
disable-all: true
323
enable:
@@ -59,15 +79,3 @@ issues:
5979
- path: ^test/util/goroutine_leaks\.go$
6080
linters:
6181
- goheader
62-
63-
linters-settings:
64-
goheader:
65-
values:
66-
const:
67-
AUTHOR: The Accumulate Authors
68-
template: |-
69-
Copyright {{ YEAR }} {{ AUTHOR }}
70-
71-
Use of this source code is governed by an MIT-style
72-
license that can be found in the LICENSE file or at
73-
https://opensource.org/licenses/MIT.

go.mod

Lines changed: 71 additions & 67 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 152 additions & 192 deletions
Large diffs are not rendered by default.

tools/cmd/golangci-lint/custom.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
1-
// Copyright 2022 The Accumulate Authors
2-
//
1+
// Copyright 2024 The Accumulate Authors
2+
//
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file or at
55
// https://opensource.org/licenses/MIT.
66

77
package main
88

99
import (
10-
"fmt"
11-
"reflect"
12-
"unsafe"
13-
14-
"github.com/golangci/golangci-lint/pkg/lint/linter"
15-
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
10+
"golang.org/x/tools/go/analysis"
1611
)
1712

18-
var customLinters []*linter.Config
19-
20-
func addCustomLinters(db *lintersdb.Manager) {
21-
field, ok := reflect.TypeOf(db).Elem().FieldByName("nameToLCs")
22-
if !ok {
23-
panic(fmt.Errorf("can't find linter config field"))
24-
}
13+
type customLinter struct {
14+
LoadMode string
15+
Analyzer *analysis.Analyzer
16+
}
2517

26-
// This is a horrific abuse of Go. But using a plugin would be a huge PITA.
27-
nameToLCs := *(*map[string][]*linter.Config)(unsafe.Pointer(uintptr(unsafe.Pointer(db)) + field.Offset))
18+
func (c *customLinter) GetLoadMode() string {
19+
return c.LoadMode
20+
}
2821

29-
for _, lc := range customLinters {
30-
nameToLCs[lc.Name()] = append(nameToLCs[lc.Name()], lc)
31-
}
22+
func (c *customLinter) BuildAnalyzers() ([]*analysis.Analyzer, error) {
23+
return []*analysis.Analyzer{c.Analyzer}, nil
3224
}

tools/cmd/golangci-lint/custom_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright 2023 The Accumulate Authors
2-
//
1+
// Copyright 2024 The Accumulate Authors
2+
//
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file or at
55
// https://opensource.org/licenses/MIT.

tools/cmd/golangci-lint/debug.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright 2022 The Accumulate Authors
2-
//
1+
// Copyright 2024 The Accumulate Authors
2+
//
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file or at
55
// https://opensource.org/licenses/MIT.

tools/cmd/golangci-lint/main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright 2023 The Accumulate Authors
2-
//
1+
// Copyright 2024 The Accumulate Authors
2+
//
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file or at
55
// https://opensource.org/licenses/MIT.
@@ -23,15 +23,14 @@ var (
2323
)
2424

2525
func main() {
26-
e := commands.NewExecutor(commands.BuildInfo{
26+
err := commands.Execute(commands.BuildInfo{
2727
GoVersion: "go",
2828
Version: version,
2929
Commit: commit,
3030
Date: date,
3131
})
32-
addCustomLinters(e.DBManager)
3332

34-
if err := e.Execute(); err != nil {
33+
if err != nil {
3534
fmt.Fprintf(os.Stderr, "failed executing command with error %v\n", err)
3635
os.Exit(exitcodes.Failure)
3736
}

tools/cmd/golangci-lint/nodebug.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright 2022 The Accumulate Authors
2-
//
1+
// Copyright 2024 The Accumulate Authors
2+
//
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file or at
55
// https://opensource.org/licenses/MIT.
@@ -10,23 +10,24 @@ import (
1010
"go/ast"
1111
"strings"
1212

13-
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
14-
"github.com/golangci/golangci-lint/pkg/lint/linter"
13+
"github.com/golangci/plugin-module-register/register"
1514
"golang.org/x/tools/go/analysis"
1615
)
1716

1817
func init() {
1918
const name = "nodebug"
2019
const doc = "Checks for enabled debug flags"
2120

22-
customLinters = append(customLinters, linter.NewConfig(
23-
goanalysis.NewLinter(name, doc, []*analysis.Analyzer{{
24-
Name: name,
25-
Doc: doc,
26-
Run: nodebug,
27-
}}, nil).
28-
WithLoadMode(goanalysis.LoadModeSyntax),
29-
))
21+
register.Plugin(name, func(any) (register.LinterPlugin, error) {
22+
return &customLinter{
23+
LoadMode: register.LoadModeSyntax,
24+
Analyzer: &analysis.Analyzer{
25+
Name: name,
26+
Doc: doc,
27+
Run: nodebug,
28+
},
29+
}, nil
30+
})
3031
}
3132

3233
func nodebug(pass *analysis.Pass) (interface{}, error) {

tools/cmd/golangci-lint/noprint.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright 2022 The Accumulate Authors
2-
//
1+
// Copyright 2024 The Accumulate Authors
2+
//
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file or at
55
// https://opensource.org/licenses/MIT.
@@ -9,23 +9,24 @@ package main
99
import (
1010
"go/ast"
1111

12-
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
13-
"github.com/golangci/golangci-lint/pkg/lint/linter"
12+
"github.com/golangci/plugin-module-register/register"
1413
"golang.org/x/tools/go/analysis"
1514
)
1615

1716
func init() {
1817
const name = "noprint"
1918
const doc = "Checks for out of place print statements"
2019

21-
customLinters = append(customLinters, linter.NewConfig(
22-
goanalysis.NewLinter(name, doc, []*analysis.Analyzer{{
23-
Name: name,
24-
Doc: doc,
25-
Run: noprint,
26-
}}, nil).
27-
WithLoadMode(goanalysis.LoadModeSyntax),
28-
))
20+
register.Plugin(name, func(any) (register.LinterPlugin, error) {
21+
return &customLinter{
22+
LoadMode: register.LoadModeSyntax,
23+
Analyzer: &analysis.Analyzer{
24+
Name: name,
25+
Doc: doc,
26+
Run: noprint,
27+
},
28+
}, nil
29+
})
2930
}
3031

3132
func noprint(pass *analysis.Pass) (interface{}, error) {

tools/cmd/golangci-lint/rangevarref.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright 2022 The Accumulate Authors
2-
//
1+
// Copyright 2024 The Accumulate Authors
2+
//
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file or at
55
// https://opensource.org/licenses/MIT.
@@ -11,23 +11,24 @@ import (
1111
"go/token"
1212
"go/types"
1313

14-
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
15-
"github.com/golangci/golangci-lint/pkg/lint/linter"
14+
"github.com/golangci/plugin-module-register/register"
1615
"golang.org/x/tools/go/analysis"
1716
)
1817

1918
func init() {
2019
const name = "rangevarref"
2120
const doc = "Checks for loops that capture a pointer to a value-type range variable"
2221

23-
customLinters = append(customLinters, linter.NewConfig(
24-
goanalysis.NewLinter(name, doc, []*analysis.Analyzer{{
25-
Name: name,
26-
Doc: doc,
27-
Run: rangevarref,
28-
}}, nil).
29-
WithLoadMode(goanalysis.LoadModeTypesInfo),
30-
))
22+
register.Plugin(name, func(any) (register.LinterPlugin, error) {
23+
return &customLinter{
24+
LoadMode: register.LoadModeSyntax,
25+
Analyzer: &analysis.Analyzer{
26+
Name: name,
27+
Doc: doc,
28+
Run: rangevarref,
29+
},
30+
}, nil
31+
})
3132
}
3233

3334
func rangevarref(pass *analysis.Pass) (interface{}, error) {

0 commit comments

Comments
 (0)