Skip to content
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
9 changes: 4 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
security-events: write

steps:

- name: Check out code into the Go module directory
uses: actions/checkout@v4
with:
Expand All @@ -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
283 changes: 125 additions & 158 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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$
2 changes: 1 addition & 1 deletion pkg/custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/custom/custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down