Skip to content

Commit bca29eb

Browse files
Merge pull request #169 from github/ls/golangci-lint-v2
Require Go 1.26 and lint with golangci-lint v2
2 parents 024d2ed + 5d68b1e commit bca29eb

14 files changed

Lines changed: 105 additions & 467 deletions

File tree

‎.github/workflows/lint.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Set up Go
2424
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
2525
with:
26-
go-version: 1.17
26+
go-version: '1.27.4'
2727

2828
- name: Check out code
2929
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -33,7 +33,7 @@ jobs:
3333
go mod verify
3434
go mod download
3535
36-
LINT_VERSION=1.43.0
36+
LINT_VERSION=2.15.0
3737
curl -fsSL https://github.com/golangci/golangci-lint/releases/download/v${LINT_VERSION}/golangci-lint-${LINT_VERSION}-linux-amd64.tar.gz | \
3838
tar xz --strip-components 1 --wildcards \*/golangci-lint
3939
mkdir -p bin && mv golangci-lint bin/
@@ -54,6 +54,6 @@ jobs:
5454
assert-nothing-changed go fmt ./...
5555
assert-nothing-changed go mod tidy
5656
57-
bin/golangci-lint run --out-format=github-actions --timeout=3m || STATUS=$?
57+
bin/golangci-lint run --timeout=3m || STATUS=$?
5858
5959
exit $STATUS

‎.golangci.toml‎

Lines changed: 62 additions & 395 deletions
Large diffs are not rendered by default.

‎git-sizer.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func main() {
123123
}
124124

125125
func mainImplementation(ctx context.Context, stdout, stderr io.Writer, args []string) error {
126-
var nameStyle sizes.NameStyle = sizes.NameStyleFull
126+
nameStyle := sizes.NameStyleFull
127127
var cpuprofile string
128128
var jsonOutput bool
129129
var jsonVersion int
@@ -219,7 +219,7 @@ func mainImplementation(ctx context.Context, stdout, stderr io.Writer, args []st
219219
}
220220

221221
if cpuprofile != "" {
222-
f, err := os.Create(cpuprofile)
222+
f, err := os.Create(cpuprofile) //nolint:gosec // The user chooses the path.
223223
if err != nil {
224224
return fmt.Errorf("couldn't set up cpuprofile file: %w", err)
225225
}
@@ -249,10 +249,10 @@ func mainImplementation(ctx context.Context, stdout, stderr io.Writer, args []st
249249
return err
250250
}
251251
jsonVersion = v
252-
if !(jsonVersion == 1 || jsonVersion == 2) {
252+
if jsonVersion != 1 && jsonVersion != 2 {
253253
return fmt.Errorf("JSON version (read from gitconfig) must be 1 or 2")
254254
}
255-
} else if !(jsonVersion == 1 || jsonVersion == 2) {
255+
} else if jsonVersion != 1 && jsonVersion != 2 {
256256
return fmt.Errorf("JSON version must be 1 or 2")
257257
}
258258
}

‎git/git.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"os/exec"
1010
"path/filepath"
11+
"slices"
1112
)
1213

1314
// ObjectType represents the type of a Git object ("blob", "tree",
@@ -133,17 +134,15 @@ func (repo *Repository) IsFull() (bool, error) {
133134
}
134135

135136
func (repo *Repository) GitCommand(callerArgs ...string) *exec.Cmd {
136-
args := []string{
137+
args := slices.Concat([]string{
137138
// Disable replace references when running our commands:
138139
"--no-replace-objects",
139140

140141
// Disable the warning that grafts are deprecated, since we
141142
// want to set the grafts file to `/dev/null` below (to
142143
// disable grafts even where they are supported):
143144
"-c", "advice.graftFileDeprecated=false",
144-
}
145-
146-
args = append(args, callerArgs...)
145+
}, callerArgs)
147146

148147
//nolint:gosec // `gitBin` is chosen carefully, and the rest of
149148
// the args have been checked.

‎git/gitconfig.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ func (config *Config) FullKey(key string) string {
9090
// a component boundary (i.e., at a '.'). If yes, it returns `true`
9191
// and the part of the key after the prefix; e.g.:
9292
//
93-
// configKeyMatchesPrefix("foo.bar", "foo") → true, "bar"
94-
// configKeyMatchesPrefix("foo.bar", "foo.") → true, "bar"
95-
// configKeyMatchesPrefix("foo.bar", "foo.bar") → true, ""
96-
// configKeyMatchesPrefix("foo.bar", "foo.bar.") → false, ""
93+
// configKeyMatchesPrefix("foo.bar", "foo") → true, "bar"
94+
// configKeyMatchesPrefix("foo.bar", "foo.") → true, "bar"
95+
// configKeyMatchesPrefix("foo.bar", "foo.bar") → true, ""
96+
// configKeyMatchesPrefix("foo.bar", "foo.bar.") → false, ""
9797
func configKeyMatchesPrefix(key, prefix string) (bool, string) {
9898
if prefix == "" {
9999
return true, key

‎git/ref_filter.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ func (f intersection) Filter(refname string) bool {
3636
// If `f1` is `nil`, it is treated as including nothing.
3737
type include struct{}
3838

39-
func (_ include) Combine(f1, f2 ReferenceFilter) ReferenceFilter {
39+
func (include) Combine(f1, f2 ReferenceFilter) ReferenceFilter {
4040
if f1 == nil {
4141
return f2
4242
}
4343
return union{f1, f2}
4444
}
4545

46-
func (_ include) Inverted() Combiner {
46+
func (include) Inverted() Combiner {
4747
return Exclude
4848
}
4949

@@ -61,31 +61,31 @@ func (f union) Filter(refname string) bool {
6161
// If `f1` is `nil`, it is treated as including everything.
6262
type exclude struct{}
6363

64-
func (_ exclude) Combine(f1, f2 ReferenceFilter) ReferenceFilter {
64+
func (exclude) Combine(f1, f2 ReferenceFilter) ReferenceFilter {
6565
if f1 == nil {
6666
return inverse{f2}
6767
}
6868
return intersection{f1, inverse{f2}}
6969

7070
}
7171

72-
func (_ exclude) Inverted() Combiner {
72+
func (exclude) Inverted() Combiner {
7373
return include{}
7474
}
7575

7676
var Exclude exclude
7777

7878
type allReferencesFilter struct{}
7979

80-
func (_ allReferencesFilter) Filter(_ string) bool {
80+
func (allReferencesFilter) Filter(_ string) bool {
8181
return true
8282
}
8383

8484
var AllReferencesFilter allReferencesFilter
8585

8686
type noReferencesFilter struct{}
8787

88-
func (_ noReferencesFilter) Filter(_ string) bool {
88+
func (noReferencesFilter) Filter(_ string) bool {
8989
return false
9090
}
9191

‎git/reference.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Reference struct {
2727
// `Reference`. It is assumed that `line` is formatted like the output
2828
// of
2929
//
30-
// git for-each-ref --format='%(objectname) %(objecttype) %(objectsize) %(refname)'
30+
// git for-each-ref --format='%(objectname) %(objecttype) %(objectsize) %(refname)'
3131
func ParseReference(line string) (Reference, error) {
3232
words := strings.Split(line, " ")
3333
if len(words) != 4 {

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/github/git-sizer
22

3-
go 1.17
3+
go 1.26
44

55
require (
66
github.com/cli/safeexec v1.0.0

‎go.sum‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI=
22
github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
3-
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
43
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
54
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
65
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -23,36 +22,10 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
2322
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
2423
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
2524
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
26-
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
2725
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
2826
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
29-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
30-
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
31-
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
32-
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
33-
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
34-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
35-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
36-
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
37-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
38-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3927
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
4028
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
41-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
42-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
43-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
44-
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
45-
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
46-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
47-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
48-
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
49-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
50-
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
51-
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
52-
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
53-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
54-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
55-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5629
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5730
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
5831
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

‎internal/refopts/filter_value.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ func (v *filterValue) Set(s string) error {
7474

7575
// Interpret an option argument flexibly:
7676
//
77-
// * If it is bracketed with `/` characters, treat it as a regexp.
77+
// - If it is bracketed with `/` characters, treat it as a regexp.
7878
//
79-
// * If it starts with `@`, then consider it a refgroup name. That
80-
// refgroup must already be defined. Use its filter. This construct
81-
// is only allowed at the top level.
79+
// - If it starts with `@`, then consider it a refgroup name. That
80+
// refgroup must already be defined. Use its filter. This construct
81+
// is only allowed at the top level.
8282
//
83-
// * Otherwise treat it as a prefix.
83+
// - Otherwise treat it as a prefix.
8484
func (v *filterValue) interpretFlexibly(s string) (git.ReferenceFilter, error) {
8585
if len(s) >= 2 && strings.HasPrefix(s, "/") && strings.HasSuffix(s, "/") {
8686
pattern := s[1 : len(s)-1]

0 commit comments

Comments
 (0)