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

ci: run revive using golang-lint-ci #2499

Merged
merged 5 commits into from
May 15, 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
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
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved
- 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"
phillebaba marked this conversation as resolved.
Show resolved Hide resolved
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
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading