Files
mux/.golangci.yml

298 lines
11 KiB
YAML
Raw Normal View History

# golangci-lint configuration for Mux project
# See https://golangci-lint.run/usage/configuration/
run:
# Timeout for analysis
timeout: 5m
# Include test files
tests: true
# Modules download mode
modules-download-mode: readonly
# Allow multiple parallel golangci-lint instances
allow-parallel-runners: true
# Output configuration
output:
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|html|junit-xml
formats:
- format: colored-line-number
# Print lines of code with issue
print-issued-lines: true
# Print linter name in the end of issue text
print-linter-name: true
# Make issues output unique by line
uniq-by-line: true
# Sort results by: filepath, line and column
sort-results: true
# Linters configuration
linters:
enable:
# Enabled by default
- errcheck # Check for unchecked errors
- gosimple # Simplify code
- govet # Reports suspicious constructs
- ineffassign # Detects ineffectual assignments
- staticcheck # Advanced Go linter
- typecheck # Type-checks Go code
- unused # Checks for unused constants, variables, functions and types
# Additional recommended linters
- asasalint # Check for pass []any as any in variadic func(...any)
- asciicheck # Check for non-ASCII identifiers
- bidichk # Check for dangerous unicode character sequences
- bodyclose # Check whether HTTP response body is closed successfully
- containedctx # Detects struct fields with context.Context
- contextcheck # Check whether the function uses a non-inherited context
- decorder # Check declaration order and count of types, constants, variables and functions
- dogsled # Check for too many blank identifiers (e.g. x, _, _, _, := f())
- dupl # Code clone detection
- durationcheck # Check for two durations multiplied together
- errname # Check that sentinel errors are prefixed with Err and error types are suffixed with Error
- errorlint # Find code that will cause problems with the error wrapping scheme introduced in Go 1.13
- exhaustive # Check exhaustiveness of enum switch statements
- exportloopref # Check for pointers to enclosing loop variables
- forcetypeassert # Find forced type assertions
- gocheckcompilerdirectives # Check that go compiler directive comments (//go:) are valid
- gochecknoinits # Check that no init functions are present
- goconst # Find repeated strings that could be replaced by a constant
- gocritic # Provides diagnostics that check for bugs, performance and style issues
- gocyclo # Computes and checks the cyclomatic complexity of functions
- godot # Check if comments end in a period
- gofmt # Check whether code was gofmt-ed
- gofumpt # Check whether code was gofumpt-ed
- goimports # Check import statements are formatted according to the 'goimport' command
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod
- gomodguard # Allow and block list linter for direct Go module dependencies
- goprintffuncname # Check that printf-like functions are named with f at the end
- gosec # Inspect source code for security problems
- grouper # Analyze expression groups
- importas # Enforce consistent import aliases
- interfacebloat # Check the number of methods inside an interface
- loggercheck # Check key-value pairs for common logger libraries
- makezero # Find slice declarations with non-zero initial length
- misspell # Find commonly misspelled English words in comments
- nakedret # Find naked returns in functions greater than a specified function length
- nilerr # Find the code that returns nil even if it checks that the error is not nil
- nilnil # Check that there is no simultaneous return of nil error and an invalid value
- noctx # Find sending http request without context.Context
- nolintlint # Reports ill-formed or insufficient nolint directives
- nosprintfhostport # Check for misuse of Sprintf to construct a host with port in a URL
- prealloc # Find slice declarations that could potentially be pre-allocated
- predeclared # Find code that shadows one of Go's predeclared identifiers
- promlinter # Check Prometheus metrics naming via promlint
- reassign # Check that package variables are not reassigned
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go
- stylecheck # Replacement for golint
- tenv # Detect using os.Setenv instead of t.Setenv
- testpackage # Makes you use a separate _test package
- thelper # Detect golang test helpers without t.Helper() call
- tparallel # Detect inappropriate usage of t.Parallel() method in Go tests
- unconvert # Remove unnecessary type conversions
- unparam # Reports unused function parameters
- usestdlibvars # Detect the possibility to use variables/constants from the Go standard library
- wastedassign # Find wasted assignment statements
- whitespace # Tool for detection of leading and trailing whitespace
disable:
- cyclop # Too strict cyclomatic complexity
- depguard # Not needed for this project
- exhaustruct # Too strict for struct initialization
- forbidigo # Not needed
- funlen # Function length checks are too strict
- gci # Import ordering conflicts with goimports
- gochecknoglobals # Globals are acceptable in some cases
- gocognit # Cognitive complexity is too strict
- godox # Allow TODO/FIXME comments
- goerr113 # Too strict error handling requirements
- gomnd # Magic number detection is too noisy
- goheader # No standard header required
- ireturn # Interface return is acceptable
- lll # Line length is not critical
- maintidx # Maintainability index not needed
- nestif # Nesting depth checks too strict
- nlreturn # Newline before return not required
- nonamedreturns # Named returns are acceptable
- paralleltest # Not all tests need to be parallel
- tagliatelle # Tag naming conventions not strict
- testableexamples # Example tests style not enforced
- varnamelen # Variable name length checks too strict
- wrapcheck # Error wrapping not always needed
- wsl # Whitespace linting too opinionated
linters-settings:
errcheck:
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`
check-type-assertions: true
# Report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`
check-blank: false
# List of functions to exclude from checking
exclude-functions:
- (io.Closer).Close
- (io.Writer).Write
govet:
# Enable all analyzers
enable-all: true
# Disable specific analyzers
disable:
- shadow # Variable shadowing is sometimes acceptable
gocyclo:
# Minimal code complexity to report
min-complexity: 15
goconst:
# Minimal length of string constant
min-len: 3
# Minimum occurrences of constant string count to trigger issue
min-occurrences: 3
# Ignore test files
ignore-tests: true
gocritic:
# Enable multiple checks by tags
enabled-tags:
- diagnostic
- style
- performance
- experimental
- opinionated
disabled-checks:
- whyNoLint # Allow lint directives without explanation
- unnamedResult # Named results are acceptable
gofmt:
# Simplify code: gofmt with `-s` option
simplify: true
goimports:
# Put imports beginning with prefix after 3rd-party packages
local-prefixes: code.patial.tech/go/mux
gosec:
# To specify a set of rules to explicitly exclude
excludes:
- G104 # Audit errors not checked (covered by errcheck)
- G307 # Deferring unsafe method Close (too noisy)
misspell:
# Correct spellings using locale preferences
locale: US
ignore-words:
- mux
nakedret:
# Make an issue if func has more lines of code than this setting and it has naked returns
max-func-lines: 30
prealloc:
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them
simple: true
range-loops: true
for-loops: true
revive:
# Enable all available rules
enable-all-rules: false
rules:
# Disabled rules
- name: add-constant
disabled: true
- name: argument-limit
disabled: true
- name: banned-characters
disabled: true
- name: cognitive-complexity
disabled: true
- name: cyclomatic
disabled: true
- name: file-header
disabled: true
- name: function-length
disabled: true
- name: function-result-limit
disabled: true
- name: line-length-limit
disabled: true
- name: max-public-structs
disabled: true
- name: unhandled-error
disabled: true
stylecheck:
# Select the Go version to target
checks:
["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022"]
# ST1000: Incorrect or missing package comment
# ST1003: Poorly chosen identifier
# ST1016: Methods on the same type should have the same receiver name
# ST1020: Comment should be of the form "Type ..."
# ST1021: Comment should be of the form "Func ..."
# ST1022: Comment should be of the form "var Name ..."
dot-import-whitelist:
- fmt
unparam:
# Inspect exported functions
check-exported: false
issues:
# Maximum issues count per one linter
max-issues-per-linter: 50
# Maximum count of issues with the same text
max-same-issues: 3
# Show only new issues created after git revision
new: false
# Fix found issues (if it's supported by the linter)
fix: false
# List of regexps of issue texts to exclude
exclude:
- 'declaration of "(err|ctx)" shadows declaration at'
- 'shadow: declaration of "err" shadows declaration'
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# Exclude some linters from running on tests files
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- goconst
- bodyclose
# Exclude known linters from partially hard-vendored code
- path: internal/hmac/
text: "weak cryptographic primitive"
linters:
- gosec
# Exclude some staticcheck messages
- linters:
- staticcheck
text: "SA9003:"
# Exclude lll issues for long lines with go:generate
- linters:
- lll
source: "^//go:generate "
# Independently of option `exclude` we use default exclude patterns
exclude-use-default: true
# If set to true exclude and exclude-rules regular expressions become case sensitive
exclude-case-sensitive: false