chore(lint): enable nilnil #11235

Merged
mfenniak merged 1 commit from famfo/forgejo:nilnil-lint into forgejo 2026-02-11 19:08:29 +01:00
Member

The general consensus I have gotten from past contributions is that return nil, nil is an
antipattern in Forgejo, especially because:

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.

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.
feat(lint): enable nilnil
All checks were successful
testing / semgrep/ci (pull_request) Successful in 20s
testing / frontend-checks (pull_request) Successful in 1m34s
testing / backend-checks (pull_request) Successful in 3m21s
testing / test-unit (pull_request) Successful in 7m17s
testing / test-remote-cacher (redis) (pull_request) Successful in 2m1s
testing / test-remote-cacher (valkey) (pull_request) Successful in 2m1s
testing / test-remote-cacher (garnet) (pull_request) Successful in 1m57s
testing / test-remote-cacher (redict) (pull_request) Successful in 1m51s
testing / test-mysql (pull_request) Successful in 23m58s
testing / test-pgsql (pull_request) Successful in 31m57s
testing / test-sqlite (pull_request) Successful in 26m31s
testing / security-check (pull_request) Successful in 43s
issue-labels / cascade (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Has been skipped
requirements / merge-conditions (pull_request) Successful in 1s
issue-labels / backporting (pull_request_target) Has been skipped
milestone / set (pull_request_target) Successful in 5s
testing / test-e2e (pull_request) Successful in 23m9s
70bf0cadde
viceice approved these changes 2026-02-11 16:32:34 +01:00
viceice changed title from feat(lint): enable nilnil to chore(lint): enable nilnil 2026-02-11 16:33:06 +01:00
Owner

changed the pr title, as this isn't a feature which is worth a release note 😉

changed the pr title, as this isn't a feature which is worth a release note 😉
Author
Member

Ah, that's how chores in conventional commits are meant to work :D

Ah, that's how chores in conventional commits are meant to work :D
Member

Would it be plausible to exclude the current situations with //nolint:nilnil at the site of the return, rather than excluding the whole file? I worry that a whitelist of files will (a) never be cleaned up, (b) subtle because it's not in the affected file, and (c) allow new return nil, nil to be added to those files.

Would it be plausible to exclude the current situations with `//nolint:nilnil` at the site of the return, rather than excluding the whole file? I worry that a whitelist of files will (a) never be cleaned up, (b) subtle because it's not in the affected file, and (c) allow new `return nil, nil` to be added to those files.
Author
Member

Hm, I have the same worry about //nolint:nilnil, it being less discoverable and never being cleared up because of that, especially in a lot of files that aren't touched as often. I agree with the new return nil, nils being added though.

Maybe having an issue with all the files to clean this up could be actionable enough?

Hm, I have the same worry about `//nolint:nilnil`, it being less discoverable and never being cleared up because of that, especially in a lot of files that aren't touched as often. I agree with the new `return nil, nil`s being added though. Maybe having an issue with all the files to clean this up could be actionable enough?
Member

Creating a follow-up issue would be fine, maybe a "good first issue" for anyone wanting to find a starting point contribution.

Creating a follow-up issue would be fine, maybe a "good first issue" for anyone wanting to find a starting point contribution.
mfenniak merged commit 172bb4cefe into forgejo 2026-02-11 19:08:29 +01:00
mfenniak referenced this pull request from a commit 2026-02-11 19:08:30 +01:00
alberic89 referenced this pull request from a commit 2026-02-23 18:43:15 +01:00
Sign in to join this conversation.
No reviewers
No labels
arch
riscv64
backport/v1.19
backport/v1.20
backport/v1.21/forgejo
backport/v10.0/forgejo
backport/v11.0/forgejo
backport/v12.0/forgejo
backport/v13.0/forgejo
backport/v14.0/forgejo
backport/v7.0/forgejo
backport/v8.0/forgejo
backport/v9.0/forgejo
breaking
bug
bug
confirmed
bug
duplicate
bug
needs-more-info
bug
new-report
bug
reported-upstream
code/actions
code/api
code/auth
code/auth/faidp
code/auth/farp
code/email
code/federation
code/git
code/migrations
code/packages
code/wiki
database
MySQL
database
PostgreSQL
database
SQLite
dependency-upgrade
dependency
certmagic
dependency
chart.js
dependency
Chi
dependency
Chroma
dependency
citation.js
dependency
codespell
dependency
css-loader
dependency
devcontainers
dependency
dropzone
dependency
editorconfig-checker
dependency
elasticsearch
dependency
enmime
dependency
F3
dependency
ForgeFed
dependency
garage
dependency
Git
dependency
git-backporting
dependency
Gitea
dependency
gitignore
dependency
go-ap
dependency
go-enry
dependency
go-gitlab
dependency
Go-org
dependency
go-rpmutils
dependency
go-sql-driver mysql
dependency
go-swagger
dependency
go-version
dependency
go-webauthn
dependency
gocron
dependency
Golang
dependency
goldmark
dependency
goquery
dependency
Goth
dependency
grpc-go
dependency
happy-dom
dependency
Helm
dependency
image-spec
dependency
jsonschema
dependency
KaTeX
dependency
lint
dependency
MariaDB
dependency
Mermaid
dependency
minio-go
dependency
misspell
dependency
Monaco
dependency
PDFobject
dependency
playwright
dependency
postcss
dependency
postcss-plugins
dependency
pprof
dependency
prometheus client_golang
dependency
protobuf
dependency
relative-time-element
dependency
renovate
dependency
reply
dependency
ssh
dependency
swagger-ui
dependency
tailwind
dependency
temporal-polyfill
dependency
terminal-to-html
dependency
tests-only
dependency
text-expander-element
dependency
urfave
dependency
vfsgen
dependency
vite
dependency
Woodpecker CI
dependency
x tools
dependency
XORM
Discussion
duplicate
enhancement/feature
forgejo/accessibility
forgejo/branding
forgejo/ci
forgejo/commit-graph
forgejo/documentation
forgejo/furnace cleanup
forgejo/i18n
forgejo/interop
forgejo/moderation
forgejo/privacy
forgejo/release
forgejo/scaling
forgejo/security
forgejo/ui
Gain
High
Gain
Nice to have
Gain
Undefined
Gain
Very High
good first issue
i18n/backport-stable
impact
large
impact
medium
impact
small
impact
unknown
Incompatible license
issue
closed
issue
do-not-exist-yet
issue
open
manual test
Manually tested during feature freeze
OS
FreeBSD
OS
Linux
OS
macOS
OS
Windows
problem
QA
regression
release blocker
Release Cycle
Feature Freeze
release-blocker
v7.0
release-blocker
v7.0.1
release-blocker
v7.0.2
release-blocker
v7.0.3
release-blocker
v7.0.4
release-blocker
v8.0.0
release-blocker/v9.0.0
run-all-playwright-tests
run-end-to-end-tests
test
manual
test
needed
test
needs-help
test
not-needed
test
present
untested
User research - time-tracker
valuable code
worth a release-note
User research - Accessibility
User research - Blocked
User research - Community
User research - Config (instance)
User research - Errors
User research - Filters
User research - Future backlog
User research - Git workflow
User research - Labels
User research - Moderation
User research - Needs input
User research - Notifications/Dashboard
User research - Rendering
User research - Repo creation
User research - Repo units
User research - Security
User research - Settings (in-app)
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
forgejo/forgejo!11235
No description provided.