Skip to content

Commit 120a7bb

Browse files
miparnisaricschleiden
authored andcommitted
upgrade to linter v2
1 parent 27a800e commit 120a7bb

File tree

143 files changed

+601
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+601
-377
lines changed

.custom-gcl.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# The golangci-lint version used to build the custom binary.
2+
version: v2.0.0
3+
name: goworkflows
4+
destination: .
5+
plugins:
6+
- module: 'github.com/cschleiden/go-workflows'
7+
path: ./analyzer

.golangci.yml

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,53 @@
1+
---
2+
version: "2"
13
run:
2-
tests: false
3-
4+
allow-parallel-runners: true
45
linters:
56
enable:
6-
- goworkflows
7-
8-
linters-settings:
9-
custom:
10-
goworkflows:
11-
path: ./plugin.so
12-
description: go-workflows
13-
original-url: github.com/cschleiden/go-workflows/analyzer
7+
- "bidichk"
8+
- "bodyclose"
9+
- "errcheck"
10+
- "errname"
11+
- "errorlint"
12+
# - "gocritic"
13+
- "goprintffuncname"
14+
# - "gosec"
15+
- "govet"
16+
- "importas"
17+
- "ineffassign"
18+
- "makezero"
19+
- "prealloc"
20+
- "predeclared"
21+
- "promlinter"
22+
# - "revive"
23+
- "rowserrcheck"
24+
- "spancheck"
25+
- "staticcheck"
26+
- "tagalign"
27+
- "testifylint"
28+
- "tparallel"
29+
- "unconvert"
30+
- "usetesting"
31+
- "wastedassign"
32+
- "whitespace"
33+
- "unused"
34+
settings:
35+
staticcheck:
36+
checks:
37+
- "all"
38+
formatters:
39+
enable:
40+
- "gci"
41+
- "gofmt"
42+
- "gofumpt"
43+
- "goimports"
44+
settings:
45+
gci:
46+
sections:
47+
- "standard"
48+
- "default"
49+
- "prefix(github.com/cschleiden)"
50+
- "localmodule"
51+
goimports:
52+
local-prefixes:
53+
- "github.com/cschleiden/go-workflows"

DEVELOPMENT.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@
22

33
1. `docker-compose up`
44

5-
### Use custom linter
6-
7-
1. Build analyzer `go build -tags analyzerplugin -buildmode=plugin analyzer/plugin/plugin.go`

activitytester/activitytester_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import (
44
"context"
55
"testing"
66

7-
"github.com/cschleiden/go-workflows/activity"
87
"github.com/stretchr/testify/require"
8+
9+
"github.com/cschleiden/go-workflows/activity"
910
)
1011

1112
func Activity(ctx context.Context, a int, b int) (int, error) {

analyzer/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,18 @@
22

33
This package implements a basic analyzer for checking various common workflow error conditions.
44

5-
It can be used with golangci-lint as a custom linter to provide feedback in editors or in CI runs.
5+
In your own .golangci.yaml configuration file, you can enable it like this:
6+
7+
```yaml
8+
version: "2"
9+
10+
linters:
11+
enable:
12+
- goworkflows
13+
14+
settings:
15+
custom:
16+
goworkflows:
17+
type: module
18+
original-url: github.com/cschleiden/go-workflows/analyzer
19+
```

analyzer/analyzer.go

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,55 @@ import (
44
"go/ast"
55
"go/types"
66

7+
"github.com/golangci/plugin-module-register/register"
78
"golang.org/x/tools/go/analysis"
89
"golang.org/x/tools/go/analysis/passes/inspect"
910
"golang.org/x/tools/go/ast/inspector"
1011
)
1112

12-
var checkPrivateReturnValues bool
13+
func init() {
14+
register.Plugin("goworkflows", New)
15+
}
1316

14-
func New() *analysis.Analyzer {
15-
a := &analysis.Analyzer{
16-
Name: "goworkflows",
17-
Doc: "Checks for common errors when writing workflows",
18-
Run: run,
19-
Requires: []*analysis.Analyzer{inspect.Analyzer},
17+
func New(settings any) (register.LinterPlugin, error) {
18+
// The configuration type will be map[string]any or []interface, it depends on your configuration.
19+
// You can use https://github.com/go-viper/mapstructure to convert map to struct.
20+
s, err := register.DecodeSettings[Settings](settings)
21+
if err != nil {
22+
return nil, err
2023
}
2124

22-
a.Flags.BoolVar(&checkPrivateReturnValues, "checkprivatereturnvalues", false, "Check return values of workflows which aren't exported")
25+
return &GoWorkflowsPlugin{Settings: s}, nil
26+
}
27+
28+
type GoWorkflowsPlugin struct {
29+
Settings Settings
30+
}
31+
32+
type Settings struct {
33+
CheckPrivateReturnValues bool `json:"checkprivatereturnvalues"`
34+
}
35+
36+
func (w *GoWorkflowsPlugin) BuildAnalyzers() ([]*analysis.Analyzer, error) {
37+
return []*analysis.Analyzer{
38+
{
39+
Name: "goworkflows",
40+
Doc: "Checks for common errors when writing workflows",
41+
Run: w.run,
42+
Requires: []*analysis.Analyzer{inspect.Analyzer},
43+
},
44+
}, nil
45+
}
46+
47+
func (w *GoWorkflowsPlugin) GetLoadMode() string {
48+
// NOTE: the mode can be `register.LoadModeSyntax` or `register.LoadModeTypesInfo`.
49+
// - `register.LoadModeSyntax`: if the linter doesn't use types information.
50+
// - `register.LoadModeTypesInfo`: if the linter uses types information.
2351

24-
return a
52+
return register.LoadModeSyntax
2553
}
2654

27-
func run(pass *analysis.Pass) (interface{}, error) {
55+
func (w *GoWorkflowsPlugin) run(pass *analysis.Pass) (interface{}, error) {
2856
inspector := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
2957

3058
// Expect workflows to be top level functions in a file. Therefore it should be enough to just keep track if the current
@@ -84,7 +112,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
84112
inWorkflow = true
85113

86114
// Check return types
87-
if n.Name.IsExported() || checkPrivateReturnValues {
115+
if n.Name.IsExported() || w.Settings.CheckPrivateReturnValues {
88116
if n.Type.Results == nil || len(n.Type.Results.List) == 0 {
89117
pass.Reportf(n.Pos(), "workflow `%v` doesn't return anything. needs to return at least `error`", n.Name.Name)
90118
} else {

analyzer/analyzer_test.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,39 @@ package analyzer
33
import (
44
"testing"
55

6+
"github.com/golangci/plugin-module-register/register"
67
"github.com/stretchr/testify/require"
78
"golang.org/x/tools/go/analysis/analysistest"
89
)
910

1011
func TestAll(t *testing.T) {
11-
a := New()
12-
a.Flags.Set("checkprivatereturnvalues", "true")
13-
analysistest.Run(t, analysistest.TestData(), a, "p", "q")
12+
newPlugin, err := register.GetPlugin("goworkflows")
13+
require.NoError(t, err)
14+
15+
plugin, err := newPlugin(map[string]any{
16+
"checkprivatereturnvalues": true,
17+
})
18+
require.NoError(t, err)
19+
20+
analyzers, err := plugin.BuildAnalyzers()
21+
require.NoError(t, err)
22+
23+
analysistest.Run(t, analysistest.TestData(), analyzers[0], "p", "q")
1424
}
1525

1626
func TestComplex(t *testing.T) {
17-
a := New()
18-
a.Flags.Set("checkprivatereturnvalues", "true")
19-
result := analysistest.Run(t, analysistest.TestData(), a, "q")
27+
newPlugin, err := register.GetPlugin("goworkflows")
28+
require.NoError(t, err)
29+
30+
plugin, err := newPlugin(map[string]any{
31+
"checkprivatereturnvalues": true,
32+
})
33+
require.NoError(t, err)
34+
35+
analyzers, err := plugin.BuildAnalyzers()
36+
require.NoError(t, err)
37+
38+
result := analysistest.Run(t, analysistest.TestData(), analyzers[0], "q")
2039
for _, r := range result {
2140
require.NoError(t, r.Err)
2241
require.Equal(t, 1, len(r.Diagnostics))

analyzer/go.mod

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module github.com/cschleiden/go-workflows/analyzer
2+
3+
go 1.24.5
4+
5+
require (
6+
github.com/golangci/plugin-module-register v0.1.1
7+
github.com/stretchr/testify v1.10.0
8+
golang.org/x/tools v0.31.0
9+
)
10+
11+
require (
12+
github.com/davecgh/go-spew v1.1.1 // indirect
13+
github.com/pmezard/go-difflib v1.0.0 // indirect
14+
golang.org/x/mod v0.24.0 // indirect
15+
golang.org/x/sync v0.12.0 // indirect
16+
gopkg.in/yaml.v3 v3.0.1 // indirect
17+
)

analyzer/go.sum

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/golangci/plugin-module-register v0.1.1 h1:TCmesur25LnyJkpsVrupv1Cdzo+2f7zX0H6Jkw1Ol6c=
4+
github.com/golangci/plugin-module-register v0.1.1/go.mod h1:TTpqoB6KkwOJMV8u7+NyXMrkwwESJLOkfl9TxR1DGFc=
5+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
6+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
7+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
10+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
11+
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
12+
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
13+
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
14+
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
15+
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
16+
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=
17+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
18+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
19+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
20+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

analyzer/plugin/plugin.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)