Staticcheck
lastmod 2026-01-21created 2025-11-0510 edits
Staticcheck is a state of the art linter for the Go programming language. Using static analysis, it finds bugs and performance issues, offers simplifications, and enforces style rules.
Tools
- staticcheck - Go static analysis, detecting bugs, performance issues, and much more.
- structlayout - Displays the layout (field sizes and padding) of structs.
- structlayout-optimize - Reorders struct fields to minimize the amount of padding.
- structlayout-pretty - Formats the output of structlayout with ASCII art.
Install
Installed to $GOPATH/bin. Just run staticcheck from the command line.
Usage
Just pass the location of your Go files.
If there is a problem, an error is printed like this:
run script example
To search subfolders recursively, enter something like ./lib/...:
#!/usr/bin/env bash
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" || exit; pwd)
if ! command -v go &> /dev/null; then
echo "Not found go command" 1>&2
exit 1
fi
staticcheck \
"$ROOT_DIR/lib/..." \
"$ROOT_DIR/cmd/..."
Warnings
How to handle the errors and warnings that are printed.
wrong type for method ProtoReflect
See Protocol Buffers#wrong type for method ProtoReflect for details.
See also
Favorite site
Pages that link here