Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce linter to run on PR builds #592

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/golangci_lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Run golangci-lint

on:
pull_request:
branches: [main]

jobs:
golangci-lint:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: golangci-lint
uses: reviewdog/action-golangci-lint@7708105983c614f7a2725e2172908b7709d1c3e4 # v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-check
golangci_lint_flags: "--timeout=240s"
level: warning
141 changes: 141 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
run:
concurrency: 6
linters:
disable-all: true
enable:
# - depguard
- gofmt
- goimports
- govet
- ineffassign
- misspell
- nakedret
- prealloc
- typecheck
# - asciicheck
# - bodyclose
# - dogsled
# - dupl
# - errcheck
# - errorlint
# - exhaustive
# - exhaustivestruct
# - exportloopref
# - funlen
# - gci
# - gochecknoglobals
# - gochecknoinits
# - gocognit
# - goconst
# - gocritic
# - gocyclo
# - godot
# - godox
# - goerr113
# - gofumpt
# - goheader
# - golint
# - gomnd
# - gomodguard
# - goprintffuncname
# - gosec (gas)
- gosimple # (megacheck)
# - interfacer
# - lll
# - maligned
# - nestif
# - nlreturn
# - noctx
# - nolintlint
- revive
# - rowserrcheck
# - scopelint
# - sqlclosecheck
- staticcheck
- stylecheck
# - testpackage
# - tparallel
- unconvert
# - unparam
- unused
# - whitespace
# - wrapcheck
# - wsl
linters-settings:
gocritic:
enabled-checks:
# Diagnostic
- appendAssign
- argOrder
- badCond
- caseOrder
- codegenComment
- commentedOutCode
- deprecatedComment
- dupArg
- dupBranchBody
- dupCase
- dupSubExpr
- exitAfterDefer
- flagDeref
- flagName
- nilValReturn
- offBy1
- sloppyReassign
- weakCond
- octalLiteral

# Performance
- appendCombine
- equalFold
- hugeParam
- indexAlloc
- rangeExprCopy
- rangeValCopy

# Style
- assignOp
- boolExprSimplify
- captLocal
- commentFormatting
- commentedOutImport
- defaultCaseOrder
- docStub
- elseif
- emptyFallthrough
- emptyStringTest
- hexLiteral
- ifElseChain
- methodExprCall
- regexpMust
- singleCaseSwitch
- sloppyLen
- stringXbytes
- switchTrue
- typeAssertChain
- typeSwitchVar
- underef
- unlabelStmt
- unlambda
- unslice
- valSwap
- wrapperFunc
- yodaStyleExpr

# Opinionated
- builtinShadow
- importShadow
- initClause
- nestingReduce
- paramTypeCombine
- ptrToRefParam
- typeUnparen
- unnamedResult
- unnecessaryBlock

issues:
exclude-rules:
- linters:
- revive
text: "unused-parameter"
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

## lint: Run go lint against code.
.PHONY: lint
lint:
@golangci-lint run -v --timeout=5m ./...

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
Expand Down
2 changes: 1 addition & 1 deletion controllers/analysis_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (step *AnalysisStep) execute(instance *K8sGPTInstance) (ctrl.Result, error)
}

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