chore: enhance golangci-lint with nil-safety and type-assertion linters#604
Merged
chore: enhance golangci-lint with nil-safety and type-assertion linters#604
Conversation
Enable forcetypeassert, nilerr, nilnesserr, nilnil linters and govet nilness analyzer to catch nil pointer dereferences and unsafe type assertions at lint time. Exclude forcetypeassert from test files.
- lsp/server.go: add type assertion ok checks for LSP params to prevent panics on malformed messages - gen_shims/main.go: use idiomatic switch assignment to eliminate redundant type assertions, remove dead nil-check code - config/file_discovery.go: nolint nilerr for intentional WalkDir skip - config/cli_rules.go: nolint nilnil for documented no-input convention
Contributor
There was a problem hiding this comment.
Code Review
This pull request enables several new linters, including forcetypeassert, nilerr, nilnesserr, and nilnil, and updates the codebase to comply with these rules. Key changes include replacing unsafe type assertions with safe 'comma ok' checks in the LSP server implementation and adding intentional nolint annotations in configuration logic. Additionally, the shim generation tool was refactored to use more idiomatic type switches. I have no feedback to provide.
chenjiahan
approved these changes
Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enable additional golangci-lint rules to catch nil pointer dereferences and unsafe type assertions at lint time:
x.(Type)withoutokcheck) that can panic at runtime. Excluded from test files.nilerror whenerr != nil, which silently swallows errors.return nil, nilthat can confuse callers.err != nilbranches that return a different nil error variable.All existing warnings from the newly enabled linters have been fixed:
internal/lsp/server.go: addedokchecks for LSP params type assertions to prevent server panics on malformed messages.tools/gen_shims/main.go: refactored type switch to idiomatic assignment form; removed dead nil-check code.internal/config/file_discovery.go: addednolint:nilerrfor intentionalfs.WalkDirerror-skip pattern.internal/config/cli_rules.go: addednolint:nilnilfor documented no-input return convention.Related Links
N/A
Checklist