Skip to content

Commit ddf0285

Browse files
committed
Exclude types defined in generated files; update go version; make basic check the default; refactor
Signed-off-by: Oliver Eikemeier <[email protected]>
1 parent 298450d commit ddf0285

Some content is hidden

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

52 files changed

+1031
-482
lines changed

.github/workflows/test.yml

+14-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name: Test
99
- main
1010
jobs:
1111
test:
12-
name: Test on Go ${{ matrix.go-version }}
12+
name: Test on Go ${{ matrix.go }}
1313
permissions:
1414
checks: write
1515
contents: read
@@ -18,29 +18,34 @@ jobs:
1818
runs-on: ubuntu-24.04
1919
strategy:
2020
matrix:
21-
go-version: ["1.24.0-rc.3", "1.23.6", "1.22.12"]
21+
go: ["1.24", "1.23"]
2222
include:
23-
- go-version: "1.23.6"
23+
- go: "1.24"
24+
go-version: "1.24.2"
2425
update-coverage: true
26+
- go: "1.23"
27+
go-version: "1.23.8"
2528
env:
2629
GOTOOLCHAIN: local
2730
steps:
2831
- name: ✔ Check out
29-
uses: actions/checkout@v4
32+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3033
- name: 🐹 Set up Go ${{ matrix.go-version }}
31-
uses: actions/setup-go@v5
34+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
3235
with:
3336
go-version: ${{ matrix.go-version }}
3437
- name: 🧸 golangci-lint
35-
uses: golangci/golangci-lint-action@v6
38+
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
3639
with:
37-
version: v1.63.4
40+
version: v2.0.2
3841
- name: 🔨 Test
3942
run: |
40-
go get -C ./pkg/analyzer/testdata golang.org/x/exp/errors
43+
(cd ./pkg/internal/visitor/testdata && go mod download)
4144
go test -coverprofile=cover.out ./...
45+
env:
46+
GOEXPERIMENT: aliastypeparams
4247
- name: 🧑🏻‍💻 codecov
43-
uses: codecov/codecov-action@v5
48+
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0
4449
if: ${{ matrix.update-coverage }}
4550
with:
4651
files: ./cover.out

.golangci.yaml

+78-42
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
---
2+
version: "2"
3+
24
run:
35
modules-download-mode: readonly
6+
7+
formatters:
8+
enable:
9+
- gofumpt
10+
settings:
11+
gofumpt:
12+
module-path: fillmore-labs.com/zerolint
13+
414
linters:
5-
enable-all: true
15+
default: all
616
disable:
7-
# deprecated
8-
- exportloopref
9-
# disabled
1017
- depguard
1118
- dupl
1219
- exhaustruct
@@ -15,41 +22,70 @@ linters:
1522
- varnamelen
1623
- wrapcheck
1724
- wsl
18-
linters-settings:
19-
govet:
20-
enable-all: true
21-
disable:
22-
- fieldalignment
23-
settings:
24-
shadow:
25-
strict: true
26-
testifylint:
27-
enable-all: true
28-
disable:
29-
- require-error
30-
ireturn:
31-
allow:
32-
- anon
33-
- error
34-
- empty
35-
- stdlib
36-
- generic
37-
predeclared:
38-
ignore: "new"
39-
issues:
40-
exclude-rules:
41-
- path: _test\.go$
42-
linters:
43-
- revive
44-
text: "dot-imports"
45-
- path: _test\.go$
46-
linters:
47-
- govet
48-
text: "lostcancel"
49-
- path: ^main\.go$
50-
linters:
51-
- gocheckcompilerdirectives
52-
text: "go:debug"
53-
- linters:
54-
- govet
55-
text: '^shadow: declaration of "(ctx|err|ok)" shadows declaration at line \d+$'
25+
settings:
26+
errcheck:
27+
exclude-functions:
28+
- (io/fs.File).Close
29+
govet:
30+
enable-all: true
31+
disable:
32+
- fieldalignment
33+
settings:
34+
shadow:
35+
strict: true
36+
testifylint:
37+
enable-all: true
38+
disable:
39+
- require-error
40+
ireturn:
41+
allow:
42+
- anon
43+
- error
44+
- empty
45+
- stdlib
46+
- generic
47+
predeclared:
48+
ignore: ["new"]
49+
revive:
50+
rules:
51+
- name: atomic
52+
- name: blank-imports
53+
- name: context-as-argument
54+
- name: context-keys-type
55+
- name: dot-imports
56+
exclude: ["TEST"]
57+
- name: early-return
58+
- name: error-return
59+
- name: error-strings
60+
- name: error-naming
61+
- name: exported
62+
- name: increment-decrement
63+
- name: var-naming
64+
- name: var-declaration
65+
- name: range
66+
- name: receiver-naming
67+
- name: time-naming
68+
- name: unexported-return
69+
- name: indent-error-flow
70+
- name: errorf
71+
- name: empty-block
72+
- name: superfluous-else
73+
- name: unused-parameter
74+
- name: unreachable-code
75+
- name: redefines-builtin-id
76+
- name: file-header
77+
arguments:
78+
- "Copyright 2024 Oliver Eikemeier. All Rights Reserved."
79+
exclusions:
80+
rules:
81+
- path: _test\.go$
82+
linters:
83+
- govet
84+
text: "lostcancel"
85+
- path: ^main\.go$
86+
linters:
87+
- gocheckcompilerdirectives
88+
text: "go:debug"
89+
- linters:
90+
- govet
91+
text: '^shadow: declaration of "(ctx|err|ok)" shadows declaration at line \d+$'

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Usage: `zerolint [-flag] [package]`
2020
Flags:
2121

2222
- **-c** int display offending line with this many lines of context (default -1)
23-
- **-basic** basic analysis only
23+
- **-full** full analysis
2424
- **-excluded** `<filename>` read excluded types from this file
2525
- **-zerotrace** trace found zero-sized types
2626
- **-fix** apply all suggested fixes
27+
- **-generated** analyze generated files and types defined in generated files

go.mod

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module fillmore-labs.com/zerolint
22

3-
go 1.22.0
3+
go 1.23.0
44

5-
toolchain go1.23.6
5+
toolchain go1.24.2
66

7-
require golang.org/x/tools v0.29.0
7+
require golang.org/x/tools v0.31.0
88

99
require (
10-
golang.org/x/mod v0.23.0 // indirect
11-
golang.org/x/sync v0.11.0 // indirect
10+
golang.org/x/mod v0.24.0 // indirect
11+
golang.org/x/sync v0.13.0 // indirect
1212
)

go.sum

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
22
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3-
golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
4-
golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
5-
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
6-
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
7-
golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE=
8-
golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588=
3+
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
4+
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
5+
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
6+
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
7+
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
8+
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=

main.go

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
//
1515
// SPDX-License-Identifier: Apache-2.0
1616

17-
//go:debug gotypesalias=1
18-
1917
// This is the main program for the zerolint linter.
2018
package main
2119

pkg/analyzer/analyzer.go

+18-15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//
1515
// SPDX-License-Identifier: Apache-2.0
1616

17+
//nolint:gochecknoglobals
1718
package analyzer
1819

1920
import (
@@ -22,6 +23,7 @@ import (
2223
"golang.org/x/tools/go/analysis/passes/inspect"
2324
)
2425

26+
// Documentation constants.
2527
const (
2628
Name = "zerolint"
2729
Doc = `checks for usage of pointers to zero-length variables
@@ -30,35 +32,36 @@ Pointer to zero-length variables carry very little information and
3032
can often be avoided.`
3133
)
3234

33-
var Analyzer = &analysis.Analyzer{ //nolint:gochecknoglobals
35+
// Analyzer checks for usage of pointers to zero-length variables.
36+
var Analyzer = &analysis.Analyzer{
3437
Name: Name,
3538
Doc: Doc,
3639
URL: "https://pkg.go.dev/fillmore-labs.com/zerolint/pkg/analyzer",
3740
Run: run,
3841
Requires: []*analysis.Analyzer{inspect.Analyzer},
3942
}
4043

41-
func init() { //nolint:gochecknoinits
42-
Analyzer.Flags.StringVar(&Excludes, "excluded", "", "read excluded types from this file")
43-
Analyzer.Flags.BoolVar(&ZeroTrace, "zerotrace", false, "trace found zero-sized types")
44-
Analyzer.Flags.BoolVar(&Basic, "basic", false, "basic analysis only")
45-
Analyzer.Flags.BoolVar(&Generated, "generated", false, "check generated files")
46-
}
47-
4844
var (
49-
// Excludes is a list of types to exclude from the analysis.
50-
Excludes string //nolint:gochecknoglobals
45+
// Excludes is a file containing a list of types to exclude from the analysis.
46+
Excludes string
5147

5248
// ZeroTrace enables tracing of found zero-sized types.
53-
ZeroTrace bool //nolint:gochecknoglobals
49+
ZeroTrace bool
5450

55-
// Basic enables basic analysis only.
56-
Basic bool //nolint:gochecknoglobals
51+
// Full enables full analysis, which should be handles manually.
52+
Full bool
5753

5854
// Generated enables checking generated files.
59-
Generated bool //nolint:gochecknoglobals
55+
Generated bool
6056
)
6157

58+
func init() { //nolint:gochecknoinits
59+
Analyzer.Flags.StringVar(&Excludes, "excluded", "", "read excluded types from this file")
60+
Analyzer.Flags.BoolVar(&ZeroTrace, "zerotrace", false, "trace found zero-sized types")
61+
Analyzer.Flags.BoolVar(&Full, "full", false, "full analysis")
62+
Analyzer.Flags.BoolVar(&Generated, "generated", false, "check generated files")
63+
}
64+
6265
// run applies the analyzer to a package.
6366
func run(pass *analysis.Pass) (any, error) {
6467
// Read the list of excluded types from the file specified by the "excluded" flag.
@@ -70,7 +73,7 @@ func run(pass *analysis.Pass) (any, error) {
7073
return NewRun(
7174
WithExcludes(ex),
7275
WithZeroTrace(ZeroTrace),
73-
WithBasic(Basic),
76+
WithFull(Full),
7477
WithGenerated(Generated),
7578
)(pass)
7679
}

pkg/analyzer/analyzer_test.go

+20-15
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,27 @@ import (
2323
"golang.org/x/tools/go/analysis/analysistest"
2424
)
2525

26-
func TestAnalyzer(t *testing.T) { //nolint:paralleltest
27-
dir := analysistest.TestData()
28-
a := analyzer.Analyzer
29-
30-
analyzer.Basic = false
31-
analyzer.Excludes = dir + "/excluded.txt"
26+
func TestAnalyzer(t *testing.T) { //nolint:tparallel
27+
t.Parallel()
3228

33-
analysistest.RunWithSuggestedFixes(t, dir, a, "go.test/a")
34-
}
35-
36-
func TestAnalyzerBasic(t *testing.T) { //nolint:paralleltest
3729
dir := analysistest.TestData()
38-
a := analyzer.Analyzer
39-
40-
analyzer.Basic = true
41-
analyzer.Excludes = ""
4230

43-
analysistest.RunWithSuggestedFixes(t, dir, a, "go.test/basic")
31+
type args struct {
32+
excludes string
33+
}
34+
tests := []struct {
35+
name string
36+
args args
37+
}{
38+
{"basic", args{dir + "/excluded.txt"}},
39+
}
40+
41+
for _, tt := range tests { //nolint:paralleltest
42+
a := analyzer.Analyzer
43+
analyzer.Excludes = tt.args.excludes
44+
45+
t.Run(tt.name, func(t *testing.T) {
46+
analysistest.Run(t, dir, a, "go.test/basic")
47+
})
48+
}
4449
}

pkg/analyzer/osfs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ type osFS struct{}
2626
var _ fs.FS = osFS{}
2727

2828
func (osFS) Open(name string) (fs.File, error) {
29-
return os.Open(name)
29+
return os.Open(name) //nolint:gosec
3030
}

0 commit comments

Comments
 (0)