CBG-5969: fix staticcheck slice/range nil check warnings - #8518
CBG-5969: fix staticcheck slice/range nil check warnings#8518torcolvin wants to merge 4 commits into
Conversation
|
Droid finished @torcolvin's task —— View job |
There was a problem hiding this comment.
Pull request overview
This PR removes redundant nil checks around len() and range that are flagged by staticcheck (S1009/S1031), and updates the strict golangci-lint configuration to stop suppressing those checks—aiming to eliminate unskippable gopls/staticcheck warnings in the Sync Gateway Go codebase.
Changes:
- Remove redundant
nilchecks beforelen(slice)calls across REST/DB code paths (S1009). - Remove redundant
nilchecks guardingrangeloops where applicable (S1031). - Update
.golangci-strict.ymlto no longer disable S1009 and S1031.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| rest/doc_api.go | Simplifies empty-body detection by relying on len(nil)==0. |
| db/users.go | Refactors collection access update detection logic (introduces a nil-deref risk as written). |
| db/sg_replicate_cfg.go | Removes redundant nil guards around len() and range. |
| db/revision.go | Simplifies ancestor revision length check via len(nil)==0. |
| db/document.go | Simplifies raw body length check via len(nil)==0. |
| db/changes.go | Simplifies “no late logs” check via len(nil)==0. |
| .golangci-strict.yml | Enables staticcheck S1009 and S1031 by removing their exclusions. |
| for collectionName, updatedCollectionAccess := range scope { | ||
| _, err := dbc.GetDatabaseCollection(scopeName, collectionName) | ||
| if err != nil { | ||
| return false, base.HTTPErrorf(http.StatusNotFound, "keyspace specified in collection_access (%s) not found", fmt.Sprintf("%s.%s.%s", dbc.Name, scopeName, collectionName)) | ||
| } |
There was a problem hiding this comment.
I pushed a bunch of changes for this into this review but ultimately it was a separate long standing problem.
There was a problem hiding this comment.
Most changes are safe mechanical removals of redundant nil checks. One correctness issue: RequiresCollectionAccessUpdate can panic when a collection_access map contains a JSON null value for a collection; the nil check needs to happen before dereferencing read-only fields.
Move the nil check for updatedCollectionAccess before the read-only field checks so a null collection_access entry (used to delete a collection's explicit channels) no longer panics. Regression caught by review from Copilot and factory-droid on PR #8518. Add TestPutUserCollectionAccessNull to cover the null-entry PUT path.
Move the nil check for updatedCollectionAccess before the read-only field checks so a null collection_access entry (used to delete a collection's explicit channels) no longer panics. Regression caught by review from Copilot and factory-droid on PR #8518. Add TestPutUserCollectionAccessNull to cover the null-entry PUT path.
Redocly previews |
- Remove redundant slice nil checks prior to calling len() (staticcheck S1009) - Remove redundant nil checks around slice/map range loops (staticcheck S1031)
Move the nil check for updatedCollectionAccess before the read-only field checks so a null collection_access entry (used to delete a collection's explicit channels) no longer panics. Regression caught by review from Copilot and factory-droid on PR #8518. Add TestPutUserCollectionAccessNull to cover the null-entry PUT path.
55034e1 to
81bb57f
Compare
CBG-5969: fix staticcheck slice/range nil check warnings
This silences some unskippable gopls warnings without specific user configuration.