Skip to content

Commit 1507e62

Browse files
committed
feat: introduce linter to run on PR builds
Signed-off-by: Kay Yan <[email protected]>
1 parent 6db7ba8 commit 1507e62

File tree

4 files changed

+167
-1
lines changed

4 files changed

+167
-1
lines changed

.github/workflows/golangci_lint.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Run golangci-lint
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
golangci-lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check out code into the Go module directory
12+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
13+
14+
- name: golangci-lint
15+
uses: reviewdog/action-golangci-lint@7708105983c614f7a2725e2172908b7709d1c3e4 # v2
16+
with:
17+
github_token: ${{ secrets.GITHUB_TOKEN }}
18+
reporter: github-pr-check
19+
golangci_lint_flags: "--timeout=240s"
20+
level: warning

.golangci.yml

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
run:
3+
concurrency: 6
4+
linters:
5+
disable-all: true
6+
enable:
7+
# - depguard
8+
- gofmt
9+
- goimports
10+
- govet
11+
- ineffassign
12+
- misspell
13+
- nakedret
14+
- prealloc
15+
- typecheck
16+
# - asciicheck
17+
# - bodyclose
18+
# - dogsled
19+
# - dupl
20+
# - errcheck
21+
# - errorlint
22+
# - exhaustive
23+
# - exhaustivestruct
24+
# - exportloopref
25+
# - funlen
26+
# - gci
27+
# - gochecknoglobals
28+
# - gochecknoinits
29+
# - gocognit
30+
# - goconst
31+
# - gocritic
32+
# - gocyclo
33+
# - godot
34+
# - godox
35+
# - goerr113
36+
# - gofumpt
37+
# - goheader
38+
# - golint
39+
# - gomnd
40+
# - gomodguard
41+
# - goprintffuncname
42+
# - gosec (gas)
43+
- gosimple # (megacheck)
44+
# - interfacer
45+
# - lll
46+
# - maligned
47+
# - nestif
48+
# - nlreturn
49+
# - noctx
50+
# - nolintlint
51+
- revive
52+
# - rowserrcheck
53+
# - scopelint
54+
# - sqlclosecheck
55+
- staticcheck
56+
- stylecheck
57+
# - testpackage
58+
# - tparallel
59+
- unconvert
60+
# - unparam
61+
- unused
62+
# - whitespace
63+
# - wrapcheck
64+
# - wsl
65+
linters-settings:
66+
gocritic:
67+
enabled-checks:
68+
# Diagnostic
69+
- appendAssign
70+
- argOrder
71+
- badCond
72+
- caseOrder
73+
- codegenComment
74+
- commentedOutCode
75+
- deprecatedComment
76+
- dupArg
77+
- dupBranchBody
78+
- dupCase
79+
- dupSubExpr
80+
- exitAfterDefer
81+
- flagDeref
82+
- flagName
83+
- nilValReturn
84+
- offBy1
85+
- sloppyReassign
86+
- weakCond
87+
- octalLiteral
88+
89+
# Performance
90+
- appendCombine
91+
- equalFold
92+
- hugeParam
93+
- indexAlloc
94+
- rangeExprCopy
95+
- rangeValCopy
96+
97+
# Style
98+
- assignOp
99+
- boolExprSimplify
100+
- captLocal
101+
- commentFormatting
102+
- commentedOutImport
103+
- defaultCaseOrder
104+
- docStub
105+
- elseif
106+
- emptyFallthrough
107+
- emptyStringTest
108+
- hexLiteral
109+
- ifElseChain
110+
- methodExprCall
111+
- regexpMust
112+
- singleCaseSwitch
113+
- sloppyLen
114+
- stringXbytes
115+
- switchTrue
116+
- typeAssertChain
117+
- typeSwitchVar
118+
- underef
119+
- unlabelStmt
120+
- unlambda
121+
- unslice
122+
- valSwap
123+
- wrapperFunc
124+
- yodaStyleExpr
125+
126+
# Opinionated
127+
- builtinShadow
128+
- importShadow
129+
- initClause
130+
- nestingReduce
131+
- paramTypeCombine
132+
- ptrToRefParam
133+
- typeUnparen
134+
- unnamedResult
135+
- unnecessaryBlock
136+
137+
issues:
138+
exclude-rules:
139+
- linters:
140+
- revive
141+
text: "unused-parameter"

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ fmt: ## Run go fmt against code.
5454
vet: ## Run go vet against code.
5555
go vet ./...
5656

57+
## lint: Run go lint against code.
58+
.PHONY: lint
59+
lint:
60+
@golangci-lint run -v --timeout=5m ./...
61+
5762
.PHONY: test
5863
test: manifests generate fmt vet envtest ## Run tests.
5964
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

controllers/analysis_step.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (step *AnalysisStep) execute(instance *K8sGPTInstance) (ctrl.Result, error)
6363
}
6464

6565
// Prior to creating or updating any results we will delete any stale results that
66-
// no longer are relevent, we can do this by using the resultSpec composed name against
66+
// no longer are relevant, we can do this by using the resultSpec composed name against
6767
// the custom resource name
6868
err = step.cleanUpStaleResults(rawResults, instance)
6969
if err != nil {

0 commit comments

Comments
 (0)