Skip to content

Commit

Permalink
Run revive using golang-lint-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
phillebaba committed May 14, 2024
1 parent 488a9ad commit 478d7b2
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 113 deletions.
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pre-commit install
# install goimports
go install golang.org/x/tools/cmd/goimports@latest

# install revive
go install github.com/mgechev/revive@latest
# install golang-ci-lint
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
```

Now every time you commit, the hooks will run and format your code, linting can be called via `make lint-go`.
Expand Down
11 changes: 3 additions & 8 deletions .github/workflows/scan-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Run Revive Action by pulling pre-built image
uses: docker://morphy/revive-action:v2.5.7@sha256:087d4e61077087755711ab7e9fae3cc899b7bb07ff8f6a30c3dfb240b1620ae8
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
config: hack/revive.toml
# Exclude patterns, separated by semicolons (optional)
exclude: "src/cmd/viper.go"
# Path pattern (default: ./...)
path: "./src/..."
version: v1.58.1
22 changes: 22 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
run:
timeout: 5m
linters:
disable-all: true
enable:
- gosimple
- govet
- staticcheck
- unused
- revive
- goheader
- goimports
linters-settings:
goheader:
template: |-
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: 2021-Present The Zarf Authors
issues:
exclude-rules:
- path: "src/cmd/tools/helm/(.*).go"
linters:
- goheader
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ repos:
language: system
pass_filenames: true
- id: lint
name: revive go lint
entry: revive
name: golang-ci-lint go lint
entry: golang-ci-lint
args:
- "-config"
- "hack/revive.toml"
- "-exclude"
- "src/cmd/viper.go"
- "run"
files: .go$
language: system
pass_filenames: true
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,5 @@ cve-report: ## Create a CVE report for the current project (must `brew install g
@test -d ./build || mkdir ./build
go run main.go tools sbom scan . -o json --exclude './site' --exclude './examples' | grype -o template -t hack/grype.tmpl > build/zarf-known-cves.csv

lint-go: ## Run revive to lint the go code (must `brew install revive` first)
revive -config hack/revive.toml -exclude src/cmd/viper.go -formatter stylish ./src/...
@hack/check-spdx-go.sh src >/dev/null || (echo "SPDX check for go failed, please run 'hack/check-spdx-go.sh src' to see the errors" && exit 1)
lint-go: ## Run golang-ci-lint to lint the go code (must `brew install golang-ci-lint` first)
golangci-lint run
63 changes: 0 additions & 63 deletions hack/check-spdx-go.sh

This file was deleted.

31 changes: 0 additions & 31 deletions hack/revive.toml

This file was deleted.

1 change: 1 addition & 0 deletions src/pkg/utils/bytes.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// forked from https://www.socketloop.com/tutorials/golang-byte-format-example

// Package utils provides generic utility functions.
Expand Down

0 comments on commit 478d7b2

Please sign in to comment.