Skip to content

Commit 41319c0

Browse files
committed
Add golangci-lint to CI
Signed-off-by: Austin Vazquez <[email protected]>
1 parent ec3cfb6 commit 41319c0

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,38 @@ jobs:
4747

4848
- name: Run tests
4949
run: make test
50+
51+
lint:
52+
name: Lint
53+
runs-on: ubuntu-latest
54+
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@v4
58+
59+
- name: Set up Go
60+
uses: actions/setup-go@v5
61+
with:
62+
go-version: stable
63+
64+
- name: golangci-lint (apparmor)
65+
id: lint-apparmor
66+
uses: golangci/golangci-lint-action@v8
67+
with:
68+
version: latest
69+
working-directory: apparmor
70+
continue-on-error: true
71+
72+
- name: golangci-lint (seccomp)
73+
id: lint-seccomp
74+
uses: golangci/golangci-lint-action@v8
75+
with:
76+
version: latest
77+
working-directory: seccomp
78+
continue-on-error: true
79+
80+
- name: Check lint results
81+
if: steps.lint-apparmor.outcome == 'failure' || steps.lint-seccomp.outcome == 'failure'
82+
run: |
83+
echo "One or more lint checks failed"
84+
exit 1

.golangci.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
version: "2"
2+
3+
run:
4+
issues-exit-code: 1
5+
tests: true
6+
7+
formatters:
8+
enable:
9+
- gofmt
10+
- goimports
11+
12+
linters:
13+
enable:
14+
- asasalint # Detects "[]any" used as argument for variadic "func(...any)".
15+
- copyloopvar # Detects places where loop variables are copied.
16+
- depguard
17+
- dogsled # Detects assignments with too many blank identifiers.
18+
- dupword # Detects duplicate words.
19+
- durationcheck # Detect cases where two time.Duration values are being multiplied in possibly erroneous ways.
20+
- errorlint # Detects code that will cause problems with the error wrapping scheme introduced in Go 1.13.
21+
- errchkjson # Detects unsupported types passed to json encoding functions and reports if checks for the returned error can be omitted.
22+
- exhaustive # Detects missing options in enum switch statements.
23+
- exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions.
24+
- fatcontext # Detects nested contexts in loops and function literals.
25+
- forbidigo
26+
- gocheckcompilerdirectives # Detects invalid go compiler directive comments (//go:).
27+
- gocritic # Detects for bugs, performance and style issues.
28+
- gosec # Detects security problems.
29+
- govet
30+
- iface # Detects incorrect use of interfaces. Currently only used for "identical" interfaces in the same package.
31+
- importas
32+
- ineffassign
33+
- makezero # Finds slice declarations with non-zero initial length.
34+
- mirror # Detects wrong mirror patterns of bytes/strings usage.
35+
- misspell # Detects commonly misspelled English words in comments.
36+
- nakedret # Detects uses of naked returns.
37+
- nilnesserr # Detects returning nil errors. It combines the features of nilness and nilerr,
38+
- nosprintfhostport # Detects misuse of Sprintf to construct a host with port in a URL.
39+
- reassign # Detects reassigning a top-level variable in another package.
40+
- revive # Metalinter; drop-in replacement for golint.
41+
- spancheck # Detects mistakes with OpenTelemetry/Census spans.
42+
- staticcheck
43+
- thelper
44+
- unconvert # Detects unnecessary type conversions.
45+
- unused
46+
- usestdlibvars # Detects the possibility to use variables/constants from the Go standard library.
47+
- wastedassign # Detects wasted assignment statements.
48+
49+
disable:
50+
- errcheck
51+
- depguard # TODO(austinvazquez): Enable this linter after fixing the issues it reports.
52+
53+
settings:
54+
errorlint:
55+
# Check whether fmt.Errorf uses the %w verb for formatting errors.
56+
errorf: false
57+
# See the https://github.com/polyfloyd/go-errorlint for caveats.
58+
asserts: false
59+
60+
gosec:
61+
excludes:
62+
- G304 # G304: Potential file inclusion via variable.
63+
- G306 # G306: Expect WriteFile permissions to be 0600 or less (too restrictive; also flags "0o644" permissions)
64+
65+
revive:
66+
rules:
67+
- name: package-comments
68+
disabled: true
69+
70+
staticcheck:
71+
checks:
72+
- all
73+
- -ST1000 # Incorrect or missing package comment; https://staticcheck.dev/docs/checks/#ST1000
74+
- -ST1005 # Incorrectly formatted error string; https://staticcheck.dev/docs/checks/#ST1005

0 commit comments

Comments
 (0)