← 返回命令列表

Linux command

staticcheck 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Analyze all packages

staticcheck ./...

Analyze specific packages

staticcheck [package1] [package2]

Run specific checks only

staticcheck -checks "SA*,ST1000" ./...

Ignore specific checks

staticcheck -checks "all,-ST1003" ./...

Output in different format

staticcheck -f [stylish] ./...

Show explanation for a check

staticcheck -explain [SA1019]

Display version

staticcheck -version

说明

staticcheck is a state-of-the-art static analysis linter for Go. It finds bugs, performance issues, and code quality problems using sophisticated analysis techniques that go beyond what the standard go vet tool provides. The tool includes over 150 checks organized into categories: SA (staticcheck - bugs and correctness), S (simple - code simplifications), ST (stylecheck - style issues), QF (quickfix - suggested improvements), and U (unused - dead code detection). Staticcheck integrates seamlessly with Go's tooling conventions, accepting packages in the same format as go build. It supports configuration via staticcheck.conf files for project-wide settings and inline directives like //lint:ignore for suppressing specific warnings. The linter is used as the default in VS Code's Go extension and is included as a component of golangci-lint. It provides machine-readable output formats for CI/CD integration.

参数

-checks _checks_
Comma-separated list of checks to run. Supports wildcards and negation.
-f _format_
Output format: text (default), stylish, json, sarif, or null.
-fail _checks_
Comma-separated list of checks that cause non-zero exit on findings.
-explain _check_
Display detailed explanation of a specific check.
-show-ignored
Include findings that have been explicitly ignored via directives.
-go _version_
Target Go version for compatibility checks.
-debug.cpuprofile _file_
Write CPU profile to file.
-debug.memprofile _file_
Write memory profile to file.
-debug.version
Print detailed version information.
-version
Display version information.

FAQ

What is the staticcheck command used for?

staticcheck is a state-of-the-art static analysis linter for Go. It finds bugs, performance issues, and code quality problems using sophisticated analysis techniques that go beyond what the standard go vet tool provides. The tool includes over 150 checks organized into categories: SA (staticcheck - bugs and correctness), S (simple - code simplifications), ST (stylecheck - style issues), QF (quickfix - suggested improvements), and U (unused - dead code detection). Staticcheck integrates seamlessly with Go's tooling conventions, accepting packages in the same format as go build. It supports configuration via staticcheck.conf files for project-wide settings and inline directives like //lint:ignore for suppressing specific warnings. The linter is used as the default in VS Code's Go extension and is included as a component of golangci-lint. It provides machine-readable output formats for CI/CD integration.

How do I run a basic staticcheck example?

Run `staticcheck ./...` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -checks _checks_ do in staticcheck?

Comma-separated list of checks to run. Supports wildcards and negation.