Ptrcmp
A linter to detect direct comparisons between basic pointer types in Go
Install / Use
/learn @loveholidays/PtrcmpREADME
ptrcmp
This linter detects direct comparisons between basic pointer types (like *int, *string) since developers usually want to compare the underlying values rather than memory addresses.
Run
go run main.go ./example
Why use this linter?
This linter helps prevent subtle bugs by detecting direct comparisons between basic pointer types (like *int, *string, etc.). Such comparisons check if two pointers reference the exact same memory address rather than comparing the underlying values, which is rarely the intended behavior in application code.
For example:
var one *int
var two *int
if one == two {
// linter should highlight as comparisons between two "basic" ptrs i.e *int == *int
}
if *one == *two {
// linter should ignore as its int == int
}
While pointer comparisons have valid uses (particularly in low-level code), they're often a source of bugs when working with basic types where value comparison is typically desired. This linter helps developers catch these cases early and encourages more explicit code by requiring them to either:
- Use value comparison with dereferencing (*x == *y)
- Explicitly acknowledge pointer comparison is intended by disabling the lint warning
Related Skills
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
