Skip to content

Enable more linters #12438

Open
2 of 3 issues completed
Open

Description

@babakks

We need to add more linters to spot potential security/styling issues in our code base.

A good and up-to-date source of recommended linters is this, thanks to @maratori for their efforts:
https://github.com/maratori/golangci-lint-config/blob/main/.golangci.yml

Adding a large number of linters at once would make it difficult for review, so I suggest picking them one at a time as a continuous enhancement.

For starter, I'm thinking about the following linters. I also think it's best to commit this into .golangci.yml for reference.

linters:
  default: none
  enable:
    # Already enabled
    - bodyclose # checks whether HTTP response body is closed successfully
    - copyloopvar # detects places where loop variables are copied (Go 1.22+)
    - durationcheck # checks for two durations multiplied together
    - gocritic # provides diagnostics that check for bugs, performance and style issues
    - govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
    - ineffassign # detects when assignments to existing variables are not used
    - nilerr # finds the code that returns nil even if it checks that the error is not nil
    - nolintlint # reports ill-formed or insufficient nolint directives

    ## Already compliant (noop):
    - asasalint # checks for pass []any as any in variadic func(...any)
    - asciicheck # checks that your code does not contain non-ASCII identifiers
    - bidichk # checks for dangerous unicode character sequences
    - exptostd # detects functions from golang.org/x/exp/ that can be replaced by std functions
    - fatcontext # detects nested contexts in loops
    - gocheckcompilerdirectives # validates go compiler directive comments (//go:)
    - gochecksumtype # checks exhaustiveness on Go "sum types"
    - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
    - goprintffuncname # checks that printf-like functions are named with f at the end
    - nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
    - reassign # checks that package variables are not reassigned    
    - unused # checks for unused constants, variables, functions and types

    ## Medium/low effort (based on number of issues):
    # - canonicalheader # checks whether net/http.Header uses canonical header
    # - embeddedstructfieldcheck # checks embedded types in structs
    # - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
    # - exhaustive # checks exhaustiveness of enum switch statements
    # - forbidigo # forbids identifiers
    # - gochecknoinits # checks that no init functions are present in Go code
    # - gocyclo # computes and checks the cyclomatic complexity of functions
    # - iface # checks the incorrect use of interfaces, helping developers avoid interface pollution
    # - intrange # finds places where for loops could make use of an integer range
    # - iotamixing # checks if iotas are being used in const blocks with other non-iota declarations
    # - makezero # finds slice declarations with non-zero initial length
    # - mirror # reports wrong mirror patterns of bytes/strings usage
    # - protogetter # reports direct reads from proto message fields when getters should be used
    # - recvcheck # checks for receiver type consistency
    # - testableexamples # checks if examples are testable (have an expected output)
    # - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
    # - unconvert # removes unnecessary type conversions
    # - usetesting # reports uses of functions with replacement inside the testing package
    # - wastedassign # finds wasted assignment statements
    # - whitespace # detects leading and trailing whitespace

    ## High effort, but good to have:
    # - errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
    # - gosec # inspects source code for security problems
    # - nakedret # finds naked returns in functions greater than a specified function length
    # - noctx # finds sending http request without context.Context
    # - nonamedreturns # reports all named returns
    # - staticcheck # is a go vet on steroids, applying a ton of static analysis checks

    ## High effort:
    # - cyclop # checks function and package cyclomatic complexity
    # - depguard # checks if package imports are in a list of acceptable packages
    # - dupl # tool for code clone detection
    # - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
    # - funcorder # checks the order of functions, methods, and constructors
    # - funlen # tool for detection of long functions
    # - gochecknoglobals # checks that no global variables exist
    # - gocognit # computes and checks the cognitive complexity of functions
    # - goconst # finds repeated strings that could be replaced by a constant
    # - godoclint # checks Golang's documentation practice
    # - godot # checks if comments end in a period
    # - mnd # detects magic numbers
    # - modernize # suggests simplifications to Go code, using modern language and library features
    # - musttag # enforces field tags in (un)marshaled structs
    # - nestif # reports deeply nested if statements
    # - perfsprint # checks that fmt.Sprintf can be replaced with a faster alternative
    # - predeclared # finds code that shadows one of Go's predeclared identifiers
    # - revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
    # - testifylint # checks usage of github.com/stretchr/testify
    # - unparam # reports unused function parameters
    # - usestdlibvars # detects the possibility to use variables/constants from the Go standard library

    ## Inapplicable due to context:
    # - loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
    # - nilnesserr # reports that it checks for err != nil, but it returns a different nil value error (powered by nilness and nilerr)
    # - nilnil # checks that there is no simultaneous return of nil error and an invalid value
    # - promlinter # checks Prometheus metrics naming via promlint
    # - rowserrcheck # checks whether 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 and sql.Stmt are closed
    # - testpackage # makes you use a separate _test package
    # - unqueryvet # detects SELECT * in SQL queries and SQL builders, encouraging explicit column selection

I split them over low/medium/high effort classes based on the number of issues they reported (expand for details). So, some of low-efforts can be tough ones.

Details

canonicalheader: 5
cyclop: 284
depguard: 4245
dupl: 163
embeddedstructfieldcheck: 26
errcheck: 1036
errname: 24
errorlint: 84
exhaustive: 18
forbidigo: 7
funcorder: 63
funlen: 757
gochecknoglobals: 213
gochecknoinits: 5
gocognit: 86
goconst: 111
gocyclo: 28
godoclint: 66
godot: 257
gosec: 68
iface: 2
intrange: 26
iotamixing: 2
makezero: 2
mirror: 3
mnd: 397
modernize: 2577
musttag: 63
nakedret: 56
nestif: 123
nilnil: 36
noctx: 84
nonamedreturns: 113
perfsprint: 319
predeclared: 52
protogetter: 34
recvcheck: 6
revive: 3274
staticcheck: 177
testableexamples: 1
testifylint: 1343
testpackage: 297
tparallel: 7
unconvert: 16
unparam: 58
unqueryvet: 26
usestdlibvars: 142
usetesting: 11
wastedassign: 5
whitespace: 61

Sub-issues

Sub-issues

2 of 3 Issues completed
Loading 3 sub-issues

Activity

  1. added
    tech-debt
    core
    on Jan 7, 2026
  2. added
    pitch
    and removed
    pitch
    on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

corestaletech-debt

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions