Skip to content

Commit

Permalink
chore: enhance golangci-lint with code complexity and other measures (#…
Browse files Browse the repository at this point in the history
…484)

Co-authored-by: odubajDT <93584209+odubajDT@users.noreply.github.com>
Closes #462
  • Loading branch information
mowies committed Dec 1, 2022
1 parent 1b3a56f commit 1d711d0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
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
11 changes: 10 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 All @@ -25,6 +33,7 @@ jobs:

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
continue-on-error: true
with:
working-directory: ${{ matrix.config.folder }}
version: ${{ env.GOLANGCI_LINT_VERSION }}
Expand Down
17 changes: 17 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
run:
timeout: 5m
go: '1.19'
issue-exit-code: 0
linters:
enable:
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
Expand All @@ -10,6 +11,10 @@ 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
- gocognit # measure cognitive complexity
- funlen # limit function length
- dupl # Detect code duplication

issues:
exclude-rules:
Expand All @@ -18,4 +23,16 @@ issues:
text: '//+kubebuilder'
- linters:
- containedctx
- gocyclo
- gocognit
- funlen
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

0 comments on commit 1d711d0

Please sign in to comment.