Support golangci-lint for project-wide linting
- Dominant language
- Go
- Stars
- 43
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
To ensure consistent code quality and maintainability, we should integrate [golangci-lint](https://github.com/golangci/golangci-lint) into the project.
## Tasks:
- Add `.golangci.yml` configuration file with standard linting rules.
- Update `Makefile` or CI workflow to include `golangci-lint run`.
- Document linting instructions in `CONTRIBUTING.md`.
## Example
This is example `.golangci.yml`:
```yaml
linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- asasalint
- asciicheck
- bidichk
- bodyclose
- contextcheck
- decorder
- dogsled
- dupword
- durationcheck
- errchkjson
- errname
- errorlint
- exhaustive
- copyloopvar
- gci
- gocheckcompilerdirectives
- gocognit
- gocritic
- gocyclo
- godot
- gofmt
- gofumpt
- goheader
- goimports
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosmopolitan
- grouper
- importas
- lll
- loggercheck
- maintidx
- makezero
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- nolintlint
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- reassign
- revive
- rowserrcheck
- sqlclosecheck
- stylecheck
- tagalign
- tagliatelle
- testableexamples
- thelper
- tparallel
- unconvert
- unparam
- usestdlibvars
- wastedassign
- whitespace
# - wrapcheck
- zerologlint
- varnamelen
linters-settings:
gosimple:
checks: ["all"]
revive:
enable-all-rules: true
rules:
- name: "exported"
# TODO: Enable me
# all exported function should have comment.
disabled: true
# TODO: Enable me
- name: package-comments
disabled: true
- name: "add-constant"
disabled: true
- name: "line-length-limit"
disabled: true
- name: "cognitive-complexity"
disabled: true
- name: "function-length"
disabled: true
- name: "cyclomatic"
disabled: true
- name: "unchecked-type-assertion"
disabled: true
- name: max-public-structs
disabled: true
- name: "flag-parameter"
disabled: true
- name: "deep-exit"
disabled: true
- name: "get-return"
disabled: true
- name: "confusing-naming"
disabled: true
- name: "function-result-limit"
disabled: true
- name: "import-shadowing"
disabled: true
- name: redefines-builtin-id
disabled: true
- name: unhandled-error
arguments:
- "fmt.Printf"
- "fmt.Println"
- "fmt.Fprintf"
- "strings.Builder.WriteString"
- "strings.Builder.WriteRune"
- "strings.Builder.WriteByte"
- "bytes.Buffer.Write"
- "bytes.Buffer.WriteString"
gosec:
excludes:
- G304
- G204
- G115
stylecheck:
# TODO: enable ST1000 (at least one file in a package should have a package comment)
checks: ["all", "-ST1000"]
govet:
enable-all: true
disable: ["fieldalignment"]
settings:
shadow:
strict: true
predeclared:
# Comma-separated list of predeclared identifiers to not report on.
# Default: ""
ignore: "len, min, max"
# Include method names and field names (i.e., qualified names) in checks.
# Default: false
q: true
tagliatelle:
# Check the struct tag name case.
case:
use-field-name: false
rules:
json: snake
yaml: snake
nestif:
# Minimal complexity of if statements to report.
# Default: 5
min-complexity: 6
varnamelen:
ignore-names:
- ok
- ip
- no
- tt # table tests
- i # for simple loops
- j # for simple loops
- l
- h
- il
- r # reader
- w # writer
ignore-decls:
- wg sync.WaitGroup
- ts *testsuite.TestSuite
- td *testData
- ma multiaddr.Multiaddr
- db *leveldb.DB
issues:
exclude-use-default: false
exclude-rules:
- path: _test.go
linters:
- maintidx
- nestif
- gocognit
exclude:
- "shadow: declaration of \"err\" shadows"
- "builtinShadow: shadowing of predeclared identifier: min"
- "builtinShadow: shadowing of predeclared identifier: max"
- "builtinShadow: shadowing of predeclared identifier: len"
```
Contributor guide
Research direction
Start with the proposed .golangci.yml and inspect the repository's Makefile or CI workflow to choose where golangci-lint run belongs. Then update CONTRIBUTING.md with the linting instructions and verify that the configured command runs successfully across the project.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- ci-cd, documentation, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100