Skip to content

Commit 214bc8d

Browse files
authored
Merge pull request #1173 from mmorel-35/golangci-lint
setup golangci-lint
2 parents 36cc0d3 + 46ae957 commit 214bc8d

File tree

8 files changed

+39
-10
lines changed

8 files changed

+39
-10
lines changed

.github/workflows/lint.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Golangci-lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
golangci:
9+
name: lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Setup go
13+
uses: actions/setup-go@v2
14+
with:
15+
go-version: 1.17
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
- name: Setup golangci-lint
19+
uses: golangci/golangci-lint-action@v2
20+
with:
21+
args: --verbose
22+
version: latest
23+
working-directory: v3

.golangci.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
linters:
2+
disable:
3+
- deadcode
4+
- errcheck
5+
- govet
6+
- ineffassign
7+
- staticcheck
8+
- structcheck
9+
- unused
10+
- varcheck

v3/cpu/cpu_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func parseStatLine(line string) (*TimesStat, error) {
240240
return nil, errors.New("stat does not contain cpu info")
241241
}
242242

243-
if strings.HasPrefix(fields[0], "cpu") == false {
243+
if !strings.HasPrefix(fields[0], "cpu") {
244244
return nil, errors.New("not contain cpu")
245245
}
246246

v3/disk/disk_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC
349349
if err != nil {
350350
return nil, err
351351
}
352-
ret := make(map[string]IOCountersStat, 0)
352+
ret := make(map[string]IOCountersStat)
353353
empty := IOCountersStat{}
354354

355355
// use only basename such as "/dev/sda1" to "sda1"

v3/internal/common/common_unix.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ func CallLsofWithContext(ctx context.Context, invoke Invoker, pid int32, args ..
4141
}
4242

4343
func CallPgrepWithContext(ctx context.Context, invoke Invoker, pid int32) ([]int32, error) {
44-
var cmd []string
45-
cmd = []string{"-P", strconv.Itoa(int(pid))}
44+
cmd := []string{"-P", strconv.Itoa(int(pid))}
4645
pgrep, err := exec.LookPath("pgrep")
4746
if err != nil {
4847
return []int32{}, err

v3/net/net.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (l *ConntrackStatList) Append(c *ConntrackStat) {
131131
}
132132

133133
func (l *ConntrackStatList) Items() []ConntrackStat {
134-
items := make([]ConntrackStat, len(l.items), len(l.items))
134+
items := make([]ConntrackStat, len(l.items))
135135
for i, el := range l.items {
136136
items[i] = *el
137137
}

v3/net/net_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func IOCountersByFileWithContext(ctx context.Context, pernic bool, filename stri
140140
ret = append(ret, nic)
141141
}
142142

143-
if pernic == false {
143+
if !pernic {
144144
return getIOCountersAll(ret)
145145
}
146146

v3/process/process_linux.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,7 @@ func (p *Process) fillFromIOWithContext(ctx context.Context) (*IOCountersStat, e
726726
if err != nil {
727727
return nil, err
728728
}
729-
param := field[0]
730-
if strings.HasSuffix(param, ":") {
731-
param = param[:len(param)-1]
732-
}
729+
param := strings.TrimSuffix(field[0], ":")
733730
switch param {
734731
case "syscr":
735732
ret.ReadCount = t

0 commit comments

Comments
 (0)