Skip to content

Commit dad4cb4

Browse files
committed
chore: upgrade golangci-lint to v2 and adapt the configuration
1 parent f201eed commit dad4cb4

File tree

16 files changed

+49
-218
lines changed

16 files changed

+49
-218
lines changed

.github/workflows/pr.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,22 @@ jobs:
3030
3131
# We already run the current golangci-lint in tests, but here we test
3232
# our GitHub action with the latest stable golangci-lint.
33-
golangci-lint:
34-
runs-on: ubuntu-latest
35-
steps:
36-
- uses: actions/checkout@v4
37-
- uses: actions/setup-go@v5
38-
with:
39-
# https://github.com/actions/setup-go#supported-version-syntax
40-
# ex:
41-
# - 1.18beta1 -> 1.18.0-beta.1
42-
# - 1.18rc1 -> 1.18.0-rc.1
43-
go-version: ${{ env.GO_VERSION }}
44-
- name: lint
45-
uses: golangci/[email protected]
46-
with:
47-
version: latest
33+
# **Important**: The v1 version of the action on GitHub does not support golang 1.25, so it needs to be disabled.
34+
# golangci-lint:
35+
# runs-on: ubuntu-latest
36+
# steps:
37+
# - uses: actions/checkout@v4
38+
# - uses: actions/setup-go@v5
39+
# with:
40+
# # https://github.com/actions/setup-go#supported-version-syntax
41+
# # ex:
42+
# # - 1.18beta1 -> 1.18.0-beta.1
43+
# # - 1.18rc1 -> 1.18.0-rc.1
44+
# go-version: ${{ env.GO_VERSION }}
45+
# - name: lint
46+
# uses: golangci/[email protected]
47+
# with:
48+
# version: latest
4849

4950
tests-on-windows:
5051
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
@@ -76,8 +77,8 @@ jobs:
7677
- ubuntu-latest
7778
- ubuntu-24.04-arm
7879
golang:
80+
- '1.23'
7981
- '1.24'
80-
- '1.25'
8182
runs-on: ${{ matrix.os }}
8283
steps:
8384
- uses: actions/checkout@v4

pkg/commands/internal/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (b Builder) getBinaryName() string {
243243

244244
func sanitizeVersion(v string) string {
245245
fn := func(c rune) bool {
246-
return !(unicode.IsLetter(c) || unicode.IsNumber(c) || c == '.' || c == '/')
246+
return !unicode.IsLetter(c) && !unicode.IsNumber(c) && c != '.' && c != '/'
247247
}
248248

249249
return strings.Join(strings.FieldsFunc(v, fn), "")

pkg/goformatters/gci/gci.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gci
22

33
import (
44
"context"
5-
"fmt"
65

76
gcicfg "github.com/daixiang0/gci/pkg/config"
87
"github.com/daixiang0/gci/pkg/gci"
@@ -41,14 +40,6 @@ func New(settings *config.GciSettings) (*Formatter, error) {
4140
ModPath: modPath,
4241
}
4342

44-
if settings.LocalPrefixes != "" {
45-
cfg.SectionStrings = []string{
46-
"standard",
47-
"default",
48-
fmt.Sprintf("prefix(%s)", settings.LocalPrefixes),
49-
}
50-
}
51-
5243
parsedCfg, err := cfg.Parse()
5344
if err != nil {
5445
return nil, err

pkg/golinters/errcheck/errcheck.go

Lines changed: 3 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
package errcheck
22

33
import (
4-
"bufio"
54
"cmp"
65
"fmt"
7-
"os"
8-
"os/user"
9-
"path/filepath"
106
"regexp"
11-
"strings"
127
"sync"
138

149
"github.com/kisielk/errcheck/errcheck"
1510
"golang.org/x/tools/go/analysis"
1611
"golang.org/x/tools/go/packages"
1712

1813
"github.com/golangci/golangci-lint/pkg/config"
19-
"github.com/golangci/golangci-lint/pkg/fsutils"
2014
"github.com/golangci/golangci-lint/pkg/goanalysis"
2115
"github.com/golangci/golangci-lint/pkg/golinters/internal"
2216
"github.com/golangci/golangci-lint/pkg/lint/linter"
@@ -43,19 +37,12 @@ func New(settings *config.ErrcheckSettings) *goanalysis.Linter {
4337
nil,
4438
).WithContextSetter(func(lintCtx *linter.Context) {
4539
// copied from errcheck
46-
checker, err := getChecker(settings)
47-
if err != nil {
48-
lintCtx.Log.Errorf("failed to get checker: %v", err)
49-
return
50-
}
40+
checker := getChecker(settings)
5141

5242
checker.Tags = lintCtx.Cfg.Run.BuildTags
5343

5444
analyzer.Run = func(pass *analysis.Pass) (any, error) {
5545
issues := runErrCheck(lintCtx, pass, checker)
56-
if err != nil {
57-
return nil, err
58-
}
5946

6047
if len(issues) == 0 {
6148
return nil, nil
@@ -109,41 +96,7 @@ func runErrCheck(lintCtx *linter.Context, pass *analysis.Pass, checker *errcheck
10996
return issues
11097
}
11198

112-
// parseIgnoreConfig was taken from errcheck in order to keep the API identical.
113-
// https://github.com/kisielk/errcheck/blob/1787c4bee836470bf45018cfbc783650db3c6501/main.go#L25-L60
114-
func parseIgnoreConfig(s string) (map[string]*regexp.Regexp, error) {
115-
if s == "" {
116-
return nil, nil
117-
}
118-
119-
cfg := map[string]*regexp.Regexp{}
120-
121-
for _, pair := range strings.Split(s, ",") {
122-
colonIndex := strings.Index(pair, ":")
123-
var pkg, re string
124-
if colonIndex == -1 {
125-
pkg = ""
126-
re = pair
127-
} else {
128-
pkg = pair[:colonIndex]
129-
re = pair[colonIndex+1:]
130-
}
131-
regex, err := regexp.Compile(re)
132-
if err != nil {
133-
return nil, err
134-
}
135-
cfg[pkg] = regex
136-
}
137-
138-
return cfg, nil
139-
}
140-
141-
func getChecker(errCfg *config.ErrcheckSettings) (*errcheck.Checker, error) {
142-
ignoreConfig, err := parseIgnoreConfig(errCfg.Ignore)
143-
if err != nil {
144-
return nil, fmt.Errorf("failed to parse 'ignore' directive: %w", err)
145-
}
146-
99+
func getChecker(errCfg *config.ErrcheckSettings) *errcheck.Checker {
147100
checker := errcheck.Checker{
148101
Exclusions: errcheck.Exclusions{
149102
BlankAssignments: !errCfg.CheckAssignToBlank,
@@ -156,114 +109,7 @@ func getChecker(errCfg *config.ErrcheckSettings) (*errcheck.Checker, error) {
156109
checker.Exclusions.Symbols = append(checker.Exclusions.Symbols, errcheck.DefaultExcludedSymbols...)
157110
}
158111

159-
for pkg, re := range ignoreConfig {
160-
checker.Exclusions.SymbolRegexpsByPackage[pkg] = re
161-
}
162-
163-
if errCfg.Exclude != "" {
164-
exclude, err := readExcludeFile(errCfg.Exclude)
165-
if err != nil {
166-
return nil, err
167-
}
168-
169-
checker.Exclusions.Symbols = append(checker.Exclusions.Symbols, exclude...)
170-
}
171-
172112
checker.Exclusions.Symbols = append(checker.Exclusions.Symbols, errCfg.ExcludeFunctions...)
173113

174-
return &checker, nil
175-
}
176-
177-
func getFirstPathArg() string {
178-
args := os.Args
179-
180-
// skip all args ([golangci-lint, run/linters]) before files/dirs list
181-
for len(args) != 0 {
182-
if args[0] == "run" {
183-
args = args[1:]
184-
break
185-
}
186-
187-
args = args[1:]
188-
}
189-
190-
// find first file/dir arg
191-
firstArg := "./..."
192-
for _, arg := range args {
193-
if !strings.HasPrefix(arg, "-") {
194-
firstArg = arg
195-
break
196-
}
197-
}
198-
199-
return firstArg
200-
}
201-
202-
func setupConfigFileSearch(name string) []string {
203-
if strings.HasPrefix(name, "~") {
204-
if u, err := user.Current(); err == nil {
205-
name = strings.Replace(name, "~", u.HomeDir, 1)
206-
}
207-
}
208-
209-
if filepath.IsAbs(name) {
210-
return []string{name}
211-
}
212-
213-
firstArg := getFirstPathArg()
214-
215-
absStartPath, err := filepath.Abs(firstArg)
216-
if err != nil {
217-
absStartPath = filepath.Clean(firstArg)
218-
}
219-
220-
// start from it
221-
var curDir string
222-
if fsutils.IsDir(absStartPath) {
223-
curDir = absStartPath
224-
} else {
225-
curDir = filepath.Dir(absStartPath)
226-
}
227-
228-
// find all dirs from it up to the root
229-
configSearchPaths := []string{filepath.Join(".", name)}
230-
for {
231-
configSearchPaths = append(configSearchPaths, filepath.Join(curDir, name))
232-
newCurDir := filepath.Dir(curDir)
233-
if curDir == newCurDir || newCurDir == "" {
234-
break
235-
}
236-
curDir = newCurDir
237-
}
238-
239-
return configSearchPaths
240-
}
241-
242-
func readExcludeFile(name string) ([]string, error) {
243-
var err error
244-
var fh *os.File
245-
246-
for _, path := range setupConfigFileSearch(name) {
247-
if fh, err = os.Open(path); err == nil {
248-
break
249-
}
250-
}
251-
252-
if fh == nil {
253-
return nil, fmt.Errorf("failed reading exclude file: %s: %w", name, err)
254-
}
255-
defer func() { _ = fh.Close() }()
256-
257-
scanner := bufio.NewScanner(fh)
258-
259-
var excludes []string
260-
for scanner.Scan() {
261-
excludes = append(excludes, scanner.Text())
262-
}
263-
264-
if err := scanner.Err(); err != nil {
265-
return nil, fmt.Errorf("failed scanning file: %s: %w", name, err)
266-
}
267-
268-
return excludes, nil
114+
return &checker
269115
}

pkg/golinters/godot/godot.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ func New(settings *config.GodotSettings) *goanalysis.Linter {
2222
Period: settings.Period,
2323
Capital: settings.Capital,
2424
}
25-
26-
// Convert deprecated setting
27-
if settings.CheckAll != nil && *settings.CheckAll {
28-
dotSettings.Scope = godot.AllScope
29-
}
3025
}
3126

3227
dotSettings.Scope = cmp.Or(dotSettings.Scope, godot.DeclScope)

pkg/golinters/gofumpt/gofumpt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func New(settings *config.GofumptSettings) *goanalysis.Linter {
1616
a := goformatters.NewAnalyzer(
1717
internal.LinterLogger.Child(linterName),
1818
"Checks if code and import statements are formatted, with additional rules.",
19-
gofumptbase.New(settings, settings.LangVersion),
19+
gofumptbase.New(settings, ""),
2020
)
2121

2222
return goanalysis.NewLinter(

pkg/golinters/govet/govet.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,6 @@ func isAnalyzerEnabled(name string, cfg *config.GovetSettings, defaultAnalyzers
189189
return false
190190
}
191191

192-
// Keeping for backward compatibility.
193-
if cfg.CheckShadowing != nil && *cfg.CheckShadowing && name == shadow.Analyzer.Name {
194-
return true
195-
}
196-
197192
switch {
198193
case cfg.EnableAll:
199194
return !slices.Contains(cfg.Disable, name)

pkg/lint/package.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ type PackageLoader struct {
3939
}
4040

4141
// NewPackageLoader creates a new PackageLoader.
42-
func NewPackageLoader(log logutils.Log, cfg *config.Config, args []string, goenv *goutil.Env, loadGuard *load.Guard) *PackageLoader {
42+
func NewPackageLoader(log logutils.Log, cfg *config.Config, args []string, goEnv *goutil.Env, loadGuard *load.Guard) *PackageLoader {
4343
return &PackageLoader{
4444
cfg: cfg,
4545
args: args,
4646
log: log,
4747
debugf: logutils.Debug(logutils.DebugKeyLoader),
48-
goenv: goenv,
48+
goenv: goEnv,
4949
pkgTestIDRe: regexp.MustCompile(`^(.*) \[(.*)\.test\]`),
5050
loadGuard: loadGuard,
5151
}

scripts/gen_github_action_config/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module github.com/golangci/golangci-lint/scripts/gen_github_action_config
33
go 1.25.0
44

55
require (
6-
github.com/shurcooL/githubv4 v0.0.0-20240429030203-be2daab69064
6+
github.com/shurcooL/githubv4 v0.0.0-20240727222349-48295856cce7
77
github.com/stretchr/testify v1.10.0
8-
golang.org/x/oauth2 v0.28.0
8+
golang.org/x/oauth2 v0.30.0
99
)
1010

1111
require (

scripts/gen_github_action_config/go.sum

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)