Skip to content

Commit

Permalink
Refresh golangci-lint config (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
FollowTheProcess authored Jan 19, 2025
1 parent f30a903 commit 02193c5
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 108 deletions.
192 changes: 102 additions & 90 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
linters:
disable-all: true
enable:
- bodyclose
- containedctx
- durationcheck
- errcheck
- errchkjson
- errname
- exhaustive
- goconst
- gocritic
- gocyclo
- godot
- gofumpt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- mnd
- nilerr
- nilnil
- nolintlint
- nakedret
- predeclared
- reassign
- revive
- staticcheck
- tagliatelle
- tenv
- testpackage
- thelper
- unconvert
- unparam
- unused
- whitespace
enable-all: true
disable:
- decorder # Don't care about this
- dupl # Basically every table driven test ever triggers this
- dupword # Messes with test cases more often than not
- err113 # Out of date
- exhaustruct # No
- exportloopref # Go 1.22+ solves this
- forbidigo # Nothing to forbid
- funlen # Bad metric for complexity
- gci # gofmt/goimports is fine
- ginkgolinter # I don't use whatever this is
- gochecknoglobals # Globals are fine sometimes, use common sense
- gocyclo # cyclop does this instead
- godox # "todo" and "fixme" comments are allowed
- goheader # No need
- gosmopolitan # No need
- grouper # Imports take care of themselves, rest is common sense
- ireturn # This is just not necessary or practical in a real codebase
- lll # Auto formatters do this and what they can't do I don't care about
- maintidx # This is just the inverse of complexity... which is cyclop
- nestif # cyclop does this
- nonamedreturns # Named returns are often helpful, it's naked returns that are the issue
- paralleltest # I've never had Go tests take longer than a few seconds, it's fine
- varnamelen # Lots of false positives of things that are fine
- wrapcheck # Not every error must be wrapped

issues:
exclude-rules:
- path: test_test.go
- path: _test\.go
linters:
- thelper # The entire package is effectively a t.Helper
- goconst # Lots of repetition in here
- prealloc # These kinds of optimisations will make no difference to test code
- thelper # This entire package is a test helper
- goconst # Lots of repeated test input

exclude-files:
- internal/diff/diff.go # Code taken from go/internal/diff

linters-settings:
cyclop:
max-complexity: 20

depguard:
rules:
main:
deny:
- pkg: io/ioutil
desc: io/ioutil is deprecated, use io instead

- pkg: "math/rand$"
desc: use math/rand/v2 instead

errcheck:
check-type-assertions: true
check-blank: true
Expand All @@ -54,80 +61,85 @@ linters-settings:
- map
default-signifies-exhaustive: true

gocyclo:
min-complexity: 20

staticcheck:
checks: ["all"]
checks:
- all

gosimple:
checks: ["all"]
checks:
- all

govet:
enable-all: true

revive:
max-open-files: 256
ignore-generated-header: true
rules:
- name: argument-limit
disabled: false
arguments: [5]

- name: atomic
disabled: false
gofumpt:
extra-rules: true

- name: blank-imports
disabled: false
nakedret:
max-func-lines: 0 # Disallow any naked returns

- name: call-to-gc
disabled: false
nolintlint:
allow-unused: false
require-explanation: true
require-specific: true

- name: constant-logical-expr
disabled: false
usetesting:
context-background: true
context-todo: true
os-chdir: true
os-mkdir-temp: true
os-setenv: true
os-create-temp: true
os-temp-dir: true

- name: context-as-argument
disabled: false

- name: datarace
disabled: false
revive:
max-open-files: 256
ignore-generated-header: true
enable-all-rules: true
rules:
- name: add-constant
disabled: true # goconst does this

- name: deep-exit
disabled: false
- name: argument-limit
arguments:
- 5

- name: defer
disabled: false
- name: cognitive-complexity
disabled: true # gocognit does this

- name: dot-imports
disabled: false
- name: comment-spacings
arguments:
- "nolint:"

- name: early-return
disabled: false
- name: cyclomatic
disabled: true # cyclop does this

- name: exported
arguments:
- checkPrivateReceivers
- checkPublicInterface

- name: modifies-value-receiver
disabled: false

- name: package-comments
disabled: false
- name: flag-parameter
disabled: true # Lots of false positives in this package

- name: range
disabled: false
- name: function-length
disabled: true # Bad proxy for complexity

- name: range-val-in-closure
disabled: false
- name: function-result-limit
arguments:
- 3

- name: range-val-address
disabled: false
- name: import-shadowing
disabled: true # predeclared does this

- name: time-equal
disabled: false
- name: line-length-limit
disabled: true # gofmt/golines handles this well enough

- name: use-any
disabled: false
- name: redefines-builtin-id
disabled: true # predeclared does this

- name: waitgroup-by-value
disabled: false
- name: unhandled-error
arguments:
- fmt\.(Fp|P)rint(ln|f)?
- strings.Builder.Write(String|Byte)?
- bytes.Buffer.Write(String|Byte)?
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[default.extend-words]
decorder = "decorder" # Name of a Go linter
4 changes: 0 additions & 4 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,9 @@ tasks:
- sh: command -v golangci-lint
msg: golangci-lint not installed, see https://golangci-lint.run/usage/install/#local-installation

- sh: command -v betteralign
msg: requires betteralign, run `go install github.com/dkorunic/betteralign/cmd/betteralign@latest`

- sh: command -v typos
msg: requires typos-cli, run `brew install typos-cli`
cmds:
- betteralign -test_files -apply ./...
- golangci-lint run --fix
- typos

Expand Down
13 changes: 11 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ func (f failure[T]) String() string {
type Option interface {
// Apply the option to the test config, returning an error if the option
// cannot be applied for whatever reason.
apply(*config) error
apply(cfg *config) error
}

// option is a function adapter implementing the Option interface, analogous
// to how http.HandlerFunc implements the Handler interface.
type option func(*config) error
type option func(cfg *config) error

// apply applies the option, implementing the Option interface for the option
// function adapter.
Expand All @@ -87,9 +87,12 @@ func FloatEqualityThreshold(threshold float64) Option {
if math.IsInf(threshold, 0) {
return errors.New("cannot set floating point equality threshold to ±infinity")
}

cfg.floatEqualityThreshold = threshold

return nil
}

return option(f)
}

Expand All @@ -109,9 +112,12 @@ func Title(title string) Option {
if title == "" {
return errors.New("cannot set title to an empty string")
}

cfg.title = strings.TrimSpace(title)

return nil
}

return option(f)
}

Expand All @@ -134,9 +140,12 @@ func Context(format string, args ...any) Option {
if format == "" {
return errors.New("cannot set context to an empty string")
}

context := fmt.Sprintf(format, args...)
cfg.context = strings.TrimSpace(context)

return nil
}

return option(f)
}
Loading

0 comments on commit 02193c5

Please sign in to comment.