Skip to content

CBG-5969: fix staticcheck slice/range nil check warnings - #8518

Open
torcolvin wants to merge 4 commits into
mainfrom
CBG-5969-gopls-nil-slices
Open

CBG-5969: fix staticcheck slice/range nil check warnings#8518
torcolvin wants to merge 4 commits into
mainfrom
CBG-5969-gopls-nil-slices

Conversation

@torcolvin

Copy link
Copy Markdown
Collaborator

CBG-5969: fix staticcheck slice/range nil check warnings

  • Remove redundant slice nil checks prior to calling len() (staticcheck S1009)
  • Remove redundant nil checks around slice/map range loops (staticcheck S1031)

This silences some unskippable gopls warnings without specific user configuration.

Copilot AI review requested due to automatic review settings July 31, 2026 15:08
@factory-droid

factory-droid Bot commented Jul 31, 2026

Copy link
Copy Markdown

Droid finished @torcolvin's task —— View job


Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 nil checks before len(slice) calls across REST/DB code paths (S1009).
  • Remove redundant nil checks guarding range loops where applicable (S1031).
  • Update .golangci-strict.yml to 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.

Comment thread .golangci-strict.yml
Comment thread db/users.go
Comment on lines +271 to +275
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))
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a bunch of changes for this into this review but ultimately it was a separate long standing problem.

Comment thread db/users.go Outdated

@factory-droid factory-droid Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

torcolvin added a commit that referenced this pull request Aug 4, 2026
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.
@torcolvin
torcolvin requested review from a team and bbrks August 4, 2026 19:16
torcolvin added a commit that referenced this pull request Aug 4, 2026
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.
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Redocly previews

@bbrks bbrks assigned torcolvin and unassigned bbrks Aug 5, 2026
- 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.
@torcolvin
torcolvin force-pushed the CBG-5969-gopls-nil-slices branch from 55034e1 to 81bb57f Compare August 6, 2026 15:48
@torcolvin torcolvin assigned bbrks and torcolvin and unassigned torcolvin and bbrks Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants