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

chore: enhance golangci-lint with code complexity and other measures #484

Merged
merged 9 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 0 additions & 5 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: CI
on:
# always execute docker build when something is pushed to main or a maintenance branch
push:
branches:
- 'main'
- '[0-9]+.[1-9][0-9]*.x'
# in addition, execute for pull requests to those branches
pull_request:
branches:
- 'main'
Expand Down Expand Up @@ -69,7 +67,6 @@ jobs:
folder: "operator/"
- name: "scheduler"
folder: "scheduler/"
# Nothing to test in functions-runtime
steps:
- name: Check out code
uses: actions/checkout@v3
Expand All @@ -90,7 +87,6 @@ jobs:
with:
flags: ${{ matrix.config.name }}


build_image:
name: Build Docker Image
needs: prepare_ci_run
Expand Down Expand Up @@ -168,7 +164,6 @@ jobs:
needs: prepare_ci_run
uses: ./.github/workflows/component-test.yml


integration_tests:
name: Integration Tests
needs: [ prepare_ci_run, build_image ]
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
name: golangci-lint
on: pull_request
on:
push:
branches:
- 'main'
- '[0-9]+.[1-9][0-9]*.x'
pull_request:
branches:
- 'main'
- '[0-9]+.[1-9][0-9]*.x'
env:
GOLANGCI_LINT_VERSION: "v1.50.1"
GO_VERSION: "1.19"
Expand Down
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ linters:
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
- nilnil # Checks that there is no simultaneous return of nil error and an invalid value.
- noctx # noctx finds sending http request without context.Context
- gocyclo # measure cyclomatic complexity
mowies marked this conversation as resolved.
Show resolved Hide resolved
- gocognit # measure cognitive complexity
- funlen # limit function length

issues:
exclude-rules:
Expand All @@ -18,4 +21,14 @@ issues:
text: '//+kubebuilder'
- linters:
- containedctx
- gocyclo
path: _test\.go

linters-settings:
gocyclo:
min-complexity: 10
gocognit:
min-complexity: 20
funlen:
lines: 120
statements: 120
14 changes: 9 additions & 5 deletions operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests fmt vet generate envtest ## Run tests.
go test ./api/... -v
go test ./controllers/... -v -coverprofile cover-pkg.out
go test ./webhooks/... -v -coverprofile cover-main.out
cat cover-main.out cover-pkg.out > cover.out
rm cover-pkg.out cover-main.out
go test ./api/... -v -coverprofile cover-api.out
go test ./controllers/... -v -coverprofile cover-pkg.out
go test ./webhooks/... -v -coverprofile cover-main.out
sed -i '/mode: set/d' cover-api.out
sed -i '/mode: set/d' cover-pkg.out
sed -i '/mode: set/d' cover-main.out
echo "mode: set" > cover.out
cat cover-main.out cover-pkg.out cover-api.out >> cover.out
rm cover-pkg.out cover-main.out cover-api.out

.PHONY: component-test
component-test: manifests generate envtest ## Run tests.
Expand Down
5 changes: 4 additions & 1 deletion scheduler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ test: manifests fmt vet envtest## Run tests.
go test ./pkg/... -coverprofile cover-pkg.out
go test ./cmd/scheduler -coverprofile cover-main.out
go test ./test/... -v -ginkgo.skip-file="e2e"
cat cover-main.out cover-pkg.out > cover.out
sed -i '/mode: set/d' cover-pkg.out
sed -i '/mode: set/d' cover-main.out
echo "mode: set" > cover.out
cat cover-main.out cover-pkg.out >> cover.out
rm cover-pkg.out cover-main.out


Expand Down