jojo/.golangci.yml
famfo 172bb4cefe chore(lint): enable nilnil (#11235)
The general consensus I have gotten from past contributions is that `return nil, nil` is an
antipattern in Forgejo, especially because:

```go
val, err := Func()
if err != nil {
    return
}
val.Func()
```

can easily lead to a nil pointer dereference.

This PR merely enables the lint and ignores all currently broken files. In addition to this PR,
a tracking issue to keep track of re-enabling nilnil linting on the ignored files could be
useful.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11235
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: famfo <famfo@famfo.xyz>
Co-committed-by: famfo <famfo@famfo.xyz>
2026-02-11 19:08:24 +01:00

427 lines
11 KiB
YAML

---
version: "2"
output:
sort-order:
- file
linters:
default: none
enable:
- bidichk
- depguard
- dupl
- errcheck
- forbidigo
- gocritic
- govet
- importas
- ineffassign
- nakedret
- nolintlint
- revive
- staticcheck
- testifylint
- unconvert
- unparam
- unused
- usetesting
- wastedassign
- nilnil
settings:
depguard:
rules:
main:
deny:
- pkg: encoding/json
desc: use gitea's modules/json instead of encoding/json
- pkg: golang.org/x/exp
desc: it's experimental and unreliable
- pkg: forgejo.org/modules/git/internal
desc: do not use the internal package, use AddXxx function instead
- pkg: gopkg.in/ini.v1
desc: do not use the ini package, use gitea's config system instead
- pkg: github.com/minio/sha256-simd
desc: use crypto/sha256 instead, see https://codeberg.org/forgejo/forgejo/pulls/1528
- pkg: github.com/go-git/go-git
desc: use forgejo.org/modules/git instead, see https://codeberg.org/forgejo/forgejo/pulls/4941
- pkg: gopkg.in/yaml.v3
desc: use go.yaml.in/yaml instead, see https://codeberg.org/forgejo/forgejo/pulls/8956
gocritic:
disabled-checks:
- ifElseChain
importas:
alias:
# Specific overrides that would violate the default rules further below.
- pkg: forgejo.org/models/db
alias: ""
- pkg: forgejo.org/models/organization
alias: org_model
- pkg: forgejo.org/services/context
alias: app_context
- pkg: forgejo.org/services/doctor
alias: doctor
- pkg: forgejo.org/services/repository
alias: repo_service
# Make sure that we follow a consistent naming for model and service aliases.
- pkg: 'forgejo.org/(model|service)s/(\w+)'
alias: '${2}_${1}'
revive:
severity: error
rules:
- name: atomic
- name: bare-return
- name: blank-imports
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: duplicated-imports
- name: empty-lines
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: identical-branches
- name: if-return
- name: increment-decrement
- name: indent-error-flow
- name: modifies-value-receiver
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: string-of-int
- name: superfluous-else
- name: time-naming
- name: unconditional-recursion
- name: unexported-return
- name: unreachable-code
- name: var-declaration
- name: var-naming
arguments:
- []
- []
- - skip-package-name-checks: true
- name: redefines-builtin-id
disabled: true
staticcheck:
checks:
- all
testifylint:
disable:
- error-is-as
- go-require
nilnil:
only-two: false
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- nolintlint
path: models/db/sql_postgres_with_schema.go
- linters:
- dupl
- errcheck
- gocyclo
- gosec
- staticcheck
- unparam
path: _test\.go
- linters:
- dupl
- errcheck
- gocyclo
- gosec
path: models/gitea_migrations/v
- linters:
- forbidigo
path: cmd
- linters:
- dupl
text: (?i)webhook
- linters:
- gocritic
text: (?i)`ID' should not be capitalized
- linters:
- deadcode
- unused
text: (?i)swagger
- linters:
- staticcheck
text: (?i)argument x is overwritten before first use
- linters:
- gocritic
text: '(?i)commentFormatting: put a space between `//` and comment text'
- linters:
- gocritic
text: '(?i)exitAfterDefer:'
- linters:
- staticcheck
text: "(ST1005|ST1003|QF1001):"
# TODO: eventually remove this section entirely
- path: cmd/admin_auth_ldap_test.go
linters:
- nilnil
- path: cmd/admin_auth_oauth_test.go
linters:
- nilnil
- path: cmd/admin_auth_pam_test.go
linters:
- nilnil
- path: cmd/cmd.go
linters:
- nilnil
- path: cmd/forgejo/actions.go
linters:
- nilnil
- path: models/actions/run.go
linters:
- nilnil
- path: models/actions/task.go
linters:
- nilnil
- path: models/activities/action_list.go
linters:
- nilnil
- path: models/asymkey/gpg_key_object_verification.go
linters:
- nilnil
- path: models/auth/oauth2.go
linters:
- nilnil
- path: models/db/collation.go
linters:
- nilnil
- path: models/dbfs/dbfile.go
linters:
- nilnil
- path: models/forgefed/federationhost_repository.go
linters:
- nilnil
- path: models/forgejo_migrations_legacy/v32.go
linters:
- nilnil
- path: models/forgejo_migrations_legacy/v32_test.go
linters:
- nilnil
- path: models/db/context.go
linters:
- nilnil
- path: models/git/branch_list.go
linters:
- nilnil
- path: models/git/lfs_lock.go
linters:
- nilnil
- path: models/git/protected_branch.go
linters:
- nilnil
- path: models/git/protected_tag.go
linters:
- nilnil
- path: models/issues/issue.go
linters:
- nilnil
- path: models/issues/issue_xref.go
linters:
- nilnil
- path: models/issues/review.go
linters:
- nilnil
- path: models/organization/org_user.go
linters:
- nilnil
- path: models/quota/rule.go
linters:
- nilnil
- path: models/repo/archiver.go
linters:
- nilnil
- path: models/repo/fork.go
linters:
- nilnil
- path: models/repo/topic.go
linters:
- nilnil
- path: models/user/email_address.go
linters:
- nilnil
- path: models/user/list.go
linters:
- nilnil
- path: models/user/user.go
linters:
- nilnil
- path: models/repo/repo.go
linters:
- nilnil
- path: models/user/user_repository.go
linters:
- nilnil
- path: modules/git/commit.go
linters:
- nilnil
- path: modules/git/foreachref/parser.go
linters:
- nilnil
- path: modules/git/last_commit_cache.go
linters:
- nilnil
- path: modules/git/log_name_status.go
linters:
- nilnil
- path: modules/graceful/net_unix.go
linters:
- nilnil
- path: modules/indexer/internal/bleve/util.go
linters:
- nilnil
- path: modules/indexer/issues/util.go
linters:
- nilnil
- path: modules/optional/serialization.go
linters:
- nilnil
- path: modules/setting/storage.go
linters:
- nilnil
- path: routers/api/packages/chef/auth.go
linters:
- nilnil
- path: routers/api/packages/container/auth.go
linters:
- nilnil
- path: routers/api/packages/nuget/auth.go
linters:
- nilnil
- path: routers/api/packages/swift/swift.go
linters:
- nilnil
- path: routers/web/auth/oauth.go
linters:
- nilnil
- path: routers/web/repo/compare.go
linters:
- nilnil
- path: routers/web/repo/release.go
linters:
- nilnil
- path: routers/web/repo/setting/runners.go
linters:
- nilnil
- path: routers/web/repo/setting/secrets.go
linters:
- nilnil
- path: routers/web/repo/setting/variables.go
linters:
- nilnil
- path: services/actions/context.go
linters:
- nilnil
- path: services/actions/task.go
linters:
- nilnil
- path: services/actions/trust.go
linters:
- nilnil
- path: services/auth/basic.go
linters:
- nilnil
- path: services/auth/httpsign.go
linters:
- nilnil
- path: services/auth/oauth2.go
linters:
- nilnil
- path: services/auth/reverseproxy.go
linters:
- nilnil
- path: services/auth/session.go
linters:
- nilnil
- path: services/contexttest/context_tests.go
linters:
- nilnil
- path: services/gitdiff/csv.go
linters:
- nilnil
- path: services/issue/assignee.go
linters:
- nilnil
- path: routers/api/packages/conan/auth.go
linters:
- nilnil
- path: services/federation/signature_service.go
linters:
- nilnil
- path: services/issue/commit.go
linters:
- nilnil
- path: services/issue/issue.go
linters:
- nilnil
- path: services/migrations/onedev.go
linters:
- nilnil
- path: services/packages/cargo/index.go
linters:
- nilnil
- path: services/pull/check.go
linters:
- nilnil
- path: services/pull/comment.go
linters:
- nilnil
- path: services/pull/merge.go
linters:
- nilnil
- path: services/pull/review.go
linters:
- nilnil
- path: services/remote/promote.go
linters:
- nilnil
- path: services/repository/archiver/archiver.go
linters:
- nilnil
- path: services/repository/generate_repo_commit.go
linters:
- nilnil
- path: services/repository/repository.go
linters:
- nilnil
paths:
- node_modules
- public
- web_src
- third_party$
- builtin$
- examples$
issues:
max-issues-per-linter: 0
max-same-issues: 0
formatters:
enable:
- gofmt
- gofumpt
settings:
gofumpt:
extra-rules: true
exclusions:
generated: lax
paths:
- node_modules
- public
- web_src
- third_party$
- builtin$
- examples$