Skip to content

Commit

Permalink
chore: enable more linters (#5228)
Browse files Browse the repository at this point in the history
* chore: enable more linters

* fix typos

* ci: add `verbose` option in linter action

* ci: remove `verbose` option in linter action
  • Loading branch information
DmitriyLewen authored Sep 26, 2023
1 parent 2baad46 commit 559c0f3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Lint
uses: golangci/[email protected]
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'
Expand Down
16 changes: 15 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/*"
Expand Down
7 changes: 6 additions & 1 deletion docs/community/contribute/pr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

Expand Down
14 changes: 11 additions & 3 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/image/registry/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 559c0f3

Please sign in to comment.