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
|
- name: Lint
|
||||||
uses: golangci/golangci-lint-action@v3.7.0
|
uses: golangci/golangci-lint-action@v3.7.0
|
||||||
with:
|
with:
|
||||||
version: v1.52
|
version: v1.54
|
||||||
args: --deadline=30m
|
args: --deadline=30m
|
||||||
skip-cache: true # https://github.com/golangci/golangci-lint-action/issues/244#issuecomment-1052197778
|
skip-cache: true # https://github.com/golangci/golangci-lint-action/issues/244#issuecomment-1052197778
|
||||||
if: matrix.operating-system == 'ubuntu-latest'
|
if: matrix.operating-system == 'ubuntu-latest'
|
||||||
|
|||||||
@@ -32,6 +32,17 @@ linters-settings:
|
|||||||
- prefix(github.com/aquasecurity/)
|
- prefix(github.com/aquasecurity/)
|
||||||
- blank
|
- blank
|
||||||
- dot
|
- 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:
|
linters:
|
||||||
disable-all: true
|
disable-all: true
|
||||||
@@ -47,12 +58,15 @@ linters:
|
|||||||
- gocyclo
|
- gocyclo
|
||||||
- gofmt
|
- gofmt
|
||||||
- misspell
|
- misspell
|
||||||
|
- bodyclose
|
||||||
- gci
|
- gci
|
||||||
|
- gomodguard
|
||||||
|
- tenv
|
||||||
|
|
||||||
run:
|
run:
|
||||||
go: '1.20'
|
go: '1.20'
|
||||||
skip-files:
|
skip-files:
|
||||||
- ".*._mock.go$"
|
- ".*_mock.go$"
|
||||||
- ".*_test.go$"
|
- ".*_test.go$"
|
||||||
- "integration/*"
|
- "integration/*"
|
||||||
- "examples/*"
|
- "examples/*"
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ $ ./trivy -h
|
|||||||
You must pass the linter checks:
|
You must pass the linter checks:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ mage lint
|
$ mage lint:run
|
||||||
```
|
```
|
||||||
|
|
||||||
Additionally, you need to have run `go mod tidy`, so execute the following command as well:
|
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
|
$ mage tidy
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To autofix linters use the following command:
|
||||||
|
```shell
|
||||||
|
$ mage lint:fix
|
||||||
|
```
|
||||||
|
|
||||||
### Unit tests
|
### Unit tests
|
||||||
Your PR must pass all the unit tests. You can test it as below.
|
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
|
// GolangciLint installs golangci-lint
|
||||||
func (Tool) GolangciLint() error {
|
func (Tool) GolangciLint() error {
|
||||||
const version = "v1.52.2"
|
const version = "v1.54.2"
|
||||||
if exists(filepath.Join(GOBIN, "golangci-lint")) {
|
if exists(filepath.Join(GOBIN, "golangci-lint")) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -277,12 +277,20 @@ func (Test) UpdateVMGolden() error {
|
|||||||
return sh.RunWithV(ENV, "go", "test", "-v", "-tags=vm_integration", "./integration/...", "-update")
|
return sh.RunWithV(ENV, "go", "test", "-v", "-tags=vm_integration", "./integration/...", "-update")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lint runs linters
|
type Lint mg.Namespace
|
||||||
func Lint() error {
|
|
||||||
|
// Run runs linters
|
||||||
|
func (Lint) Run() error {
|
||||||
mg.Deps(Tool{}.GolangciLint)
|
mg.Deps(Tool{}.GolangciLint)
|
||||||
return sh.RunV("golangci-lint", "run", "--timeout", "5m")
|
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
|
// Fmt formats Go code and proto files
|
||||||
func Fmt() error {
|
func Fmt() error {
|
||||||
// Check if clang-format is installed
|
// Check if clang-format is installed
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func (g *Registry) CheckOptions(domain string, option types.RegistryOptions) err
|
|||||||
return nil
|
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
|
var credStore store.GCRCredStore
|
||||||
if g.Store == nil {
|
if g.Store == nil {
|
||||||
credStore, err = store.DefaultGCRCredStore()
|
credStore, err = store.DefaultGCRCredStore()
|
||||||
|
|||||||
Reference in New Issue
Block a user