generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Centralized linter #57
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,38 @@ | ||
# This workflow defines a reusable Go linting flow, using Golangci-lint: https://golangci-lint.run/ | ||
# https://golangci-lint.run/usage/configuration/ | ||
|
||
name: Lint code (reusable) | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
go-version: | ||
required: true | ||
type: string | ||
description: "The Go version to use. This can be a specific version. E.g. 1.19 or 1.21.x" | ||
lint-config-uri: | ||
required: true | ||
type: string | ||
description: "The URI to the linter config file. This can be a local file or a remote file. E.g. https://raw.githubusercontent.com/kyma-project/eventing-tools/main/config/lint/.golangci.yaml" | ||
|
||
jobs: | ||
unit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ inputs.go-version }} # This can be a specific version. E.g. 1.19 or 1.21.x | ||
cache: false # Disable cache to avoid issues with different Go versions | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Download linter config | ||
run: wget -O .golangci.yaml ${{ inputs.lint-config-uri }} # This can be a remote file only. E.g. https://raw.githubusercontent.com/kyma-project/eventing-tools/main/config/lint/.golangci.yaml | ||
|
||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: v1.55 | ||
args: --timeout=5m --config=./.golangci.yaml --issues-exit-code 1 # Failed if any issues are found |
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 |
---|---|---|
|
@@ -22,4 +22,4 @@ jobs: | |
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: v1.55 | ||
args: --timeout=5m | ||
args: --timeout=5m |
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,168 @@ | ||
linters: | ||
enable-all: true | ||
disable: | ||
- contextcheck # too many false positives | ||
- deadcode # deprecated (since v1.49.0) and replaced by 'unused' | ||
- depguard # checks if package imports are whitelisted | ||
- exhaustivestruct # deprecated (since v1.46.0) and replaced by 'exhaustruct' | ||
- exhaustruct # TODO enable and fix, use regex to exclude certain cases | ||
- golint # deprecated (since v1.41.0) and replaced by 'revive' | ||
- ifshort # deprecated (since v1.48.0) | ||
- interfacer # deprecated (since v1.38.0) | ||
- lll | ||
- maligned # deprecated (since v1.38.0) | ||
- nlreturn # too strict and mostly code is not more readable | ||
- nosnakecase # deprecated (since v1.48.1) and replaced by 'revive' | ||
- scopelint # deprecated (since v1.39.0) and replaced by 'exportloopref' | ||
- structcheck # deprecated (since v1.49.0) and replaced by 'unused' | ||
- sqlclosecheck # not needed for this project | ||
- varcheck # deprecated (since v1.49.0) and replaced by 'unused' | ||
- wsl # too strict and mostly code is not more readable | ||
### disabled for now... will be enabled 1 by 1 | ||
- dupl | ||
- forcetypeassert | ||
- gosec | ||
- inamedparam | ||
- ireturn | ||
- maintidx | ||
- nolintlint | ||
- paralleltest | ||
- prealloc | ||
- testpackage | ||
- tparallel | ||
- unconvert | ||
- varnamelen | ||
- wrapcheck | ||
### Disable linters one by one | ||
- gci | ||
- tagalign | ||
- dupword | ||
- gomoddirectives | ||
- gofumpt | ||
- goerr113 | ||
- funlen | ||
- testifylint | ||
- bodyclose | ||
- containedctx | ||
- thelper | ||
- tagliatelle | ||
- errchkjson | ||
- perfsprint | ||
- noctx | ||
- godox | ||
- goconst | ||
|
||
|
||
linters-settings: | ||
stylecheck: | ||
dot-import-whitelist: | ||
- github.com/onsi/ginkgo/v2 | ||
- github.com/onsi/gomega | ||
revive: | ||
enable-all-rules: false | ||
severity: error | ||
rules: | ||
- name: comment-spacings | ||
disabled: true | ||
- name: dot-imports | ||
severity: warning | ||
disabled: true | ||
- name: line-length-limit | ||
severity: warning | ||
disabled: true | ||
arguments: [ 120 ] | ||
funlen: | ||
lines: 80 | ||
cyclop: | ||
max-complexity: 20 | ||
nestif: | ||
min-complexity: 6 | ||
gci: | ||
sections: | ||
- standard # Standard packages. | ||
- default # Imports that could not be matched to another section type. | ||
- prefix(github.com/kyma-project/eventing-manager) # Imports with the specified prefix. | ||
- blank # Blank imports. | ||
- dot # Dot imports. | ||
custom-order: true | ||
skip-generated: true | ||
importas: | ||
no-unaliased: false | ||
no-extra-aliases: true | ||
## Version number must be added as suffix to the package name. As an example check `k8s.io/api/core/v1` | ||
## kubernetes APIs get the prefix `k`. As an example check `kcorev1` | ||
## Eventing Manager APIs get the prefix `em`. As an example check `emeventingv1alpha1` | ||
## Eventing Publisher Proxy APIs get the prefix `epp`. As an example check `eppapi` | ||
## Cloud Events APIs get the prefix `ce`. As an example check `ce` | ||
## Eventing Auth Manager APIs get the prefix `eam`. | ||
## Kyma Metrics Collector APIs get the prefix `kmc`. | ||
## NATS Manager APIs get the prefix `nm`. | ||
|
||
alias: | ||
- pkg: "log" | ||
alias: log | ||
- pkg: k8s.io/api/core/v1 | ||
alias: kcorev1 | ||
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1 | ||
alias: kmetav1 | ||
- pkg: k8s.io/client-go/dynamic/fake | ||
alias: kdynamicfake | ||
- pkg: github.com/nats-io/nats.go | ||
alias: natsgo | ||
- pkg: go.opencensus.io/trace/propagation | ||
alias: ocpropagation | ||
- pkg: github.com/kyma-project/eventing-publisher-proxy/testing | ||
alias: epptestingutils | ||
- pkg: github.com/kyma-project/eventing-publisher-proxy/pkg/legacy/api | ||
alias: eppapi | ||
- pkg: github.com/kyma-project/eventing-publisher-proxy/pkg/nats | ||
alias: eppnats | ||
- pkg : github.com/kyma-project/eventing-manager/pkg/logger | ||
alias: emlogger | ||
- pkg: github.com/kyma-project/eventing-manager/api/eventing/v1alpha1 | ||
alias: emeventingv1alpha1 | ||
- pkg: github.com/kyma-project/eventing-manager/api/eventing/v1alpha2 | ||
alias: emeventingv2alpha1 | ||
- pkg : github.com/cloudevents/sdk-go/v2 | ||
alias: ce | ||
- pkg : github.com/cloudevents/sdk-go/v2/protocol/http | ||
alias: cehttp | ||
- pkg : github.com/cloudevents/sdk-go/v2/event | ||
alias: ceevent | ||
- pkg : github.com/cloudevents/sdk-go/v2/client | ||
alias: ceclient | ||
- pkg : github.com/kyma-project/kyma/components/central-application-gateway/pkg/apis/applicationconnector/v1alpha1 | ||
alias: kymaappconnv1alpha1 | ||
|
||
|
||
|
||
ireturn: | ||
allow: | ||
- anon | ||
- error | ||
- empty | ||
- stdlib | ||
- Client | ||
- client.Object | ||
- (or|er)$ | ||
wrapcheck: | ||
ignorePackageGlobs: | ||
issues: | ||
exclude-rules: | ||
- path: "_test\\.go" | ||
linters: | ||
- wrapcheck | ||
- gochecknoglobals | ||
- funlen # Table driven unit and integration tests exceed function length by design | ||
- maintidx # Table driven unit and integration tests exceed maintainability index by design | ||
- linters: | ||
- importas | ||
text: has alias "" which is not part of config # Ignore false positives that emerged due to https://github.com/julz/importas/issues/15. | ||
max-issues-per-linter: 0 | ||
max-same-issues: 0 | ||
output: | ||
sort-results: true | ||
run: | ||
timeout: 15m | ||
skip-files: | ||
- zz_generated.deepcopy.go |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you want to replace the existing one so we do not have this twice.
https://github.com/kyma-project/eventing-tools/blob/main/.github/workflows/lint-reusable.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just apply your changes to the existing file instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to replace it. The only reason I did not do it, because Eventing Manager uses it. I don't want to kill that solution, until this solution will work fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats reasonable. Then, let's keep it for now.