Skip to content

Add linters and cleanup #1

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

Merged
merged 1 commit into from
Apr 3, 2025
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
217 changes: 196 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,219 @@
---
version: "2"
run:
relative-path-mode: gomod
linters:
disable-all: true
default: none
# disable:
# - testpackage
# - funlen
# - exhaustruct
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- canonicalheader
- copyloopvar
- cyclop
- depguard
- dupl
- durationcheck
- errcheck
- errname
- errname
- errorlint
- exhaustive
- exptostd
- fatcontext
- forbidigo
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gochecksumtype
- gocognit
- goconst
- gocritic
- gocyclo
- gocyclo
- gofumpt
- goimports
- godot
- gomoddirectives
- goprintffuncname
- gosec
- gosimple
- govet
- iface
- ineffassign
- ireturn
- intrange
- lll
- loggercheck
- makezero
- mirror
- mnd
- musttag
- nakedret
- nestif
- nilerr
- nilnesserr
- nilnil
- noctx
- nolintlint
- nonamedreturns
- nosprintfhostport
- perfsprint
- predeclared
- promlinter
- protogetter
- reassign
- recvcheck
- revive
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- stylecheck
- testableexamples
- testifylint
- typecheck
- tparallel
- unconvert
- unparam
- unused
- usestdlibvars
- usetesting

linters-settings:
gofumpt:
extra-rules: true
# https://golangci-lint.run/usage/linters/#nolintlint
nolintlint:
# Enable to require an explanation of nonzero length after each nolint directive.
# Default: false
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed.
# Default: false
require-specific: true
- wastedassign
- whitespace
settings:
cyclop:
max-complexity: 30
package-average: 10
depguard:
rules:
deprecated:
files:
- $all
deny:
- pkg: github.com/golang/protobuf
desc: Use google.golang.org/protobuf instead, see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules
- pkg: github.com/satori/go.uuid
desc: Use github.com/google/uuid instead, satori's package is not maintained
- pkg: github.com/gofrs/uuid$
desc: Use github.com/gofrs/uuid/v5 or later, it was not a go module before v5
- pkg: github.com/aws/aws-sdk-go/aws
desc: Use github.com/aws/aws-sdk-go-v2 instead, see https://aws.github.io/aws-sdk-go-v2/docs/migrating/
non-main files:
files:
- '!**/main.go'
deny:
- pkg: log$
desc: Use log/slog instead, see https://go.dev/blog/slog
non-test files:
files:
- '!$test'
deny:
- pkg: math/rand$
desc: Use math/rand/v2 instead, see https://go.dev/blog/randv2
errcheck:
check-type-assertions: true
exhaustive:
check:
- switch
- map
gocognit:
min-complexity: 20
gochecksumtype:
default-signifies-exhaustive: false
gocritic:
settings:
captLocal:
paramsOnly: false
underef:
skipRecvDeref: false
govet:
disable:
- fieldalignment
enable-all: true
settings:
shadow:
strict: true
inamedparam:
skip-single-param: true
mnd:
ignored-functions:
- args.Error
- flag.Arg
- flag.Duration.*
- flag.Float.*
- flag.Int.*
- flag.Uint.*
- os.Chmod
- os.Mkdir.*
- os.OpenFile
- os.WriteFile
- prometheus.ExponentialBuckets.*
- prometheus.LinearBuckets
nolintlint:
require-explanation: true
require-specific: true
allow-no-explanation:
- funlen
- gocognit
- lll
- gochecknoglobals
perfsprint:
strconcat: false
reassign:
patterns:
- .*
rowserrcheck:
packages:
- github.com/jmoiron/sqlx
sloglint:
no-global: all
context: scope
usetesting:
os-temp-dir: true
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- godot
source: (noinspection|TODO)
- linters:
- gocritic
source: //noinspection
- linters:
- bodyclose
- dupl
- errcheck
- funlen
- goconst
- gosec
- noctx
- wrapcheck
path: _test\.go
paths:
- third_party$
- builtin$
- examples$
issues:
max-same-issues: 50
formatters:
enable:
- gofmt
- gofumpt
- goimports
- golines
- gci
settings:
gofmt:
simplify: true
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
gci:
sections:
- standard
- default
- localmodule
4 changes: 4 additions & 0 deletions .ls-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ls:
.go: snake_case
.md: SCREAMING_SNAKE_CASE
.yml: kebab-case
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
brew "ls-lint"
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ test.coverage:

test.coverage.check: test.coverage
go tool go-test-coverage --config=./.testcoverage.yml


test.coverage.treemap: test.coverage
go tool go-cover-treemap -coverprofile coverage/cover.out > coverage.svg

gen:
go generate ./...

lint.go:
go tool golangci-lint run

modernize:
go tool modernize ./...

vulcheck:
go tool govulncheck ./...
go tool golangci-lint run --fix

run.example:
go tool godotenv -f .env.test go run ./example/main.go

.env.test:
touch .env.test

.PRECIOUS: .env.test
deps.macos:
brew bundle install

.PRECIOUS: .env.test
86 changes: 86 additions & 0 deletions coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading