mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-12 15:50:15 -08:00
chore: enable more linters (#5228)
* chore: enable more linters * fix typos * ci: add `verbose` option in linter action * ci: remove `verbose` option in linter action
This commit is contained in:
2
.github/workflows/test.yaml
vendored
2
.github/workflows/test.yaml
vendored
@@ -43,7 +43,7 @@ jobs:
|
||||
- name: Lint
|
||||
uses: golangci/golangci-lint-action@v3.7.0
|
||||
with:
|
||||
version: v1.52
|
||||
version: v1.54
|
||||
args: --deadline=30m
|
||||
skip-cache: true # https://github.com/golangci/golangci-lint-action/issues/244#issuecomment-1052197778
|
||||
if: matrix.operating-system == 'ubuntu-latest'
|
||||
|
||||
@@ -32,6 +32,17 @@ linters-settings:
|
||||
- prefix(github.com/aquasecurity/)
|
||||
- blank
|
||||
- dot
|
||||
gomodguard:
|
||||
blocked:
|
||||
modules:
|
||||
- github.com/hashicorp/go-version:
|
||||
recommendations:
|
||||
- github.com/aquasecurity/go-version
|
||||
reason: "`aquasecurity/go-version` is designed for our use-cases"
|
||||
- github.com/Masterminds/semver:
|
||||
recommendations:
|
||||
- github.com/aquasecurity/go-version
|
||||
reason: "`aquasecurity/go-version` is designed for our use-cases"
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
@@ -47,12 +58,15 @@ linters:
|
||||
- gocyclo
|
||||
- gofmt
|
||||
- misspell
|
||||
- bodyclose
|
||||
- gci
|
||||
- gomodguard
|
||||
- tenv
|
||||
|
||||
run:
|
||||
go: '1.20'
|
||||
skip-files:
|
||||
- ".*._mock.go$"
|
||||
- ".*_mock.go$"
|
||||
- ".*_test.go$"
|
||||
- "integration/*"
|
||||
- "examples/*"
|
||||
|
||||
@@ -27,7 +27,7 @@ $ ./trivy -h
|
||||
You must pass the linter checks:
|
||||
|
||||
```shell
|
||||
$ mage lint
|
||||
$ mage lint:run
|
||||
```
|
||||
|
||||
Additionally, you need to have run `go mod tidy`, so execute the following command as well:
|
||||
@@ -36,6 +36,11 @@ Additionally, you need to have run `go mod tidy`, so execute the following comma
|
||||
$ mage tidy
|
||||
```
|
||||
|
||||
To autofix linters use the following command:
|
||||
```shell
|
||||
$ mage lint:fix
|
||||
```
|
||||
|
||||
### Unit tests
|
||||
Your PR must pass all the unit tests. You can test it as below.
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ func (Tool) Wire() error {
|
||||
|
||||
// GolangciLint installs golangci-lint
|
||||
func (Tool) GolangciLint() error {
|
||||
const version = "v1.52.2"
|
||||
const version = "v1.54.2"
|
||||
if exists(filepath.Join(GOBIN, "golangci-lint")) {
|
||||
return nil
|
||||
}
|
||||
@@ -277,12 +277,20 @@ func (Test) UpdateVMGolden() error {
|
||||
return sh.RunWithV(ENV, "go", "test", "-v", "-tags=vm_integration", "./integration/...", "-update")
|
||||
}
|
||||
|
||||
// Lint runs linters
|
||||
func Lint() error {
|
||||
type Lint mg.Namespace
|
||||
|
||||
// Run runs linters
|
||||
func (Lint) Run() error {
|
||||
mg.Deps(Tool{}.GolangciLint)
|
||||
return sh.RunV("golangci-lint", "run", "--timeout", "5m")
|
||||
}
|
||||
|
||||
// Fix auto fixes linters
|
||||
func (Lint) Fix() error {
|
||||
mg.Deps(Tool{}.GolangciLint)
|
||||
return sh.RunV("golangci-lint", "run", "--timeout", "5m", "--fix")
|
||||
}
|
||||
|
||||
// Fmt formats Go code and proto files
|
||||
func Fmt() error {
|
||||
// Check if clang-format is installed
|
||||
|
||||
@@ -34,7 +34,7 @@ func (g *Registry) CheckOptions(domain string, option types.RegistryOptions) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Registry) GetCredential(ctx context.Context) (username, password string, err error) {
|
||||
func (g *Registry) GetCredential(_ context.Context) (username, password string, err error) {
|
||||
var credStore store.GCRCredStore
|
||||
if g.Store == nil {
|
||||
credStore, err = store.DefaultGCRCredStore()
|
||||
|
||||
Reference in New Issue
Block a user