Skip to content

Commit 9684daf

Browse files
authored
Cleanup various linting issues (#548)
Fix up minor issues found by newer golangci-lint. * Remove unused params. * Fix unused-parameter issues. * Fix redefines-builtin-id issues. Signed-off-by: SuperQ <[email protected]>
1 parent 4b2218e commit 9684daf

File tree

10 files changed

+20
-24
lines changed

10 files changed

+20
-24
lines changed

Diff for: btrfs/get.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (r *reader) calcRatio(p string) float64 {
207207

208208
// readDeviceInfo returns the information for all devices associated with this filesystem.
209209
func (r *reader) readDeviceInfo(d string) map[string]*Device {
210-
devs := r.listFiles("devices")
210+
devs := r.listFiles(d)
211211
info := make(map[string]*Device, len(devs))
212212
for _, n := range devs {
213213
info[n] = &Device{

Diff for: fs.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
// FS represents the pseudo-filesystem sys, which provides an interface to
2121
// kernel data structures.
2222
type FS struct {
23-
proc fs.FS
24-
real bool
23+
proc fs.FS
24+
isReal bool
2525
}
2626

2727
// DefaultMountPoint is the common mount point of the proc filesystem.
@@ -41,10 +41,10 @@ func NewFS(mountPoint string) (FS, error) {
4141
return FS{}, err
4242
}
4343

44-
real, err := isRealProc(mountPoint)
44+
isReal, err := isRealProc(mountPoint)
4545
if err != nil {
4646
return FS{}, err
4747
}
4848

49-
return FS{fs, real}, nil
49+
return FS{fs, isReal}, nil
5050
}

Diff for: iscsi/get.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,8 @@ func (fs FS) GetRBDMatch(rbdNumber string, poolImage string) (*RBD, error) {
195195
bSystemPool, err := os.ReadFile(systemPoolPath)
196196
if err != nil {
197197
continue
198-
} else {
199-
systemPool = strings.TrimSpace(string(bSystemPool))
200198
}
199+
systemPool = strings.TrimSpace(string(bSystemPool))
201200

202201
systemImagePath := filepath.Join(systemRbdPath, "name")
203202
if _, err := os.Stat(systemImagePath); os.IsNotExist(err) {
@@ -206,9 +205,8 @@ func (fs FS) GetRBDMatch(rbdNumber string, poolImage string) (*RBD, error) {
206205
bSystemImage, err := os.ReadFile(systemImagePath)
207206
if err != nil {
208207
continue
209-
} else {
210-
systemImage = strings.TrimSpace(string(bSystemImage))
211208
}
209+
systemImage = strings.TrimSpace(string(bSystemImage))
212210

213211
if strings.Compare(strconv.FormatInt(int64(systemRbdNumber), 10), rbdNumber) == 0 &&
214212
matchPoolImage(systemPool, systemImage, poolImage) {

Diff for: proc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func (p Proc) FileDescriptorTargets() ([]string, error) {
244244
// a process.
245245
func (p Proc) FileDescriptorsLen() (int, error) {
246246
// Use fast path if available (Linux v6.2): https://github.com/torvalds/linux/commit/f1f1f2569901
247-
if p.fs.real {
247+
if p.fs.isReal {
248248
stat, err := os.Stat(p.path("fd"))
249249
if err != nil {
250250
return 0, err

Diff for: proc_psi.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ func (fs FS) PSIStatsForResource(resource string) (PSIStats, error) {
6464
return PSIStats{}, fmt.Errorf("%s: psi_stats: unavailable for %q: %w", ErrFileRead, resource, err)
6565
}
6666

67-
return parsePSIStats(resource, bytes.NewReader(data))
67+
return parsePSIStats(bytes.NewReader(data))
6868
}
6969

7070
// parsePSIStats parses the specified file for pressure stall information.
71-
func parsePSIStats(resource string, r io.Reader) (PSIStats, error) {
71+
func parsePSIStats(r io.Reader) (PSIStats, error) {
7272
psiStats := PSIStats{}
7373

7474
scanner := bufio.NewScanner(r)

Diff for: proc_psi_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestPSIStats(t *testing.T) {
111111
func TestParsePSIStats(t *testing.T) {
112112
t.Run("unknown measurement type", func(t *testing.T) {
113113
raw := "nonsense haha test=fake"
114-
_, err := parsePSIStats("fake", strings.NewReader(raw))
114+
_, err := parsePSIStats(strings.NewReader(raw))
115115
if err != nil {
116116
t.Error("unknown measurement type must be ignored")
117117
}
@@ -121,7 +121,7 @@ func TestParsePSIStats(t *testing.T) {
121121
t.Run("some", func(t *testing.T) {
122122
raw := `some avg10=0.10 avg60=2.00 avg300=3.85 total=oops
123123
full avg10=0.20 avg60=3.00 avg300=teddy total=25`
124-
stats, err := parsePSIStats("fake", strings.NewReader(raw))
124+
stats, err := parsePSIStats(strings.NewReader(raw))
125125
if err == nil {
126126
t.Error("a malformed line must result in a parse error")
127127
}
@@ -133,7 +133,7 @@ full avg10=0.20 avg60=3.00 avg300=teddy total=25`
133133
t.Run("full", func(t *testing.T) {
134134
raw := `some avg10=0.10 avg60=2.00 avg300=3.85 total=1
135135
full avg10=0.20 avg60=3.00 avg300=test total=25`
136-
stats, err := parsePSIStats("fake", strings.NewReader(raw))
136+
stats, err := parsePSIStats(strings.NewReader(raw))
137137
t.Log(err)
138138
t.Log(stats)
139139
if err == nil {

Diff for: proc_smaps.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ func (s *ProcSMapsRollup) parseLine(line string) error {
135135
}
136136
vBytes := vKBytes * 1024
137137

138-
s.addValue(k, v, vKBytes, vBytes)
138+
s.addValue(k, vBytes)
139139

140140
return nil
141141
}
142142

143-
func (s *ProcSMapsRollup) addValue(k string, vString string, vUint uint64, vUintBytes uint64) {
143+
func (s *ProcSMapsRollup) addValue(k string, vUintBytes uint64) {
144144
switch k {
145145
case "Rss":
146146
s.Rss += vUintBytes

Diff for: sysfs/class_sas_device.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,8 @@ func (fs FS) blockSASDeviceBlockDevices(name string) ([]string, error) {
163163
if err != nil {
164164
if os.IsNotExist(err) {
165165
continue
166-
} else {
167-
return nil, err
168166
}
167+
return nil, err
169168
}
170169

171170
for _, blockdevice := range blocks {

Diff for: sysfs/class_sas_phy.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ func (fs FS) parseSASPhy(name string) (*SASPhy, error) {
9999
if err != nil {
100100
if os.IsPermission(err) {
101101
continue
102-
} else {
103-
return nil, fmt.Errorf("failed to read file %q: %w", name, err)
104102
}
103+
return nil, fmt.Errorf("failed to read file %q: %w", name, err)
105104
}
106105

107106
vp := util.NewValueParser(value)

Diff for: thread.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (fs FS) AllThreads(pid int) (Procs, error) {
5555
continue
5656
}
5757

58-
t = append(t, Proc{PID: int(tid), fs: FS{fsi.FS(taskPath), fs.real}})
58+
t = append(t, Proc{PID: int(tid), fs: FS{fsi.FS(taskPath), fs.isReal}})
5959
}
6060

6161
return t, nil
@@ -67,12 +67,12 @@ func (fs FS) Thread(pid, tid int) (Proc, error) {
6767
if _, err := os.Stat(taskPath); err != nil {
6868
return Proc{}, err
6969
}
70-
return Proc{PID: tid, fs: FS{fsi.FS(taskPath), fs.real}}, nil
70+
return Proc{PID: tid, fs: FS{fsi.FS(taskPath), fs.isReal}}, nil
7171
}
7272

7373
// Thread returns a process for a given TID of Proc.
7474
func (proc Proc) Thread(tid int) (Proc, error) {
75-
tfs := FS{fsi.FS(proc.path("task")), proc.fs.real}
75+
tfs := FS{fsi.FS(proc.path("task")), proc.fs.isReal}
7676
if _, err := os.Stat(tfs.proc.Path(strconv.Itoa(tid))); err != nil {
7777
return Proc{}, err
7878
}

0 commit comments

Comments
 (0)