Overview
Clippy is the official lint suite, a rustup component run as cargo clippy, with over
750 lints that go far beyond the compiler's built-in warnings: idiom upgrades, API
misuse, performance smells, outright bugs. Because it plugs into rustc's own lint-level
machinery (allow/warn/deny attributes), policy is expressed in source, per item or
per crate, rather than in an external config — closer to a compiler feature than to the
JVM's checkstyle/SpotBugs layer, and roughly covering what
staticcheck does for Go.
Key points
- Categories with default levels:
correctness(deny — these are bugs),suspiciousandstyleandcomplexityandperf(warn),pedanticandnurseryandrestrictionandcargo(allow — opt-in only). - Turning on pedantic wholesale is a trap:
#![warn(clippy::pedantic)]plus targeted#[allow]s works for greenfield libraries; on applications, cherry-picking individual pedantic lints ages better. cargo clippy --fixapplies machine-applicable suggestions — safe, and an excellent idiom tutor when upgrading old code or learning the language.- CI gate:
cargo clippy --all-targets --all-features -- -D warnings— lint tests and examples too, deny drift. Prefer failing on warnings in CI overdenyattributes in source (deny breaks builds for downstream users on newer clippy versions with new lints). clippy.tomlconfigures individual lints' thresholds (too-many-arguments,cognitive-complexity, MSRV for idiom suggestions) — not lint selection, which stays in source or on the command line.#[allow(clippy::lint_name, reason = "…")]: scoped, documented exemptions at the narrowest item that needs them — the review-friendly form.- New lints arrive every six weeks with the toolchain; a version bump can introduce warnings. That's the deal — treat the diff as a free code review.
Examples
cargo clippy --all-targets -- -D warnings # the CI invocation
cargo clippy --fix # apply machine-applicable suggestions
#![warn(clippy::pedantic)] // library crate root
#[allow(clippy::module_name_repetitions, reason = "re-exported at crate root")]
pub struct ConfigError { /* … */ }
Related
- The Rust toolchain — parent catalog.
- rustc — the lint-level machinery clippy plugs into.
- rustfmt — the mechanical-style layer below lint.
- staticcheck & golangci-lint — the Go counterpart, third-party where clippy is first-party.