Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golangci-lint update #348

Merged
merged 1 commit into from
Jan 5, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
version: v1.55
args: --issues-exit-code=1 --timeout 10m
only-new-issues: false
# the cache is already managed above, enabling it here
Expand Down
27 changes: 24 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# see https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml

linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/crowdsecurity)
- prefix(github.com/crowdsecurity/crowdsec)
- prefix(github.com/crowdsecurity/cs-firewall-bouncer)

gocyclo:
min-complexity: 30

Expand All @@ -16,16 +24,28 @@ linters-settings:

govet:
check-shadowing: true

lll:
line-length: 140

misspell:
locale: US

nlreturn:
block-size: 4

nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
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.New() is deprecated in favor of fmt.Errorf()"

linters:
enable-all: true
disable:
Expand All @@ -47,7 +67,6 @@ linters:
# Disabled
#
- gci # Gci control golang package import order and make it always deterministic.
- depguard # Go linter that checks if package imports are in a list of acceptable packages

#
# Enabled
Expand All @@ -60,6 +79,7 @@ linters:
# - containedctx # containedctx is a linter that detects struct contained context.Context field
# - contextcheck # check the function whether use a non-inherited context
# - decorder # check declaration order and count of types, constants, variables and functions
# - depguard # Go linter that checks if package imports are in a list of acceptable packages
# - dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
# - durationcheck # check for two durations multiplied together
# - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
Expand All @@ -71,6 +91,7 @@ linters:
# - exportloopref # checks for pointers to enclosing loop variables
# - forcetypeassert # finds forced type assertions
# - funlen # Tool for detection of long functions
# - ginkgolinter # enforces standards of using ginkgo and gomega
# - gochecknoinits # Checks that no init functions are present in Go code
# - godot # Check if comments end in a period
# - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
Expand Down Expand Up @@ -164,7 +185,7 @@ linters:

issues:
max-issues-per-linter: 0
max-same-issues: 10
max-same-issues: 0
exclude-rules:
# `err` is often shadowed, we may continue to do it
- linters:
Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"

"github.com/crowdsecurity/crowdsec/pkg/models"
csbouncer "github.com/crowdsecurity/go-cs-bouncer"
"github.com/crowdsecurity/go-cs-lib/csdaemon"
"github.com/crowdsecurity/go-cs-lib/version"

"github.com/crowdsecurity/crowdsec/pkg/models"

"github.com/crowdsecurity/cs-firewall-bouncer/pkg/backend"
"github.com/crowdsecurity/cs-firewall-bouncer/pkg/cfg"
"github.com/crowdsecurity/cs-firewall-bouncer/pkg/metrics"
Expand Down
2 changes: 0 additions & 2 deletions pkg/iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ type iptables struct {
}

func NewIPTables(config *cfg.BouncerConfig) (types.Backend, error) {
var err error

ret := &iptables{}

ipv4Ctx := &ipTablesContext{
Expand Down
4 changes: 1 addition & 3 deletions pkg/iptables/iptables_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ type ipTablesContext struct {
}

func (ctx *ipTablesContext) CheckAndCreate() error {
var err error

log.Infof("Checking existing set")
/* check if the set already exist */
cmd := exec.Command(ctx.ipsetBin, "-L", ctx.SetName)
if _, err = cmd.CombinedOutput(); err != nil { // it doesn't exist
if _, err := cmd.CombinedOutput(); err != nil { // it doesn't exist
if ctx.ipsetContentOnly {
/*if we manage ipset content only, error*/
log.Errorf("set %s doesn't exist, can't manage content", ctx.SetName)
Expand Down
3 changes: 2 additions & 1 deletion pkg/pf/pf_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

log "github.com/sirupsen/logrus"

"github.com/crowdsecurity/crowdsec/pkg/models"
"github.com/crowdsecurity/go-cs-lib/slicetools"

"github.com/crowdsecurity/crowdsec/pkg/models"
)

type pfContext struct {
Expand Down