Clippy & rustfmt — Linting and Formatting
eslint + prettier → clippy + rustfmt
Section titled “eslint + prettier → clippy + rustfmt”In TypeScript projects you typically wire up two separate tools: eslint for catching logical mistakes and enforcing code patterns, and prettier for opinionated formatting. Each needs its own config, its own plugins, and sometimes they conflict.
Rust ships two first-party tools that are always present:
| TypeScript | Rust | Purpose |
|---|---|---|
eslint | cargo clippy | Catches bugs, anti-patterns, and non-idiomatic code |
prettier | cargo fmt | Enforces a single canonical style |
.eslintrc | clippy.toml or #[allow(...)] | Configuration |
.prettierrc | rustfmt.toml | Formatting overrides |
cargo fmt — formatting
Section titled “cargo fmt — formatting”# TypeScriptnpx prettier --write "src/**/*.ts"
# Rustcargo fmt # format all files in the workspacecargo fmt --check # CI mode: exit 1 if any file would changecargo fmt wraps rustfmt. The defaults are the official style and almost no one overrides them. A minimal rustfmt.toml at the project root can adjust a few options:
# rustfmt.toml (optional — most projects have none)max_width = 100edition = "2021"cargo clippy — linting
Section titled “cargo clippy — linting”# TypeScriptnpx eslint src/
# Rustcargo clippy # warn on lint violationscargo clippy -- -D warnings # treat every warning as a compile error (use on CI)// eslint might warn: prefer constlet items = getItems();
// eslint might warn: no-unused-varsfunction helper(x: number, _y: number) { return x * 2;}// Clippy warns: this could be written more idiomaticallylet v: Vec<i32> = vec![1, 2, 3];let doubled: Vec<i32> = v.iter().map(|x| x * 2).collect();
// Clippy warns: use .is_empty() instead of .len() == 0if doubled.len() == 0 { println!("empty");}// Idiomatic version:if doubled.is_empty() { println!("empty");}Suppressing a lint
Section titled “Suppressing a lint”// Suppress one lint on the next item#[allow(clippy::needless_pass_by_value)]fn process(data: Vec<u8>) { /* ... */ }
// Suppress across the whole file (put at crate root)#![allow(dead_code)]Recommended CI configuration
Section titled “Recommended CI configuration”Run both tools on CI so formatting and lint errors are caught before merge:
cargo fmt --checkcargo clippy -- -D warningscargo testThese are
bashcommands to run in your terminal or CI pipeline — there is no runnable browser snippet for linter invocations.