Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the customlint analyzers with the following changes: updates to use newer inspector APIs, removes defensive nil checks and type assertions, improves panic messages, adds test coverage, and fixes the plugin load mode.
Changes:
- Refactored all analyzers to use
inspector.Root().Preorder()instead of olderinspect.Preorder()orinspect.PreorderSeq()APIs - Removed defensive nil checks and type assertions throughout the codebase, replacing them with fail-fast panics
- Added comprehensive test cases to improve code coverage for unexported API and shadow checkers
- Changed plugin load mode from
LoadModeSyntaxtoLoadModeTypesInfoto match analyzer requirements
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
_tools/customlint/unexportedapi.go |
Refactored to use new inspector API, renamed functions for clarity, removed nil checks, improved SelectorExpr handling, added types.Alias support, and removed unused expression cases |
_tools/customlint/shadow.go |
Refactored to use new inspector API, removed defensive type assertions and nil checks, removed unused functions, added map capacity hints |
_tools/customlint/emptycase.go |
Refactored to use pass struct pattern and new inspector API, changed default case to panic |
_tools/customlint/plugin.go |
Changed GetLoadMode from LoadModeSyntax to LoadModeTypesInfo |
_tools/customlint/testdata/unexportedapi/* |
Added extensive test cases for edge cases and code coverage, including new otherpkg test package |
_tools/customlint/testdata/shadow/* |
Added comprehensive shadow detection test cases |
Comments suppressed due to low confidence (2)
_tools/customlint/unexportedapi.go:241
- The removal of the nil check for
objis unsafe. At line 231, if bothu.pass.TypesInfo.Defs[expr]andu.pass.TypesInfo.Uses[expr]are nil, thenobjwill be nil. Accessingobj.Parent()on the next line will cause a nil pointer dereference panic. The original nil check should be restored.
case *ast.Ident:
// First check Defs (for defining occurrences), then Uses (for referring occurrences)
obj := u.pass.TypesInfo.Defs[expr]
if obj == nil {
obj = u.pass.TypesInfo.Uses[expr]
}
if !expr.IsExported() {
if obj.Parent() == types.Universe {
return false
}
// Only report if the unexported identifier is from the same package
if obj.Pkg() != nil && obj.Pkg() == u.pass.Pkg {
u.pass.Reportf(expr.Pos(), "exported API references unexported identifier %s", expr.Name)
return true
}
}
return u.checkType(obj.Type())
_tools/customlint/unexportedapi.go:191
- The removal of the nil check for
typis unsafe. At line 162,u.pass.TypesInfo.TypeOf(field.Type)can return nil if type information is unavailable. Iftypis nil, the call totyp.Underlying()at line 173 will cause a nil pointer dereference panic. The original nil check in checkEmbeddedField should be restored.
func (u *unexportedAPIPass) checkEmbeddedField(field *ast.Field) (stop bool) {
// Get the type of the embedded field
typ := u.pass.TypesInfo.TypeOf(field.Type)
// For embedded fields, walk through all exported members and check them.
// Use the checked map to avoid re-checking members we've already seen.
// Dereference pointers
if ptr, ok := typ.(*types.Pointer); ok {
typ = ptr.Elem()
}
// Check exported fields in structs
if structType, ok := typ.Underlying().(*types.Struct); ok {
for field := range structType.Fields() {
if field.Exported() && u.checkObjectType(field) {
return true
}
}
}
// Check exported methods on the type
if named, ok := typ.(*types.Named); ok {
for method := range named.Methods() {
if method.Exported() && u.checkObjectType(method) {
return true
}
}
}
return false
}
sheetalkamat
approved these changes
Feb 2, 2026
sheetalkamat
approved these changes
Feb 5, 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.
These are some refactors I've had on the mind for a while but never wrote down / had copilot do. Might as well send them...