Skip to content

Commit 26f99ad

Browse files
committed
CI: lint go code
1 parent f6d148a commit 26f99ad

8 files changed

Lines changed: 203 additions & 62 deletions

File tree

.github/workflows/lint.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Static Analysis
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
paths:
7+
- '.github/workflows/lint.yaml'
8+
- 'waf-check/**'
9+
pull_request:
10+
branches: [ master ]
11+
paths:
12+
- '.github/workflows/lint.yaml'
13+
- 'waf-check/**'
14+
15+
16+
jobs:
17+
build:
18+
name: "golangci-lint + codeql"
19+
runs-on: ubuntu-latest
20+
21+
permissions:
22+
security-events: write
23+
24+
steps:
25+
- name: Check out code into the Go module directory
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Set up Go
31+
uses: actions/setup-go@v5
32+
with:
33+
go-version-file: waf-check/go.mod
34+
35+
- name: Initialize CodeQL
36+
uses: github/codeql-action/init@v3
37+
with:
38+
languages: go, python
39+
40+
- name: Build
41+
run: |
42+
make build
43+
44+
- name: golangci-lint
45+
uses: golangci/golangci-lint-action@v7
46+
with:
47+
version: v2.0
48+
args: --issues-exit-code=1 --timeout 10m
49+
only-new-issues: false
50+
working-directory: waf-check
51+
52+
- name: Perform CodeQL Analysis
53+
uses: github/codeql-action/analyze@v3

waf-check/.golangci.yml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
version: "2"
2+
3+
linters:
4+
default: all
5+
disable:
6+
- errcheck
7+
- errorlint
8+
- exhaustruct
9+
- forbidigo
10+
- ineffassign
11+
- intrange
12+
- musttag
13+
- noctx
14+
- perfsprint
15+
- unparam
16+
- usestdlibvars
17+
- wastedassign
18+
19+
- cyclop # revive
20+
- funlen # revive
21+
- gocognit # revive
22+
- gocyclo # revive
23+
- lll # revive
24+
25+
- gosec # (gas): Inspects source code for security problems
26+
- wrapcheck # Checks that errors returned from external packages are wrapped
27+
- mnd # An analyzer to detect magic numbers.
28+
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
29+
- whitespace # Whitespace is a linter that checks for unnecessary newlines at the start and end of functions, if, for, etc.
30+
- wsl # add or remove empty lines
31+
- err113 # Go linter to check the errors handling expressions
32+
- tagliatelle # Checks the struct tags.
33+
- varnamelen # checks that the length of a variable's name matches its scope
34+
35+
settings:
36+
37+
depguard:
38+
rules:
39+
yaml:
40+
files:
41+
- '!**/config.go'
42+
deny:
43+
- pkg: gopkg.in/yaml.v2
44+
desc: yaml.v2 is deprecated for new code in favor of yaml.v3
45+
46+
errcheck:
47+
check-type-assertions: false
48+
49+
gocritic:
50+
enable-all: true
51+
disabled-checks:
52+
- httpNoBody
53+
- hugeParam
54+
- paramTypeCombine
55+
- exitAfterDefer
56+
57+
govet:
58+
disable:
59+
- fieldalignment
60+
enable-all: true
61+
62+
misspell:
63+
locale: US
64+
65+
nlreturn:
66+
block-size: 5
67+
68+
nolintlint:
69+
require-explanation: false # don't require an explanation for nolint directives
70+
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
71+
allow-unused: false # report any unused nolint directives
72+
73+
revive:
74+
severity: error
75+
enable-all-rules: true
76+
rules:
77+
- name: add-constant
78+
disabled: true
79+
- name: cognitive-complexity
80+
arguments:
81+
# lower this after refactoring
82+
- 17
83+
- name: cyclomatic
84+
arguments:
85+
# lower this after refactoring
86+
- 12
87+
- name: deep-exit
88+
disabled: true
89+
- name: empty-lines
90+
disabled: true
91+
- name: increment-decrement
92+
disabled: true
93+
- name: line-length-limit
94+
arguments:
95+
# lower this after refactoring
96+
- 111
97+
- name: struct-tag
98+
disabled: true
99+
100+
staticcheck:
101+
checks:
102+
- all
103+
- -SA4006
104+
105+
wsl:
106+
# Allow blocks to end with comments
107+
allow-trailing-comment: true
108+
109+
exclusions:
110+
presets:
111+
- comments
112+
- common-false-positives
113+
- legacy
114+
- std-error-handling
115+
rules:
116+
117+
- linters:
118+
- govet
119+
text: 'shadow: declaration of "(err|ctx)" shadows declaration'
120+
121+
paths:
122+
- third_party$
123+
- builtin$
124+
- examples$
125+
126+
issues:
127+
max-issues-per-linter: 0
128+
max-same-issues: 0
129+
130+
formatters:
131+
enable:
132+
- gci
133+
- gofumpt
134+
135+
settings:
136+
gci:
137+
sections:
138+
- standard
139+
- default
140+
141+
exclusions:
142+
paths:
143+
- third_party$
144+
- builtin$
145+
- examples$

waf-check/go.mod

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
module waf-check
22

3-
go 1.21.3
3+
go 1.24
44

5-
require (
6-
github.com/cheggaaa/pb/v3 v3.1.4
7-
github.com/google/uuid v1.5.0
8-
github.com/schollz/progressbar/v3 v3.14.1
9-
gopkg.in/yaml.v2 v2.4.0
10-
)
11-
12-
require (
13-
github.com/VividCortex/ewma v1.2.0 // indirect
14-
github.com/fatih/color v1.15.0 // indirect
15-
github.com/mattn/go-colorable v0.1.13 // indirect
16-
github.com/mattn/go-isatty v0.0.20 // indirect
17-
github.com/mattn/go-runewidth v0.0.14 // indirect
18-
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
19-
github.com/rivo/uniseg v0.4.4 // indirect
20-
golang.org/x/sys v0.14.0 // indirect
21-
golang.org/x/term v0.14.0 // indirect
22-
)
5+
require gopkg.in/yaml.v2 v2.4.0

waf-check/go.sum

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,4 @@
1-
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
2-
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
3-
github.com/cheggaaa/pb/v3 v3.1.4 h1:DN8j4TVVdKu3WxVwcRKu0sG00IIU6FewoABZzXbRQeo=
4-
github.com/cheggaaa/pb/v3 v3.1.4/go.mod h1:6wVjILNBaXMs8c21qRiaUM8BR82erfgau1DQ4iUXmSA=
5-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7-
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
8-
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
9-
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
10-
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
11-
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
12-
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
13-
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
14-
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
15-
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
16-
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
17-
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
18-
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
19-
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
20-
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
21-
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
22-
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
23-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
24-
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
25-
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
26-
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
27-
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
28-
github.com/schollz/progressbar/v3 v3.14.1 h1:VD+MJPCr4s3wdhTc7OEJ/Z3dAeBzJ7yKH/P4lC5yRTI=
29-
github.com/schollz/progressbar/v3 v3.14.1/go.mod h1:Zc9xXneTzWXF81TGoqL71u0sBPjULtEHYtj/WVgVy8E=
30-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
31-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
32-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
33-
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
34-
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
35-
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
36-
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
37-
golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8=
38-
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
1+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
392
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
403
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
414
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

waf-check/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,4 @@ func main() {
6464
}
6565

6666
fmt.Printf("everything went well!\n")
67-
6867
}

waf-check/manager.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ func (m *Manager) processFile(file string) {
9595
}
9696

9797
m.resultsChan <- result
98-
9998
}
10099

101100
func NewManager(config Config, filesList []string) Manager {

waf-check/result.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func GetResult(resultsChan chan Result, outputFolder string) error {
3333
if err != nil {
3434
log.Fatalf("unable to marshal: %+v", result)
3535
}
36-
if err := os.WriteFile(failedTestsPath, jsonData, 0644); err != nil {
36+
if err := os.WriteFile(failedTestsPath, jsonData, 0o644); err != nil {
3737
log.Fatalf("unable to write failed report '%s': %s", failedTestsPath, err)
3838
}
3939
fmt.Printf(" - failed tests report: '%s'\n", failedTestsPath)

waf-check/utils.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func listJSONFiles(folderPath string) ([]string, error) {
2222
}
2323
return nil
2424
})
25-
2625
if err != nil {
2726
return filesList, fmt.Errorf("error walking '%s': %s", folderPath, err)
2827
}
@@ -71,7 +70,7 @@ func unzip(src, dest string) error {
7170
}
7271
defer r.Close()
7372

74-
os.MkdirAll(dest, 0755)
73+
os.MkdirAll(dest, 0o755)
7574

7675
for _, f := range r.File {
7776
fPath := filepath.Join(dest, f.Name)

0 commit comments

Comments
 (0)