From c90d5b0336bdc62589487d36c7843e2e94ec90c4 Mon Sep 17 00:00:00 2001 From: Clouds Date: Fri, 3 Jul 2026 23:48:03 +0200 Subject: [PATCH] chore(nilnil lint): resolve low-hanging fruit nilnil lint violations (#13230) Some files excluded from the nilnil lint and listed in https://codeberg.org/forgejo/forgejo/issues/11261 contain no violations of the lint anymore. I removed them from the list. They are - `routers/api/packages/container/auth.go` - `routers/api/packages/nuget/auth.go` - `routers/web/repo/setting/runners.go` - `services/issue/commit.go` - `services/migrations/onedev.go` Other files contained lints that are triggered by returning `nil` for maps. This can be mitigated easily by returning `make(map[...]...)`. All except one of those return statements are already covered by tests. I list the ones that have coverage now, the statement that has no coverage was not changed. ### Tests for Go changes - I ran... - [x] `make pr-go` before pushing ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change. - [x] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/13230 Reviewed-by: Mathieu Fenniak --- .golangci.yml | 21 --------------------- models/activities/action_list.go | 2 +- models/organization/org_user.go | 4 ++-- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9f286cd4fe..c29a4208ee 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -200,9 +200,6 @@ linters: text: "(ST1005|ST1003|QF1001):" # TODO: eventually remove this section entirely - - path: models/activities/action_list.go - linters: - - nilnil - path: models/asymkey/gpg_key_object_verification.go linters: - nilnil @@ -242,9 +239,6 @@ linters: - path: models/issues/review.go linters: - nilnil - - path: models/organization/org_user.go - linters: - - nilnil - path: models/quota/rule.go linters: - nilnil @@ -299,12 +293,6 @@ linters: - 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 @@ -317,9 +305,6 @@ linters: - 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 @@ -335,18 +320,12 @@ linters: - path: services/issue/assignee.go linters: - nilnil - - path: routers/api/packages/conan/auth.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 diff --git a/models/activities/action_list.go b/models/activities/action_list.go index 64b92bbda1..f28cdb5521 100644 --- a/models/activities/action_list.go +++ b/models/activities/action_list.go @@ -29,7 +29,7 @@ func (actions ActionList) getUserIDs() []int64 { func (actions ActionList) LoadActUsers(ctx context.Context) (map[int64]*user_model.User, error) { if len(actions) == 0 { - return nil, nil + return make(map[int64]*user_model.User), nil } userIDs := actions.getUserIDs() diff --git a/models/organization/org_user.go b/models/organization/org_user.go index 4c84fccbf3..1389a6b032 100644 --- a/models/organization/org_user.go +++ b/models/organization/org_user.go @@ -123,13 +123,13 @@ func IsAnEligibleTeamMemberByID(ctx context.Context, uid int64) (bool, error) { func loadOrganizationOwners(ctx context.Context, users user_model.UserList, orgID int64) (map[int64]*TeamUser, error) { if len(users) == 0 { - return nil, nil + return make(map[int64]*TeamUser), nil } ownerTeam, err := GetOwnerTeam(ctx, orgID) if err != nil { if IsErrTeamNotExist(err) { log.Error("Organization does not have owner team: %d", orgID) - return nil, nil + return make(map[int64]*TeamUser), nil } return nil, err }