Skip to content

Commit edcde3a

Browse files
authored
Merge pull request #1797 from mmorel-35/golangci-lint-matrix
chore(golangci-lint): GOOS and GOARCH matrix
2 parents 4f2f472 + 30aff03 commit edcde3a

30 files changed

+146
-118
lines changed

Diff for: .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

Diff for: cpu/cpu_dragonfly.go

+3-2
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 (
@@ -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 {

Diff for: cpu/cpu_netbsd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -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

Diff for: cpu/cpu_openbsd.go

+3-2
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 (
@@ -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

Diff for: cpu/cpu_plan9.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"runtime"
1010

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

Diff for: cpu/cpu_solaris.go

+16-16
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++ {

Diff for: disk/disk_openbsd.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import (
88
"context"
99
"encoding/binary"
1010

11-
"github.com/shirou/gopsutil/v4/internal/common"
1211
"golang.org/x/sys/unix"
12+
13+
"github.com/shirou/gopsutil/v4/internal/common"
1314
)
1415

1516
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {

Diff for: disk/disk_solaris.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"bufio"
88
"bytes"
99
"context"
10+
"errors"
1011
"fmt"
1112
"math"
1213
"os"
@@ -16,8 +17,9 @@ import (
1617
"strconv"
1718
"strings"
1819

19-
"github.com/shirou/gopsutil/v4/internal/common"
2020
"golang.org/x/sys/unix"
21+
22+
"github.com/shirou/gopsutil/v4/internal/common"
2123
)
2224

2325
const (
@@ -100,7 +102,7 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC
100102
}
101103
lines := strings.Split(strings.TrimSpace(string(kstatSysOut)), "\n")
102104
if len(lines) == 0 {
103-
return nil, fmt.Errorf("no disk class found")
105+
return nil, errors.New("no disk class found")
104106
}
105107
dnamearr := make(map[string]string)
106108
nreadarr := make(map[string]uint64)

Diff for: host/host_openbsd.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import (
1212
"strings"
1313
"unsafe"
1414

15+
"golang.org/x/sys/unix"
16+
1517
"github.com/shirou/gopsutil/v4/internal/common"
1618
"github.com/shirou/gopsutil/v4/process"
17-
"golang.org/x/sys/unix"
1819
)
1920

2021
const (

Diff for: host/host_solaris.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"bufio"
88
"bytes"
99
"context"
10+
"errors"
1011
"fmt"
1112
"os"
1213
"regexp"
@@ -31,14 +32,13 @@ func HostIDWithContext(ctx context.Context) (string, error) {
3132
line := sc.Text()
3233

3334
// If we're in the global zone, rely on the hostname.
34-
if line == "global" {
35-
hostname, err := os.Hostname()
36-
if err == nil {
37-
return hostname, nil
38-
}
39-
} else {
35+
if line != "global" {
4036
return strings.TrimSpace(line), nil
4137
}
38+
hostname, err := os.Hostname()
39+
if err == nil {
40+
return hostname, nil
41+
}
4242
}
4343
}
4444
}
@@ -84,7 +84,7 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
8484
}
8585

8686
func UptimeWithContext(ctx context.Context) (uint64, error) {
87-
bootTime, err := BootTime()
87+
bootTime, err := BootTime() //nolint:contextcheck //FIXME
8888
if err != nil {
8989
return 0, err
9090
}
@@ -139,7 +139,7 @@ func parseUnameOutput(ctx context.Context) (string, string, string, error) {
139139

140140
fields := strings.Fields(string(out))
141141
if len(fields) < 3 {
142-
return "", "", "", fmt.Errorf("malformed `uname` output")
142+
return "", "", "", errors.New("malformed `uname` output")
143143
}
144144

145145
return fields[0], fields[1], fields[2], nil

Diff for: mem/mem_bsd_test.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
1011
)
1112

1213
const validFreeBSD = `Device: 1kB-blocks Used:
@@ -24,33 +25,31 @@ const invalid = `Device: 512-blocks Used:
2425
`
2526

2627
func TestParseSwapctlOutput_FreeBSD(t *testing.T) {
27-
assert := assert.New(t)
2828
stats, err := parseSwapctlOutput(validFreeBSD)
29-
assert.NoError(err)
29+
require.NoError(t, err)
3030

31-
assert.Equal(*stats[0], SwapDevice{
31+
assert.Equal(t, SwapDevice{
3232
Name: "/dev/gpt/swapfs",
3333
UsedBytes: 1263616,
3434
FreeBytes: 1072478208,
35-
})
35+
}, *stats[0])
3636

37-
assert.Equal(*stats[1], SwapDevice{
37+
assert.Equal(t, SwapDevice{
3838
Name: "/dev/md0",
3939
UsedBytes: 681984,
4040
FreeBytes: 1073059840,
41-
})
41+
}, *stats[1])
4242
}
4343

4444
func TestParseSwapctlOutput_OpenBSD(t *testing.T) {
45-
assert := assert.New(t)
4645
stats, err := parseSwapctlOutput(validOpenBSD)
47-
assert.NoError(err)
46+
require.NoError(t, err)
4847

49-
assert.Equal(*stats[0], SwapDevice{
48+
assert.Equal(t, SwapDevice{
5049
Name: "/dev/wd0b",
5150
UsedBytes: 1234 * 1024,
5251
FreeBytes: 653791 * 1024,
53-
})
52+
}, *stats[0])
5453
}
5554

5655
func TestParseSwapctlOutput_Invalid(t *testing.T) {

Diff for: mem/mem_linux_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,16 @@ const invalidFile = `INVALID Type Size Used Priority
151151
`
152152

153153
func TestParseSwapsFile_ValidFile(t *testing.T) {
154-
assert := assert.New(t)
155154
stats, err := parseSwapsFile(context.Background(), strings.NewReader(validFile))
156155
require.NoError(t, err)
157156

158-
assert.Equal(SwapDevice{
157+
assert.Equal(t, SwapDevice{
159158
Name: "/dev/dm-2",
160159
UsedBytes: 502566912,
161160
FreeBytes: 68128825344,
162161
}, *stats[0])
163162

164-
assert.Equal(SwapDevice{
163+
assert.Equal(t, SwapDevice{
165164
Name: "/swapfile",
166165
UsedBytes: 1024,
167166
FreeBytes: 1024,

0 commit comments

Comments
 (0)