From fe5c0de64e3f2df22c463b9f17bcc5dd21ff132e Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 3 Apr 2025 13:56:44 +0200 Subject: [PATCH] CI: golangci-lint v2 --- .github/workflows/lint.yml | 9 +- .golangci.yml | 283 ++++++++++++++++--------------------- pkg/custom/custom.go | 2 +- pkg/custom/custom_test.go | 2 +- 4 files changed, 131 insertions(+), 165 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4690d83..af6fa4d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,7 +16,6 @@ jobs: security-events: write steps: - - name: Check out code into the Go module directory uses: actions/checkout@v4 with: @@ -37,11 +36,11 @@ jobs: make build - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.64 - args: --issues-exit-code=1 --timeout 10m - only-new-issues: false + version: v2.0 + args: --issues-exit-code=1 --timeout 10m + only-new-issues: false - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 diff --git a/.golangci.yml b/.golangci.yml index 872c5e3..17e2c03 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,167 +1,134 @@ -# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml - -linters-settings: - gci: - sections: - - standard - - default - - prefix(github.com/crowdsecurity) - - prefix(github.com/crowdsecurity/crowdsec) - - prefix(github.com/crowdsecurity/cs-custom-bouncer) - - govet: - enable-all: true - disable: - - fieldalignment - - misspell: - locale: US - - nlreturn: - block-size: 4 - - nolintlint: - allow-unused: false # report any unused nolint directives - require-explanation: false # don't require an explanation for nolint directives - require-specific: false # don't require nolint directives to be specific about which linter is being skipped - - depguard: - rules: - main: - deny: - - pkg: "github.com/pkg/errors" - desc: "errors.Wrap() is deprecated in favor of fmt.Errorf()" - - stylecheck: - checks: - - all - - -ST1003 # should not use underscores in Go names; ... - - -ST1005 # error strings should not be capitalized - - -ST1012 # error var ... should have name of the form ErrFoo - - -ST1016 # methods on the same type should have the same receiver name - - -ST1022 # comment on exported var ... should be of the form ... - - revive: - ignore-generated-header: true - severity: error - enable-all-rules: true - rules: - - name: add-constant - disabled: true - - name: cognitive-complexity - disabled: true - - name: comment-spacings - disabled: true - - name: confusing-results - disabled: true - - name: cyclomatic - disabled: true - - name: empty-lines - disabled: true - - name: flag-parameter - disabled: true - - name: function-length - disabled: true - - name: if-return - disabled: true - - name: import-alias-naming - disabled: true - - name: import-shadowing - disabled: true - - name: line-length-limit - disabled: true - - name: nested-structs - disabled: true - - name: var-declaration - disabled: true - - name: exported - disabled: true - - name: unexported-naming - disabled: true - - name: unexported-return - disabled: true - - name: unhandled-error - disabled: true - arguments: - - "fmt.Print" - - "fmt.Printf" - - "fmt.Println" - - name: unused-receiver - disabled: true - - name: function-result-limit - arguments: - - 5 - wsl: - # Allow blocks to end with comments - allow-trailing-comment: true +version: "2" linters: - enable-all: true + default: all disable: - # - # DEPRECATED by golangi-lint - # - - # - # Redundant - # - + - contextcheck - cyclop - - tenv - - lll + - dupl + - err113 + - exhaustruct + - forbidigo - funlen + - gochecknoglobals - gocognit - - # - # Recommended? (easy) - # - - - gosec # (gas): Inspects source code for security problems - - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. - - wrapcheck # Checks that errors returned from external packages are wrapped - - # - # Recommended? (requires some work) - # - - - contextcheck # check the function whether use a non-inherited context - - mnd # An analyzer to detect magic numbers. - - unparam # Reports unused function parameters - - # - # Formatting only, useful in IDE but should not be forced on CI? - # - - - gofumpt # Gofumpt checks whether code was gofumpt-ed. - - nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity - - whitespace # Whitespace is a linter that checks for unnecessary newlines at the start and end of functions, if, for, etc. - - wsl # add or remove empty lines - - # - # Well intended, but not ready for this - # - - dupl # Tool for code clone detection - - err113 # Golang linter to check the errors handling expressions - - paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test - - testpackage # linter that makes you use a separate _test package - - # - # Too strict / too many false positives (for now?) - # - - exhaustruct # Checks if all structure fields are initialized - - forbidigo # Forbids identifiers - - gochecknoglobals # check that no global variables exist - - goconst # Finds repeated strings that could be replaced by a constant - - tagliatelle # Checks the struct tags. - - varnamelen # checks that the length of a variable's name matches its scope - + - goconst + - gosec + - lll + - mnd + - nlreturn + - paralleltest + - tagliatelle + - testpackage + - varnamelen + - whitespace + - wrapcheck + - wsl + settings: + + depguard: + rules: + main: + deny: + - pkg: github.com/pkg/errors + desc: errors.Wrap() is deprecated in favor of fmt.Errorf() + govet: + disable: + - fieldalignment + + enable-all: true + + misspell: + locale: US + + nlreturn: + block-size: 4 + + nolintlint: + require-explanation: false + require-specific: false + allow-unused: false + + revive: + severity: error + enable-all-rules: true + rules: + - name: add-constant + disabled: true + - name: cognitive-complexity + disabled: true + - name: comment-spacings + disabled: true + - name: confusing-results + disabled: true + - name: cyclomatic + disabled: true + - name: empty-lines + disabled: true + - name: flag-parameter + disabled: true + - name: function-length + disabled: true + - name: import-shadowing + disabled: true + - name: line-length-limit + disabled: true + - name: nested-structs + disabled: true + - name: var-declaration + disabled: true + - name: exported + disabled: true + - name: unexported-naming + disabled: true + - name: unexported-return + disabled: true + - name: unhandled-error + arguments: + - fmt.Print + - fmt.Printf + - fmt.Println + disabled: true + - name: function-result-limit + arguments: + - 5 + staticcheck: + checks: + - all + wsl: + allow-trailing-comment: true + exclusions: + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - govet + text: 'shadow: declaration of "err" shadows declaration' + paths: + - third_party$ + - builtin$ + - examples$ issues: - exclude-generated: strict - max-issues-per-linter: 0 max-same-issues: 10 - exclude-rules: - # `err` is often shadowed, we may continue to do it - - linters: - - govet - text: "shadow: declaration of \"err\" shadows declaration" +formatters: + enable: + - gci + - gofmt + - goimports + settings: + gci: + sections: + - standard + - default + - prefix(github.com/crowdsecurity) + - prefix(github.com/crowdsecurity/crowdsec) + - prefix(github.com/crowdsecurity/cs-custom-bouncer) + exclusions: + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/pkg/custom/custom.go b/pkg/custom/custom.go index c8f3032..6ea7c31 100644 --- a/pkg/custom/custom.go +++ b/pkg/custom/custom.go @@ -118,7 +118,7 @@ func (c *CustomBouncer) Delete(decision *models.Decision) error { return nil } -func (c *CustomBouncer) ShutDown() error { +func (*CustomBouncer) ShutDown() error { return nil } diff --git a/pkg/custom/custom_test.go b/pkg/custom/custom_test.go index 802d9ef..96ad840 100644 --- a/pkg/custom/custom_test.go +++ b/pkg/custom/custom_test.go @@ -34,7 +34,7 @@ type parsedLine struct { } func parseFile(path string) []parsedLine { - dat, err := os.ReadFile(binaryOutputFile) + dat, err := os.ReadFile(path) parsedLines := make([]parsedLine, 0) if err != nil { panic(err)