2022-10-26 13:11:37 +00:00
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
2022-05-25 20:27:50 +00:00
linters-settings :
2024-01-17 20:57:45 +00:00
cyclop :
# lower this after refactoring
2024-02-13 13:22:19 +00:00
max-complexity : 53
2024-01-17 20:57:45 +00:00
2024-01-04 16:10:36 +00:00
gci :
sections :
- standard
- default
- prefix(github.com/crowdsecurity)
- prefix(github.com/crowdsecurity/crowdsec)
2024-03-26 08:30:32 +00:00
gomoddirectives :
replace-allow-list :
- golang.org/x/time/rate
2024-01-17 20:57:45 +00:00
gocognit :
# lower this after refactoring
2024-02-07 10:10:25 +00:00
min-complexity : 145
2024-01-17 20:57:45 +00:00
2022-05-25 20:27:50 +00:00
gocyclo :
2024-01-17 20:57:45 +00:00
# lower this after refactoring
2024-02-13 13:22:19 +00:00
min-complexity : 49
2022-05-25 20:27:50 +00:00
funlen :
# Checks the number of lines in a function.
# If lower than 0, disable the check.
# Default: 60
2024-03-19 09:48:49 +00:00
# lower this after refactoring
lines : 437
2022-05-25 20:27:50 +00:00
# Checks the number of statements in a function.
# If lower than 0, disable the check.
# Default: 40
2024-03-19 09:48:49 +00:00
# lower this after refactoring
statements : 122
2022-05-25 20:27:50 +00:00
govet :
2024-04-22 21:54:51 +00:00
enable-all : true
disable :
- reflectvaluecompare
- fieldalignment
2022-10-26 13:11:37 +00:00
2022-05-25 20:27:50 +00:00
lll :
2024-03-19 09:48:49 +00:00
# lower this after refactoring
line-length : 2607
2022-10-26 13:11:37 +00:00
2024-01-17 20:57:45 +00:00
maintidx :
# raise this after refactoring
2024-02-13 13:22:19 +00:00
under : 11
2024-01-17 20:57:45 +00:00
2022-05-25 20:27:50 +00:00
misspell :
locale : US
2022-10-26 13:11:37 +00:00
2024-01-17 20:57:45 +00:00
nestif :
# lower this after refactoring
2024-02-06 09:50:28 +00:00
min-complexity : 28
2024-01-17 20:57:45 +00:00
2023-12-21 11:30:20 +00:00
nlreturn :
2024-04-23 09:15:27 +00:00
block-size : 5
2023-12-21 11:30:20 +00:00
2022-05-25 20:27:50 +00:00
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
2022-10-26 13:11:37 +00:00
interfacebloat :
max : 12
2023-12-21 11:30:20 +00:00
depguard :
rules :
2024-03-19 09:48:49 +00:00
wrap :
2023-12-21 11:30:20 +00:00
deny :
- pkg : "github.com/pkg/errors"
2024-01-17 14:08:41 +00:00
desc : "errors.Wrap() is deprecated in favor of fmt.Errorf()"
2024-03-19 09:48:49 +00:00
files :
- "!**/pkg/database/*.go"
- "!**/pkg/exprhelpers/*.go"
- "!**/pkg/acquisition/modules/appsec/appsec.go"
- "!**/pkg/acquisition/modules/loki/internal/lokiclient/loki_client.go"
- "!**/pkg/apiserver/controllers/v1/errors.go"
2024-03-04 13:22:53 +00:00
yaml :
files :
- "!**/cmd/crowdsec-cli/alerts.go"
- "!**/cmd/crowdsec-cli/capi.go"
- "!**/cmd/crowdsec-cli/config_show.go"
- "!**/cmd/crowdsec-cli/hubtest.go"
- "!**/cmd/crowdsec-cli/lapi.go"
- "!**/cmd/crowdsec-cli/simulation.go"
- "!**/cmd/crowdsec/crowdsec.go"
- "!**/cmd/notification-dummy/main.go"
- "!**/cmd/notification-email/main.go"
- "!**/cmd/notification-http/main.go"
- "!**/cmd/notification-slack/main.go"
- "!**/cmd/notification-splunk/main.go"
- "!**/pkg/acquisition/acquisition.go"
- "!**/pkg/acquisition/acquisition_test.go"
- "!**/pkg/acquisition/modules/appsec/appsec.go"
- "!**/pkg/acquisition/modules/cloudwatch/cloudwatch.go"
- "!**/pkg/acquisition/modules/docker/docker.go"
- "!**/pkg/acquisition/modules/file/file.go"
- "!**/pkg/acquisition/modules/journalctl/journalctl.go"
- "!**/pkg/acquisition/modules/kafka/kafka.go"
- "!**/pkg/acquisition/modules/kinesis/kinesis.go"
- "!**/pkg/acquisition/modules/kubernetesaudit/k8s_audit.go"
- "!**/pkg/acquisition/modules/loki/loki.go"
- "!**/pkg/acquisition/modules/loki/timestamp_test.go"
- "!**/pkg/acquisition/modules/s3/s3.go"
- "!**/pkg/acquisition/modules/syslog/syslog.go"
- "!**/pkg/acquisition/modules/wineventlog/wineventlog_windows.go"
- "!**/pkg/appsec/appsec.go"
- "!**/pkg/appsec/loader.go"
- "!**/pkg/csplugin/broker.go"
- "!**/pkg/csplugin/broker_test.go"
- "!**/pkg/dumps/bucket_dump.go"
- "!**/pkg/dumps/parser_dump.go"
- "!**/pkg/hubtest/coverage.go"
- "!**/pkg/hubtest/hubtest_item.go"
- "!**/pkg/hubtest/parser_assert.go"
- "!**/pkg/hubtest/scenario_assert.go"
- "!**/pkg/leakybucket/buckets_test.go"
- "!**/pkg/leakybucket/manager_load.go"
- "!**/pkg/metabase/metabase.go"
- "!**/pkg/parser/node.go"
- "!**/pkg/parser/node_test.go"
- "!**/pkg/parser/parsing_test.go"
- "!**/pkg/parser/stage.go"
deny :
- pkg : "gopkg.in/yaml.v2"
desc : "yaml.v2 is deprecated for new code in favor of yaml.v3"
2023-12-21 11:30:20 +00:00
2024-02-15 13:34:12 +00:00
wsl :
# Allow blocks to end with comments
allow-trailing-comment : true
2022-05-25 20:27:50 +00:00
linters :
enable-all : true
disable :
#
# DEPRECATED by golangi-lint
#
2024-04-22 15:18:11 +00:00
- deadcode
- exhaustivestruct
- golint
- ifshort
- interfacer
- maligned
- nosnakecase
- scopelint
- structcheck
- varcheck
2022-05-25 20:27:50 +00:00
#
# Enabled
#
2022-09-06 11:55:03 +00:00
2022-08-16 07:46:10 +00:00
# - asasalint # check for pass []any as any in variadic func(...any)
2024-04-22 15:18:11 +00:00
# - asciicheck # checks that all code identifiers does not have non-ASCII symbols in the name
2022-05-25 20:27:50 +00:00
# - bidichk # Checks for dangerous unicode character sequences
2023-12-21 11:30:20 +00:00
# - bodyclose # checks whether HTTP response body is closed successfully
2024-04-22 15:18:11 +00:00
# - copyloopvar # copyloopvar is a linter detects places where loop variables are copied
2024-01-17 20:57:45 +00:00
# - cyclop # checks function and package cyclomatic complexity
2022-05-25 20:27:50 +00:00
# - decorder # check declaration order and count of types, constants, variables and functions
2023-12-21 11:30:20 +00:00
# - depguard # Go linter that checks if package imports are in a list of acceptable packages
2022-10-26 13:11:37 +00:00
# - dupword # checks for duplicate words in the source code
2022-05-25 20:27:50 +00:00
# - durationcheck # check for two durations multiplied together
2024-04-22 15:18:11 +00:00
# - errcheck # errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases
2023-12-21 11:30:20 +00:00
# - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
2024-02-15 13:34:12 +00:00
# - execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds
2022-05-25 20:27:50 +00:00
# - exportloopref # checks for pointers to enclosing loop variables
# - funlen # Tool for detection of long functions
2023-02-15 13:27:17 +00:00
# - ginkgolinter # enforces standards of using ginkgo and gomega
2024-04-22 15:18:11 +00:00
# - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid.
2022-05-25 20:27:50 +00:00
# - gochecknoinits # Checks that no init functions are present in Go code
2024-04-22 15:18:11 +00:00
# - gochecksumtype # Run exhaustiveness checks on Go "sum types"
2024-01-17 20:57:45 +00:00
# - gocognit # Computes and checks the cognitive complexity of functions
2022-11-07 09:36:50 +00:00
# - gocritic # Provides diagnostics that check for bugs, performance and style issues.
2024-01-17 20:57:45 +00:00
# - gocyclo # Computes and checks the cyclomatic complexity of functions
2022-05-25 20:27:50 +00:00
# - goheader # Checks is file header matches to pattern
# - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
# - gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
# - goprintffuncname # Checks that printf-like functions are named with `f` at the end
2024-04-22 15:18:11 +00:00
# - gosimple # (megacheck): Linter for Go source code that specializes in simplifying code
# - gosmopolitan # Report certain i18n/l10n anti-patterns in your Go codebase
# - govet # (vet, vetshadow): Vet examines Go source code and reports suspicious constructs. It is roughly the same as 'go vet' and uses its passes.
# - grouper # Analyze expression groups.
2022-05-25 20:27:50 +00:00
# - importas # Enforces consistent import aliases
2022-09-06 11:55:03 +00:00
# - ineffassign # Detects when assignments to existing variables are not used
# - interfacebloat # A linter that checks the number of methods inside an interface.
2024-04-22 15:18:11 +00:00
# - intrange # intrange is a linter to find places where for loops could make use of an integer range.
2024-03-19 09:48:49 +00:00
# - lll # Reports long lines
2024-04-22 15:18:11 +00:00
# - loggercheck # (logrlint): Checks key value pairs for common logger libraries (kitlog,klog,logr,zap).
2022-09-06 11:55:03 +00:00
# - logrlint # Check logr arguments.
2024-01-17 20:57:45 +00:00
# - maintidx # maintidx measures the maintainability index of each function.
2022-05-25 20:27:50 +00:00
# - makezero # Finds slice declarations with non-zero initial length
2024-04-22 15:18:11 +00:00
# - mirror # reports wrong mirror patterns of bytes/strings usage
# - misspell # Finds commonly misspelled English words
# - nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero).
2024-01-17 20:57:45 +00:00
# - nestif # Reports deeply nested if statements
2022-11-07 09:36:50 +00:00
# - nilerr # Finds the code that returns nil even if it checks that the error is not nil.
2022-05-25 20:27:50 +00:00
# - nolintlint # Reports ill-formed or insufficient nolint directives
2023-12-21 11:30:20 +00:00
# - nonamedreturns # Reports all named returns
# - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL.
2024-04-22 15:18:11 +00:00
# - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative.
2022-06-16 12:41:54 +00:00
# - predeclared # find code that shadows one of Go's predeclared identifiers
2022-09-06 11:55:03 +00:00
# - reassign # Checks that package variables are not reassigned
2024-04-22 15:18:11 +00:00
# - rowserrcheck # checks whether Rows.Err of rows is checked successfully
# - sloglint # ensure consistent code style when using log/slog
# - spancheck # Checks for mistakes with OpenTelemetry/Census spans.
# - sqlclosecheck # Checks that sql.Rows, sql.Stmt, sqlx.NamedStmt, pgx.Query are closed.
# - staticcheck # (megacheck): It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary. The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint.
2022-05-25 20:27:50 +00:00
# - tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
2024-04-22 15:18:11 +00:00
# - testableexamples # linter checks if examples are testable (have an expected output)
# - testifylint # Checks usage of github.com/stretchr/testify.
2022-05-25 20:27:50 +00:00
# - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
2022-06-16 12:41:54 +00:00
# - unconvert # Remove unnecessary type conversions
2022-09-06 11:55:03 +00:00
# - unused # (megacheck): Checks Go code for unused constants, variables, functions and types
2022-08-16 07:46:10 +00:00
# - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library.
2024-04-22 15:18:11 +00:00
# - wastedassign # Finds wasted assignment statements
# - zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg`
2022-05-25 20:27:50 +00:00
#
# Recommended? (easy)
#
2022-09-06 11:55:03 +00:00
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
2024-04-22 15:18:11 +00:00
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and reports occations, where the check for the returned error can be omitted.
2022-09-06 11:55:03 +00:00
- exhaustive # check exhaustiveness of enum switch statements
2022-05-25 20:27:50 +00:00
- gci # Gci control golang package import order and make it always deterministic.
2022-09-06 11:55:03 +00:00
- godot # Check if comments end in a period
2022-05-25 20:27:50 +00:00
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
2024-04-22 15:18:11 +00:00
- goimports # Check import statements are formatted according to the 'goimport' command. Reformat imports in autofix mode.
2022-05-25 20:27:50 +00:00
- gosec # (gas) : Inspects source code for security problems
2023-12-21 11:30:20 +00:00
- inamedparam # reports interfaces with unnamed method parameters
2023-02-15 13:27:17 +00:00
- musttag # enforce field tags in (un)marshaled structs
2022-05-25 20:27:50 +00:00
- promlinter # Check Prometheus metrics naming via promlint
2023-12-21 11:30:20 +00:00
- protogetter # Reports direct reads from proto message fields when getters should be used
2022-05-25 20:27:50 +00:00
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
2023-12-21 11:30:20 +00:00
- tagalign # check that struct tags are well aligned
2024-04-22 15:18:11 +00:00
- thelper # thelper detects tests helpers which is not start with t.Helper() method.
2022-05-25 20:27:50 +00:00
- wrapcheck # Checks that errors returned from external packages are wrapped
#
# Recommended? (requires some work)
#
- containedctx # containedctx is a linter that detects struct contained context.Context field
2024-04-22 15:18:11 +00:00
- contextcheck # check whether the function uses a non-inherited context
2022-05-25 20:27:50 +00:00
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
- gomnd # An analyzer to detect magic numbers.
- ireturn # Accept Interfaces, Return Concrete Types
2022-09-06 11:55:03 +00:00
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value.
2024-04-22 15:18:11 +00:00
- noctx # Finds sending http request without context.Context
2022-09-06 11:55:03 +00:00
- unparam # Reports unused function parameters
2022-05-25 20:27:50 +00:00
#
# 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
2024-04-22 15:18:11 +00:00
- 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
2022-05-25 20:27:50 +00:00
#
# Well intended, but not ready for this
#
2022-09-06 11:55:03 +00:00
- dupl # Tool for code clone detection
2022-10-14 14:12:21 +00:00
- forcetypeassert # finds forced type assertions
2022-05-25 20:27:50 +00:00
- godox # Tool for detection of FIXME, TODO and other comment keywords
2024-04-22 15:18:11 +00:00
- goerr113 # Go linter to check the errors handling expressions
- paralleltest # Detects missing usage of t.Parallel() method in your Go test
2022-05-25 20:27:50 +00:00
- testpackage # linter that makes you use a separate _test package
#
2022-06-06 13:24:48 +00:00
# Too strict / too many false positives (for now?)
2022-05-25 20:27:50 +00:00
#
2022-09-06 11:55:03 +00:00
- exhaustruct # Checks if all structure fields are initialized
2022-05-25 20:27:50 +00:00
- forbidigo # Forbids identifiers
2024-04-22 15:18:11 +00:00
- gochecknoglobals # Check that no global variables exist.
2022-05-25 20:27:50 +00:00
- goconst # Finds repeated strings that could be replaced by a constant
- stylecheck # Stylecheck is a replacement for golint
2022-09-06 11:55:03 +00:00
- tagliatelle # Checks the struct tags.
- varnamelen # checks that the length of a variable's name matches its scope
2022-05-25 20:27:50 +00:00
#
# Under evaluation
#
- prealloc # Finds slice declarations that could potentially be preallocated
2022-10-26 13:11:37 +00:00
2022-05-25 20:27:50 +00:00
issues :
2023-02-15 13:27:17 +00:00
# “Look, that’ s why there’ s rules, understand? So that you think before you
# break ‘ em.” ― Terry Pratchett
2024-03-26 08:30:32 +00:00
exclude-dirs :
- pkg/time/rate
exclude-files :
- pkg/yamlpatch/merge.go
- pkg/yamlpatch/merge_test.go
exclude-generated-strict : true
2022-06-16 12:41:54 +00:00
max-issues-per-linter : 0
2023-12-21 11:30:20 +00:00
max-same-issues : 0
2022-05-25 20:27:50 +00:00
exclude-rules :
2023-12-21 11:30:20 +00:00
# Won't fix:
2022-05-25 20:27:50 +00:00
# `err` is often shadowed, we may continue to do it
- linters :
- govet
text : "shadow: declaration of \"err\" shadows declaration"
- linters :
- errcheck
text : "Error return value of `.*` is not checked"
2022-11-07 09:36:50 +00:00
- linters :
- gocritic
text : "ifElseChain: rewrite if-else to switch statement"
- linters :
- gocritic
text : "captLocal: `.*' should not be capitalized"
- linters :
- gocritic
text : "appendAssign: append result not assigned to the same slice"
- linters :
- gocritic
text : "commentFormatting: put a space between `//` and comment text"
2023-02-15 13:27:17 +00:00
2023-12-21 11:30:20 +00:00
# Will fix, trivial - just beware of merge conflicts
- linters :
- perfsprint
text : "fmt.Sprintf can be replaced .*"
2024-02-13 13:22:19 +00:00
- linters :
- perfsprint
text : "fmt.Errorf can be replaced with errors.New"
2023-12-21 11:30:20 +00:00
#
# Will fix, easy but some neurons required
#
- linters :
- errorlint
text : "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors"
- linters :
- errorlint
text : "type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors"
- linters :
- errorlint
text : "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors"
- linters :
- errorlint
text : "type assertion on error will fail on wrapped errors. Use errors.Is to check for specific errors"
- linters :
- errorlint
text : "comparing with .* will fail on wrapped errors. Use errors.Is to check for a specific error"
- linters :
- errorlint
text : "switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors"
- linters :
- nosprintfhostport
text : "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf"
# https://github.com/timakin/bodyclose
- linters :
- bodyclose
text : "response body must be closed"
2024-01-17 14:08:41 +00:00
# named/naked returns are evil, with a single exception
# https://go.dev/wiki/CodeReviewComments#named-result-parameters
2023-12-21 11:30:20 +00:00
- linters :
- nonamedreturns
text : "named return .* with type .* found"
2024-04-03 15:10:37 +00:00
- linters :
- staticcheck
text : "csdaemon.NotifySystemd is deprecated: Use Notify instead."