Skip to content

Commit 2f8da0a

Browse files
authored
Merge pull request #1205 from mmorel-35/master
enable more linters, report coverage and cache mods
2 parents 0bd6ae1 + fe2fab4 commit 2f8da0a

File tree

160 files changed

+940
-722
lines changed

Some content is hidden

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

160 files changed

+940
-722
lines changed

.github/workflows/build_test.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ jobs:
1313
go-version: ${{ matrix.go-version }}
1414
- name: Checkout code
1515
uses: actions/checkout@v2
16+
- id: cache-paths
17+
run: |
18+
echo "::set-output name=cache::$(go env GOCACHE)"
19+
echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
20+
- name: Cache go modules
21+
uses: actions/cache@v2
22+
with:
23+
path: |
24+
${{ steps.cache-paths.outputs.cache }}
25+
${{ steps.cache-paths.outputs.mod-cache }}
26+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27+
restore-keys: ${{ runner.os }}-go-
1628
- name: Build Test v3
1729
run: |
18-
make build_test
30+
make build_test

.github/workflows/test.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ jobs:
1414
go-version: ${{ matrix.go-version }}
1515
- name: Checkout code
1616
uses: actions/checkout@v2
17+
- id: go-env
18+
run: |
19+
echo "::set-output name=cache::$(go env GOCACHE)"
20+
echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
21+
- name: Cache go modules
22+
uses: actions/cache@v2
23+
with:
24+
path: |
25+
${{ steps.go-env.outputs.cache }}
26+
${{ steps.go-env.outputs.mod-cache }}
27+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
28+
restore-keys: ${{ runner.os }}-go-
1729
- name: Test
1830
run: |
19-
go test ./...
31+
go test -coverprofile='coverage.out' -covermode=atomic ./...
32+
- name: Upload Code Coverage
33+
uses: codecov/codecov-action@v2
34+
with:
35+
fail_ci_if_error: true
36+
files: coverage.out
37+
flags: ${{ runner.os }},go-${{ matrix.go-version }}
38+
token: ${{ secrets.CODECOV_TOKEN }}

.golangci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
1+
issues:
2+
max-same-issues: 0
3+
exclude-rules:
4+
- linters:
5+
- gosec
6+
text: "G204"
7+
- linters:
8+
- revive
9+
text: "var-naming"
10+
- linters:
11+
- revive
12+
text: "exported"
113
linters:
214
enable:
15+
- asciicheck
16+
- durationcheck
317
- errorlint
418
- gci
19+
- gofmt
20+
- gofumpt
21+
- goimports
22+
- gosec
523
- gosimple
24+
- importas
25+
- megacheck
26+
- misspell
27+
- nakedret
28+
- nolintlint
29+
- predeclared
30+
- revive
631
- typecheck
32+
- unparam
733
disable:
834
- deadcode
935
- errcheck

_tools/v3migration/v3migration.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,4 @@ func main() {
103103
issueRemoveUnusedValue()
104104
}
105105
}
106-
107106
}

cpu/cpu.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ type lastPercent struct {
5151
lastPerCPUTimes []TimesStat
5252
}
5353

54-
var lastCPUPercent lastPercent
55-
var invoke common.Invoker = common.Invoke{}
54+
var (
55+
lastCPUPercent lastPercent
56+
invoke common.Invoker = common.Invoke{}
57+
)
5658

5759
func init() {
5860
lastCPUPercent.Lock()

cpu/cpu_aix.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build aix
12
// +build aix
23

34
package cpu
@@ -36,9 +37,9 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
3637
}
3738
ct := &TimesStat{
3839
CPU: "cpu-total",
39-
Idle: float64(c.IdlePct),
40-
User: float64(c.UserPct),
41-
System: float64(c.KernPct),
40+
Idle: float64(c.IdlePct),
41+
User: float64(c.UserPct),
42+
System: float64(c.KernPct),
4243
Iowait: float64(c.WaitPct),
4344
}
4445
ret = append(ret, *ct)
@@ -56,11 +57,11 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
5657
return nil, err
5758
}
5859
info := InfoStat{
59-
CPU: 0,
60-
Mhz: float64(c.ProcessorHz / 1000000),
60+
CPU: 0,
61+
Mhz: float64(c.ProcessorHz / 1000000),
6162
Cores: int32(c.NCpusCfg),
62-
}
63-
result := []InfoStat{info};
63+
}
64+
result := []InfoStat{info}
6465
return result, nil
6566
}
6667

@@ -71,4 +72,3 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
7172
}
7273
return c.NCpusCfg, nil
7374
}
74-

cpu/cpu_darwin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build darwin
12
// +build darwin
23

34
package cpu

cpu/cpu_darwin_cgo.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// +build darwin
2-
// +build cgo
1+
//go:build darwin && cgo
2+
// +build darwin,cgo
33

44
package cpu
55

@@ -108,5 +108,4 @@ func allCPUTimes() ([]TimesStat, error) {
108108
}
109109

110110
return []TimesStat{c}, nil
111-
112111
}

cpu/cpu_darwin_nocgo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// +build darwin
2-
// +build !cgo
1+
//go:build darwin && !cgo
2+
// +build darwin,!cgo
33

44
package cpu
55

cpu/cpu_dragonfly.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ import (
1515
"golang.org/x/sys/unix"
1616
)
1717

18-
var ClocksPerSec = float64(128)
19-
var cpuMatch = regexp.MustCompile(`^CPU:`)
20-
var originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`)
21-
var featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`)
22-
var featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`)
23-
var cpuEnd = regexp.MustCompile(`^Trying to mount root`)
24-
var cpuTimesSize int
25-
var emptyTimes cpuTimes
18+
var (
19+
ClocksPerSec = float64(128)
20+
cpuMatch = regexp.MustCompile(`^CPU:`)
21+
originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`)
22+
featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`)
23+
featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`)
24+
cpuEnd = regexp.MustCompile(`^Trying to mount root`)
25+
cpuTimesSize int
26+
emptyTimes cpuTimes
27+
)
2628

2729
func init() {
2830
clkTck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK)

0 commit comments

Comments
 (0)