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

Add golangci-lint config #55

Merged
merged 22 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading