Skip to content

chore: enhance golangci-lint with nil-safety and type-assertion linters#604

Merged
fansenze merged 2 commits intomainfrom
chore/enhance-golangci-lint-20260407
Apr 7, 2026
Merged

chore: enhance golangci-lint with nil-safety and type-assertion linters#604
fansenze merged 2 commits intomainfrom
chore/enhance-golangci-lint-20260407

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Apr 7, 2026

Summary

Enable additional golangci-lint rules to catch nil pointer dereferences and unsafe type assertions at lint time:

  • forcetypeassert: detects unchecked type assertions (x.(Type) without ok check) that can panic at runtime. Excluded from test files.
  • nilerr: detects returning nil error when err != nil, which silently swallows errors.
  • nilnil: detects simultaneous return nil, nil that can confuse callers.
  • nilnesserr: detects err != nil branches that return a different nil error variable.
  • govet.nilness: detects nil dereferences and impossible nil comparisons via static analysis.

All existing warnings from the newly enabled linters have been fixed:

  • internal/lsp/server.go: added ok checks 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: added nolint:nilerr for intentional fs.WalkDir error-skip pattern.
  • internal/config/cli_rules.go: added nolint:nilnil for documented no-input return convention.

Related Links

N/A

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

fansenze added 2 commits April 7, 2026 14:09
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
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

@fansenze fansenze merged commit 5e8cbd4 into main Apr 7, 2026
11 checks passed
@fansenze fansenze deleted the chore/enhance-golangci-lint-20260407 branch April 7, 2026 06:30
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.

2 participants