Skip to content

Commit 35e8062

Browse files
committed
chore: enable unused-parameter from revive
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent b7932a9 commit 35e8062

Some content is hidden

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

76 files changed

+524
-497
lines changed

.github/workflows/lint.yml

+30-1
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,41 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
os: [ubuntu-latest, windows-latest, macos-latest]
15+
include:
16+
- {os: macos-latest, GOOS: darwin, GOARCH: amd64}
17+
- {os: macos-latest, GOOS: darwin, GOARCH: arm64}
18+
- {os: ubuntu-latest, GOOS: dragonfly, GOARCH: amd64}
19+
- {os: ubuntu-latest, GOOS: freebsd, GOARCH: amd64}
20+
- {os: ubuntu-latest, GOOS: freebsd, GOARCH: 386}
21+
- {os: ubuntu-latest, GOOS: freebsd, GOARCH: arm}
22+
- {os: ubuntu-latest, GOOS: linux, GOARCH: 386}
23+
- {os: ubuntu-latest, GOOS: linux, GOARCH: amd64}
24+
- {os: ubuntu-latest, GOOS: linux, GOARCH: arm64}
25+
- {os: ubuntu-latest, GOOS: linux, GOARCH: arm}
26+
- {os: ubuntu-latest, GOOS: linux, GOARCH: mips64}
27+
- {os: ubuntu-latest, GOOS: linux, GOARCH: mips64le}
28+
- {os: ubuntu-latest, GOOS: linux, GOARCH: mips}
29+
- {os: ubuntu-latest, GOOS: linux, GOARCH: mipsle}
30+
- {os: ubuntu-latest, GOOS: linux, GOARCH: ppc64le}
31+
- {os: ubuntu-latest, GOOS: linux, GOARCH: ppc64}
32+
- {os: ubuntu-latest, GOOS: linux, GOARCH: riscv64}
33+
- {os: ubuntu-latest, GOOS: linux, GOARCH: s390x}
34+
- {os: ubuntu-latest, GOOS: netbsd, GOARCH: amd64}
35+
- {os: ubuntu-latest, GOOS: openbsd, GOARCH: 386}
36+
- {os: ubuntu-latest, GOOS: openbsd, GOARCH: amd64}
37+
- {os: ubuntu-latest, GOOS: plan9, GOARCH: amd64}
38+
- {os: ubuntu-latest, GOOS: plan9, GOARCH: 386}
39+
- {os: ubuntu-latest, GOOS: solaris, GOARCH: amd64}
40+
- {os: windows-latest, GOOS: windows, GOARCH: amd64}
41+
- {os: windows-latest, GOOS: windows, GOARCH: 386}
1642
permissions:
1743
contents: read # for actions/checkout to fetch code
1844
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
1945
name: lint
2046
runs-on: ${{ matrix.os }}
47+
env:
48+
GOARCH: ${{ matrix.GOARCH }}
49+
GOOS: ${{ matrix.GOOS }}
2150
steps:
2251
- name: Checkout repository
2352
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

.golangci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ linters-settings:
9494
disabled: true
9595
- name: unreachable-code
9696
- name: unused-parameter
97-
disabled: true
9897
- name: use-any
9998
- name: var-declaration
10099
- name: var-naming

cpu/cpu_darwin.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func Times(percpu bool) ([]TimesStat, error) {
5959
return TimesWithContext(context.Background(), percpu)
6060
}
6161

62-
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
62+
func TimesWithContext(_ context.Context, percpu bool) ([]TimesStat, error) {
6363
lib, err := common.NewLibrary(common.System)
6464
if err != nil {
6565
return nil, err
@@ -78,7 +78,7 @@ func Info() ([]InfoStat, error) {
7878
return InfoWithContext(context.Background())
7979
}
8080

81-
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
81+
func InfoWithContext(_ context.Context) ([]InfoStat, error) {
8282
var ret []InfoStat
8383

8484
c := InfoStat{}
@@ -121,7 +121,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
121121
return append(ret, c), nil
122122
}
123123

124-
func CountsWithContext(ctx context.Context, logical bool) (int, error) {
124+
func CountsWithContext(_ context.Context, logical bool) (int, error) {
125125
var cpuArgument string
126126
if logical {
127127
cpuArgument = "hw.logicalcpu"

cpu/cpu_dragonfly.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
"strings"
1212
"unsafe"
1313

14-
"github.com/shirou/gopsutil/v4/internal/common"
1514
"github.com/tklauser/go-sysconf"
1615
"golang.org/x/sys/unix"
16+
17+
"github.com/shirou/gopsutil/v4/internal/common"
1718
)
1819

1920
var (
@@ -50,7 +51,7 @@ func Times(percpu bool) ([]TimesStat, error) {
5051
return TimesWithContext(context.Background(), percpu)
5152
}
5253

53-
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
54+
func TimesWithContext(_ context.Context, percpu bool) ([]TimesStat, error) {
5455
if percpu {
5556
buf, err := unix.SysctlRaw("kern.cp_times")
5657
if err != nil {
@@ -91,7 +92,7 @@ func Info() ([]InfoStat, error) {
9192
return InfoWithContext(context.Background())
9293
}
9394

94-
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
95+
func InfoWithContext(_ context.Context) ([]InfoStat, error) {
9596
const dmesgBoot = "/var/run/dmesg.boot"
9697

9798
c, err := parseDmesgBoot(dmesgBoot)
@@ -135,7 +136,7 @@ func parseDmesgBoot(fileName string) (InfoStat, error) {
135136
c.VendorID = matches[1]
136137
t, err := strconv.ParseInt(matches[2], 10, 32)
137138
if err != nil {
138-
return c, fmt.Errorf("unable to parse DragonflyBSD CPU stepping information from %q: %v", line, err)
139+
return c, fmt.Errorf("unable to parse DragonflyBSD CPU stepping information from %q: %w", line, err)
139140
}
140141
c.Stepping = int32(t)
141142
} else if matches := featuresMatch.FindStringSubmatch(line); matches != nil {
@@ -152,6 +153,6 @@ func parseDmesgBoot(fileName string) (InfoStat, error) {
152153
return c, nil
153154
}
154155

155-
func CountsWithContext(ctx context.Context, logical bool) (int, error) {
156+
func CountsWithContext(_ context.Context, _ bool) (int, error) {
156157
return runtime.NumCPU(), nil
157158
}

cpu/cpu_freebsd.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func Times(percpu bool) ([]TimesStat, error) {
5252
return TimesWithContext(context.Background(), percpu)
5353
}
5454

55-
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
55+
func TimesWithContext(_ context.Context, percpu bool) ([]TimesStat, error) {
5656
if percpu {
5757
buf, err := unix.SysctlRaw("kern.cp_times")
5858
if err != nil {
@@ -93,7 +93,7 @@ func Info() ([]InfoStat, error) {
9393
return InfoWithContext(context.Background())
9494
}
9595

96-
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
96+
func InfoWithContext(_ context.Context) ([]InfoStat, error) {
9797
const dmesgBoot = "/var/run/dmesg.boot"
9898

9999
c, num, err := parseDmesgBoot(dmesgBoot)
@@ -165,6 +165,6 @@ func parseDmesgBoot(fileName string) (InfoStat, int, error) {
165165
return c, cpuNum, nil
166166
}
167167

168-
func CountsWithContext(ctx context.Context, logical bool) (int, error) {
168+
func CountsWithContext(_ context.Context, _ bool) (int, error) {
169169
return runtime.NumCPU(), nil
170170
}

cpu/cpu_netbsd.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Times(percpu bool) ([]TimesStat, error) {
3636
return TimesWithContext(context.Background(), percpu)
3737
}
3838

39-
func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err error) {
39+
func TimesWithContext(_ context.Context, percpu bool) (ret []TimesStat, err error) {
4040
if !percpu {
4141
mib := []int32{ctlKern, kernCpTime}
4242
buf, _, err := common.CallSyscall(mib)
@@ -57,7 +57,7 @@ func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err er
5757

5858
ncpu, err := unix.SysctlUint32("hw.ncpu")
5959
if err != nil {
60-
return
60+
return //nolint:nakedret //FIXME
6161
}
6262

6363
var i uint32
@@ -87,7 +87,7 @@ func Info() ([]InfoStat, error) {
8787
return InfoWithContext(context.Background())
8888
}
8989

90-
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
90+
func InfoWithContext(_ context.Context) ([]InfoStat, error) {
9191
var ret []InfoStat
9292
var err error
9393

@@ -115,6 +115,6 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
115115
return append(ret, c), nil
116116
}
117117

118-
func CountsWithContext(ctx context.Context, logical bool) (int, error) {
118+
func CountsWithContext(_ context.Context, _ bool) (int, error) {
119119
return runtime.NumCPU(), nil
120120
}

cpu/cpu_openbsd.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import (
99
"runtime"
1010
"unsafe"
1111

12-
"github.com/shirou/gopsutil/v4/internal/common"
1312
"github.com/tklauser/go-sysconf"
1413
"golang.org/x/sys/unix"
14+
15+
"github.com/shirou/gopsutil/v4/internal/common"
1516
)
1617

1718
const (
@@ -53,7 +54,7 @@ func Times(percpu bool) ([]TimesStat, error) {
5354
return TimesWithContext(context.Background(), percpu)
5455
}
5556

56-
func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err error) {
57+
func TimesWithContext(_ context.Context, percpu bool) (ret []TimesStat, err error) {
5758
if !percpu {
5859
mib := []int32{ctlKern, kernCpTime}
5960
buf, _, err := common.CallSyscall(mib)
@@ -74,7 +75,7 @@ func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err er
7475

7576
ncpu, err := unix.SysctlUint32("hw.ncpu")
7677
if err != nil {
77-
return
78+
return //nolint:nakedret //FIXME
7879
}
7980

8081
var i uint32
@@ -107,7 +108,7 @@ func Info() ([]InfoStat, error) {
107108
return InfoWithContext(context.Background())
108109
}
109110

110-
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
111+
func InfoWithContext(_ context.Context) ([]InfoStat, error) {
111112
var ret []InfoStat
112113
var err error
113114

@@ -132,6 +133,6 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
132133
return append(ret, c), nil
133134
}
134135

135-
func CountsWithContext(ctx context.Context, logical bool) (int, error) {
136+
func CountsWithContext(_ context.Context, _ bool) (int, error) {
136137
return runtime.NumCPU(), nil
137138
}

cpu/cpu_plan9.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import (
99
"runtime"
1010

1111
stats "github.com/lufia/plan9stats"
12+
1213
"github.com/shirou/gopsutil/v4/internal/common"
1314
)
1415

1516
func Times(percpu bool) ([]TimesStat, error) {
1617
return TimesWithContext(context.Background(), percpu)
1718
}
1819

19-
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
20+
func TimesWithContext(ctx context.Context, _ bool) ([]TimesStat, error) {
2021
// BUG: percpu flag is not supported yet.
2122
root := os.Getenv("HOST_ROOT")
2223
c, err := stats.ReadCPUType(ctx, stats.WithRootDir(root))
@@ -41,10 +42,10 @@ func Info() ([]InfoStat, error) {
4142
return InfoWithContext(context.Background())
4243
}
4344

44-
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
45+
func InfoWithContext(_ context.Context) ([]InfoStat, error) {
4546
return []InfoStat{}, common.ErrNotImplementedError
4647
}
4748

48-
func CountsWithContext(ctx context.Context, logical bool) (int, error) {
49+
func CountsWithContext(_ context.Context, _ bool) (int, error) {
4950
return runtime.NumCPU(), nil
5051
}

cpu/cpu_solaris.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var kstatSplit = regexp.MustCompile(`[:\s]+`)
4242
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
4343
kstatSysOut, err := invoke.CommandWithContext(ctx, "kstat", "-p", "cpu_stat:*:*:/^idle$|^user$|^kernel$|^iowait$|^swap$/")
4444
if err != nil {
45-
return nil, fmt.Errorf("cannot execute kstat: %s", err)
45+
return nil, fmt.Errorf("cannot execute kstat: %w", err)
4646
}
4747
cpu := make(map[float64]float64)
4848
idle := make(map[float64]float64)
@@ -57,29 +57,29 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
5757
}
5858
cpuNumber, err := strconv.ParseFloat(fields[1], 64)
5959
if err != nil {
60-
return nil, fmt.Errorf("cannot parse cpu number: %s", err)
60+
return nil, fmt.Errorf("cannot parse cpu number: %w", err)
6161
}
6262
cpu[cpuNumber] = cpuNumber
6363
switch fields[3] {
6464
case "idle":
6565
idle[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
6666
if err != nil {
67-
return nil, fmt.Errorf("cannot parse idle: %s", err)
67+
return nil, fmt.Errorf("cannot parse idle: %w", err)
6868
}
6969
case "user":
7070
user[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
7171
if err != nil {
72-
return nil, fmt.Errorf("cannot parse user: %s", err)
72+
return nil, fmt.Errorf("cannot parse user: %w", err)
7373
}
7474
case "kernel":
7575
kern[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
7676
if err != nil {
77-
return nil, fmt.Errorf("cannot parse kernel: %s", err)
77+
return nil, fmt.Errorf("cannot parse kernel: %w", err)
7878
}
7979
case "iowait":
8080
iowt[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
8181
if err != nil {
82-
return nil, fmt.Errorf("cannot parse iowait: %s", err)
82+
return nil, fmt.Errorf("cannot parse iowait: %w", err)
8383
}
8484
//not sure how this translates, don't report, add to kernel, something else?
8585
/*case "swap":
@@ -121,22 +121,22 @@ func Info() ([]InfoStat, error) {
121121
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
122122
psrInfoOut, err := invoke.CommandWithContext(ctx, "psrinfo", "-p", "-v")
123123
if err != nil {
124-
return nil, fmt.Errorf("cannot execute psrinfo: %s", err)
124+
return nil, fmt.Errorf("cannot execute psrinfo: %w", err)
125125
}
126126

127127
procs, err := parseProcessorInfo(string(psrInfoOut))
128128
if err != nil {
129-
return nil, fmt.Errorf("error parsing psrinfo output: %s", err)
129+
return nil, fmt.Errorf("error parsing psrinfo output: %w", err)
130130
}
131131

132132
isaInfoOut, err := invoke.CommandWithContext(ctx, "isainfo", "-b", "-v")
133133
if err != nil {
134-
return nil, fmt.Errorf("cannot execute isainfo: %s", err)
134+
return nil, fmt.Errorf("cannot execute isainfo: %w", err)
135135
}
136136

137137
flags, err := parseISAInfo(string(isaInfoOut))
138138
if err != nil {
139-
return nil, fmt.Errorf("error parsing isainfo output: %s", err)
139+
return nil, fmt.Errorf("error parsing isainfo output: %w", err)
140140
}
141141

142142
result := make([]InfoStat, 0, len(flags))
@@ -160,7 +160,7 @@ func parseISAInfo(cmdOutput string) ([]string, error) {
160160
}
161161

162162
flags := make([]string, len(words)-4)
163-
for i, val := range words[4:] {
163+
for i, val := range words[4:] { //nolint:gosimple //FIXME
164164
flags[i] = val
165165
}
166166
sort.Strings(flags)
@@ -194,15 +194,15 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
194194
if physicalCPU[psrStepOffset] != "" {
195195
stepParsed, err := strconv.ParseInt(physicalCPU[psrStepOffset], 10, 32)
196196
if err != nil {
197-
return nil, fmt.Errorf("cannot parse value %q for step as 32-bit integer: %s", physicalCPU[9], err)
197+
return nil, fmt.Errorf("cannot parse value %q for step as 32-bit integer: %w", physicalCPU[9], err)
198198
}
199199
step = int32(stepParsed)
200200
}
201201

202202
if physicalCPU[psrClockOffset] != "" {
203203
clockParsed, err := strconv.ParseInt(physicalCPU[psrClockOffset], 10, 64)
204204
if err != nil {
205-
return nil, fmt.Errorf("cannot parse value %q for clock as 32-bit integer: %s", physicalCPU[10], err)
205+
return nil, fmt.Errorf("cannot parse value %q for clock as 32-bit integer: %w", physicalCPU[10], err)
206206
}
207207
clock = float64(clockParsed)
208208
}
@@ -214,7 +214,7 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
214214
case physicalCPU[psrNumCoresOffset] != "":
215215
numCores, err = strconv.ParseInt(physicalCPU[psrNumCoresOffset], 10, 32)
216216
if err != nil {
217-
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %s", physicalCPU[1], err)
217+
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %w", physicalCPU[1], err)
218218
}
219219

220220
for i := 0; i < int(numCores); i++ {
@@ -235,12 +235,12 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
235235
case physicalCPU[psrNumCoresHTOffset] != "":
236236
numCores, err = strconv.ParseInt(physicalCPU[psrNumCoresHTOffset], 10, 32)
237237
if err != nil {
238-
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %s", physicalCPU[3], err)
238+
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %w", physicalCPU[3], err)
239239
}
240240

241241
numHT, err = strconv.ParseInt(physicalCPU[psrNumHTOffset], 10, 32)
242242
if err != nil {
243-
return nil, fmt.Errorf("cannot parse value %q for hyperthread count as 32-bit integer: %s", physicalCPU[4], err)
243+
return nil, fmt.Errorf("cannot parse value %q for hyperthread count as 32-bit integer: %w", physicalCPU[4], err)
244244
}
245245

246246
for i := 0; i < int(numCores); i++ {
@@ -265,6 +265,6 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
265265
return result, nil
266266
}
267267

268-
func CountsWithContext(ctx context.Context, logical bool) (int, error) {
268+
func CountsWithContext(_ context.Context, _ bool) (int, error) {
269269
return runtime.NumCPU(), nil
270270
}

0 commit comments

Comments
 (0)