Skip to content

Commit

Permalink
Add golangci-lint config (#55)
Browse files Browse the repository at this point in the history
* Update Makefile

* Prepare Linting

* Importas

* importas

* Importas

* eppnats

* emlogger

* ceeventv2

* eppapi

* matsgo

* cev2

* eventingv1alpha1, eventingv2alpha1, epptestingutils

* ocpropagation

* Hint for naming convention

* Rename alias golog --> log

* Cloud Events without version

* Remove versions

* Centralized

* Go lint

* Importas lint
  • Loading branch information
the1bit authored and Tibor Kiss committed Sep 3, 2024
1 parent 391f925 commit 16027db
Show file tree
Hide file tree
Showing 37 changed files with 316 additions and 568 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/lint-go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Lint Go code

on:
pull_request:
branches:
- "main"
- "release-*"
paths-ignore:
- 'docs/**'
- '**.md'
- 'sec-scanners-config.yaml'

jobs:
code-linter:
name: "Run golangci-lint"
uses: kyma-project/eventing-tools/.github/workflows/lint-go-reusable.yml@main
with:
go-version: '1.21'
lint-config-uri: https://raw.githubusercontent.com/kyma-project/eventing-tools/b740019d37e5b69c1a1383c71bb5fb5a44c6534e/config/lint/.golangci.yaml
30 changes: 0 additions & 30 deletions .github/workflows/lint.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ vendor/

**/.env
**/.env.dev


# Lint files
lint-report.json
.golangci.yaml

281 changes: 0 additions & 281 deletions .golangci.yaml

This file was deleted.

37 changes: 36 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ IMG_REGISTRY_PORT ?= 8888
IMG_REGISTRY ?= op-skr-registry.localhost:$(IMG_REGISTRY_PORT)/unsigned/eventing-images
IMG ?= $(IMG_REGISTRY)/$(APP_NAME):$(APP_VERSION)

# Lint issue category
CATEGORY = "default"

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
Expand Down Expand Up @@ -40,9 +43,41 @@ help: ## Display this help.
##@ Development

.PHONY: lint
lint: ## Check and fix lint issues using `golangci-lint`
lint: ## Check lint issues using `golangci-lint`
golangci-lint run --timeout 5m --config=./.golangci.yaml

.PHONY: lint-compact
lint-compact: ## Check lint issues using `golangci-lint` in compact result format
golangci-lint run --timeout 5m --config=./.golangci.yaml --print-issued-lines=false

.PHONY: lint-fix
lint-fix: ## Check and fix lint issues using `golangci-lint`
golangci-lint run --fix --timeout 5m --config=./.golangci.yaml

.PHONY: lint-report
lint-report: ## Check lint issues using `golangci-lint` then export them to a file, then print the list of linters used
golangci-lint run --timeout 5m --config=./.golangci.yaml --issues-exit-code 0 --out-format json > ./lint-report.json

.PHONY: lint-report-issue-category
lint-report-issue-category: ## Get lint issues categories
make lint-report-clean
make lint-report
cat ./lint-report.json | jq '.Issues[].FromLinter' | jq -s 'map({(.):1})|add|keys_unsorted'

.PHONY: lint-report-get-category
lint-report-get-category: ## Get lint issues by category
cat ./lint-report.json | jq --arg CATEGORY $$CATEGORY '.Issues[] | select(.FromLinter==$$CATEGORY)'

.PHONY: lint-report-count-issue
lint-report-count-issue: ## Count lint issues
make lint-report-clean
make lint-report
cat ./lint-report.json | jq '.Issues | length'

.PHONY: lint-report-clean
lint-report-clean: ## Clean lint report
rm -f ./lint-report.json

.PHONY: fmt
fmt: ## Reformat files using `go fmt`
go fmt $$($(DIRS_TO_CHECK))
Expand Down
Loading

0 comments on commit 16027db

Please sign in to comment.