-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(linter): introduces linter to check for problematic code
This way we don not have to spend time on it during code reviews and can focus on features instead. golangci-lint is set of linters which is highly customizable. This PR enables it both as a make target and GitHub action. I fixed all the problems so we can start fresh.
- Loading branch information
1 parent
1cd814f
commit c68d7e2
Showing
13 changed files
with
365 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: linters | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
jobs: | ||
go-lint: | ||
name: golangci-lint | ||
runs-on: ubuntu-20.04 | ||
env: | ||
REPOSITORY: ${{ github.repository }} | ||
steps: | ||
- name: Set up Go env | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.19 | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 1 | ||
path: go/src/github.com/${{ env.REPOSITORY }} | ||
- name: Set $GOPATH | ||
run: | | ||
echo "GOPATH=${{ github.workspace }}/go" >> $GITHUB_ENV | ||
echo "${{ github.workspace }}/go/bin" >> $GITHUB_PATH | ||
shell: bash | ||
- name: Prepare codebase for linter (generates deps, stubs) | ||
run: | | ||
cd go/src/github.com/${{ env.REPOSITORY }} | ||
make deps generate | ||
shell: bash | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: v1.53 | ||
working-directory: go/src/github.com/${{ env.REPOSITORY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
linters-settings: | ||
govet: | ||
check-shadowing: true | ||
golint: | ||
min-confidence: 0 | ||
gocyclo: | ||
min-complexity: 16 | ||
cyclop: | ||
max-complexity: 16 | ||
dupl: | ||
threshold: 128 | ||
funlen: | ||
lines: 128 | ||
statements: 64 | ||
goconst: | ||
min-len: 4 | ||
min-occurrences: 3 | ||
depguard: | ||
list-type: blacklist | ||
packages: | ||
- github.com/sirupsen/logrus | ||
- sigs.k8s.io/controller-runtime/pkg/log | ||
- sigs.k8s.io/controller-runtime/pkg/log/zap | ||
- sigs.k8s.io/controller-runtime/pkg/runtime/log | ||
misspell: | ||
locale: US | ||
ignore-words: | ||
- istio | ||
- k8s | ||
lll: | ||
line-length: 180 | ||
goimports: | ||
local-prefixes: github.com/maistra/odh-project-controller | ||
gocritic: | ||
enabled-tags: | ||
- performance | ||
- style | ||
- experimental | ||
disabled-checks: | ||
- wrapperFunc | ||
- commentFormatting # https://github.com/go-critic/go-critic/issues/755 | ||
- hugeParam # seems to be premature optimization based on https://github.com/Maistra/istio-workspace/pull/378#discussion_r392208906 | ||
nestif: | ||
min-complexity: 8 | ||
unused: | ||
check-exported: true | ||
gocognit: | ||
min-complexity: 20 | ||
wrapcheck: | ||
ignoreSigs: | ||
- .Errorf( | ||
- errors.New( | ||
- errors.Unwrap( | ||
- .Wrap( | ||
- .Wrapf( | ||
- .WithMessage( | ||
- errors.WrapIfWithDetails | ||
- errors.WithDetails( | ||
- errors.WrapWithDetails( | ||
- errors.WrapIf( | ||
- errors.NewWithDetails( | ||
|
||
linters: | ||
enable-all: true | ||
disable: | ||
- depguard | ||
- exhaustruct | ||
- exhaustivestruct | ||
- forbidigo | ||
- gofmt # We use goimports and when using them both leads to contradicting errors | ||
- gofumpt | ||
- gomnd | ||
- paralleltest | ||
- prealloc | ||
|
||
run: | ||
deadline: 10m | ||
|
||
output: | ||
format: colored-line-number | ||
print-issued-lines: true | ||
print-linter-name: true | ||
|
||
issues: | ||
max-issues-per-linter: 0 | ||
max-same-issues: 0 | ||
exclude-rules: | ||
- path: test/ | ||
linters: | ||
- goconst | ||
- gocyclo | ||
- golint | ||
- errcheck | ||
- dupl | ||
- gosec | ||
- revive | ||
- stylecheck | ||
- wrapcheck | ||
# Exclude particular linters for tests files. | ||
- path: _test\.go | ||
linters: | ||
- gochecknoglobals | ||
- gocyclo | ||
- errcheck | ||
- dupl | ||
- gosec | ||
- revive | ||
- wrapcheck | ||
- path: _suite_test\.go | ||
linters: | ||
- revive | ||
- unused |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.