checkerlint Catches Faulty Go Struct Validation Tags Before Runtime
A new static analysis tool called checkerlint addresses a silent failure risk in Go programs where malformed struct validation tags compile successfully but crash or misbehave at runtime. The tool, built on Go's go/analysis framework, scans checker struct tags at build or lint time to flag three categories of errors: unknown checker names, type-incompatible checker usage, and cross-field references pointing to non-existent fields. For example, applying an email checker to an integer field or referencing a misspelled sibling field will now produce a build-time error rather than a runtime panic. checkerlint can be run as a standalone binary, plugged into go vet, or integrated as a custom linter within golangci-lint v2. It automatically stays in sync with whichever version of the github.com/cinar/checker/v2 library a project uses, though it cannot detect checkers registered dynamically at runtime or via non-literal expressions.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in