Skip to content

Commit 53e9e67

Browse files
authored
chore: enable errorlint linter (#742)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
1 parent 0d1fd88 commit 53e9e67

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
version: "2"
22
linters:
33
enable:
4+
- errorlint
45
- forbidigo
56
- godot
67
- misspell

blockdevice/stats_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package blockdevice
1515

1616
import (
17+
"errors"
1718
"os"
1819
"reflect"
1920
"testing"
@@ -181,9 +182,10 @@ func TestBlockDmInfo(t *testing.T) {
181182

182183
dm1Info, err := blockdevice.SysBlockDeviceMapperInfo(devices[1])
183184
if err != nil {
184-
if _, ok := err.(*os.PathError); ok {
185+
var pErr *os.PathError
186+
if errors.As(err, &pErr) {
185187
// Fail the test if there's an error other than PathError.
186-
if !os.IsNotExist(err) {
188+
if !os.IsNotExist(pErr) {
187189
t.Fatal(err)
188190
}
189191
} else {

proc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (p Procs) Less(i, j int) bool { return p[i].PID < p[j].PID }
4949
// Self returns a process for the current process read via /proc/self.
5050
func Self() (Proc, error) {
5151
fs, err := NewFS(DefaultMountPoint)
52-
if err != nil || errors.Unwrap(err) == ErrMountPoint {
52+
if err != nil || errors.Is(err, ErrMountPoint) {
5353
return Proc{}, err
5454
}
5555
return fs.Self()

stat.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package procfs
1616
import (
1717
"bufio"
1818
"bytes"
19+
"errors"
1920
"fmt"
2021
"io"
2122
"strconv"
@@ -92,7 +93,7 @@ func parseCPUStat(line string) (CPUStat, int64, error) {
9293
&cpuStat.Iowait, &cpuStat.IRQ, &cpuStat.SoftIRQ, &cpuStat.Steal,
9394
&cpuStat.Guest, &cpuStat.GuestNice)
9495

95-
if err != nil && err != io.EOF {
96+
if err != nil && !errors.Is(err, io.EOF) {
9697
return CPUStat{}, -1, fmt.Errorf("%w: couldn't parse %q (cpu): %w", ErrFileParse, line, err)
9798
}
9899
if count == 0 {

sysfs/net_class_aer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func parseCorrectableAerCounters(devicePath string, counters *CorrectableAerCoun
154154
counterName := fields[0]
155155
value, err := strconv.ParseUint(fields[1], 10, 64)
156156
if err != nil {
157-
return fmt.Errorf("error parsing value for %s: %v", counterName, err)
157+
return fmt.Errorf("error parsing value for %s: %w", counterName, err)
158158
}
159159

160160
switch counterName {
@@ -206,7 +206,7 @@ func parseUncorrectableAerCounters(devicePath string, counterType string,
206206
counterName := fields[0]
207207
value, err := strconv.ParseUint(fields[1], 10, 64)
208208
if err != nil {
209-
return fmt.Errorf("error parsing value for %s: %v", counterName, err)
209+
return fmt.Errorf("error parsing value for %s: %w", counterName, err)
210210
}
211211

212212
switch counterName {

sysfs/system_cpu_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func TestIsolatedParsingCPU(t *testing.T) {
225225
if err != nil && params.err != nil && err.Error() != params.err.Error() {
226226
t.Fatalf("should have '%v' error: got '%v'", params.err, err)
227227
}
228-
if (err == nil || params.err == nil) && err != params.err {
228+
if (err == nil || params.err == nil) && !errors.Is(err, params.err) {
229229
t.Fatalf("should have %v error: got %v", params.err, err)
230230
}
231231

0 commit comments

Comments
 (0)