Skip to content

Commit

Permalink
ci: run revive using golang-lint-ci (#2499)
Browse files Browse the repository at this point in the history
## Description

This replaces revive with golang-ci-lint, and instead runs revive
through the aforementioned tool. Additionally it replaces the header
check script with the goheader linter. The benefit of this change is
that we can enable more linters along with revive in the future.

## Related Issue

Part of #2503 

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/.github/CONTRIBUTING.md#developer-workflow)
followed

---------

Co-authored-by: Austin Abro <37223396+AustinAbro321@users.noreply.github.com>
Co-authored-by: razzle <harry@razzle.cloud>
  • Loading branch information
3 people committed May 15, 2024
1 parent 53465d7 commit 04d9e0e
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 127 deletions.
7 changes: 2 additions & 5 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ We use [pre-commit](https://pre-commit.com/) to manage our pre-commit hooks. Thi
# install hooks
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: 2 additions & 9 deletions .github/workflows/scan-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,5 @@ 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
with:
config: hack/revive.toml
# Exclude patterns, separated by semicolons (optional)
exclude: "src/cmd/viper.go"
# Path pattern (default: ./...)
path: "./src/..."
- name: Run golangci-lint
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
62 changes: 62 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
run:
timeout: 5m
linters:
disable-all: true
enable:
- gosimple
- govet
- staticcheck
- unused
- revive
- goheader
- goimports
- nolintlint
linters-settings:
govet:
enable-all: true
disable:
- shadow
- fieldalignment
- unusedwrite
nolintlint:
require-specific: true
goheader:
template: |-
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: 2021-Present The Zarf Authors
revive:
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
issues:
# Revive rules that are disabled by default.
include:
- EXC0012
- EXC0013
- EXC0014
- EXC0015
# Exclude linting code copied from Helm.
exclude-dirs:
- "src/cmd/tools/helm"
24 changes: 8 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,16 @@ repos:
language: script
- id: goimports
name: goimports
entry: goimports
files: .go$
args:
- -l
- -w
language: system
entry: golangci-lint run --enable-only goimports --fix
types: [go]
language: golang
pass_filenames: true
- id: lint
name: revive go lint
entry: revive
args:
- "-config"
- "hack/revive.toml"
- "-exclude"
- "src/cmd/viper.go"
files: .go$
language: system
pass_filenames: true
name: golangci-lint go lint
entry: golangci-lint run
types: [go]
language: golang
pass_filenames: false
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.14.0
hooks:
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 04d9e0e

Please sign in to comment.