mirror of
https://github.com/leonardomso/rust-skills.git
synced 2026-09-14 19:33:21 +08:00
0016d5cfb2
Includes rules for: - Ownership and borrowing patterns - Error handling with thiserror/anyhow - Memory management and allocation - API design following Rust guidelines - Async/Tokio patterns - Performance optimization - Naming conventions - Type safety - Testing strategies - Documentation standards - Project structure - Linting configuration - Common anti-patterns to avoid
3.6 KiB
3.6 KiB
lint-workspace-lints
Configure lints at workspace level for consistent enforcement
Why It Matters
Without centralized lint configuration, each crate develops its own standards (or none). Workspace-level lints (Rust 1.74+) ensure consistent code quality across all crates. Denied lints catch issues in CI before they reach production.
Bad
# crate-a/Cargo.toml - strict
[lints.clippy]
unwrap_used = "deny"
# crate-b/Cargo.toml - lenient
# No lint config
# crate-c/Cargo.toml - different
[lints.clippy]
unwrap_used = "warn"
# Inconsistent enforcement, some issues slip through
Good
# Root Cargo.toml
[workspace.lints.rust]
unsafe_code = "deny"
missing_docs = "warn"
[workspace.lints.clippy]
# Correctness
unwrap_used = "deny"
expect_used = "warn"
panic = "deny"
# Style
needless_pass_by_value = "warn"
redundant_clone = "warn"
# Complexity
cognitive_complexity = "warn"
[workspace.lints.rustdoc]
broken_intra_doc_links = "deny"
# crate-a/Cargo.toml
[lints]
workspace = true
# crate-b/Cargo.toml
[lints]
workspace = true
Recommended Lint Configuration
# Root Cargo.toml
[workspace.lints.rust]
# Safety
unsafe_code = "deny"
missing_debug_implementations = "warn"
# Quality
unused_results = "warn"
unused_qualifications = "warn"
[workspace.lints.clippy]
# === Correctness (deny) ===
correctness = { level = "deny", priority = -1 }
# === Suspicious (deny) ===
suspicious = { level = "deny", priority = -1 }
# === Style (warn) ===
style = { level = "warn", priority = -1 }
# === Complexity (warn) ===
complexity = { level = "warn", priority = -1 }
# === Perf (warn) ===
perf = { level = "warn", priority = -1 }
# === Pedantic (selective) ===
# Not all pedantic lints are useful
doc_markdown = "warn"
needless_pass_by_value = "warn"
redundant_closure_for_method_calls = "warn"
semicolon_if_nothing_returned = "warn"
# === Nursery (selective) ===
cognitive_complexity = "warn"
useless_let_if_seq = "warn"
# === Restriction (selective) ===
unwrap_used = "deny"
expect_used = "warn"
dbg_macro = "warn"
print_stdout = "warn" # Use logging instead
todo = "warn"
[workspace.lints.rustdoc]
broken_intra_doc_links = "deny"
private_intra_doc_links = "warn"
Per-Crate Overrides
# crate-with-binary/Cargo.toml
[lints]
workspace = true
# Binary entry point can use unwrap
[lints.clippy]
unwrap_used = "allow"
# test-utils/Cargo.toml
[lints]
workspace = true
# Test utilities can print
[lints.clippy]
print_stdout = "allow"
CI Integration
# .github/workflows/ci.yml
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Clippy
run: cargo clippy --workspace --all-targets -- -D warnings
- name: Rustdoc
run: RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps
Lint Categories
# Category-level configuration
[workspace.lints.clippy]
# All lints in category at once
correctness = { level = "deny", priority = -1 }
suspicious = { level = "deny", priority = -1 }
style = { level = "warn", priority = -1 }
complexity = { level = "warn", priority = -1 }
perf = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }
# Then override specific lints (higher priority)
missing_errors_doc = "allow" # Override pedantic
See Also
- lint-deny-correctness - Critical lints
- proj-workspace-deps - Workspace configuration
- anti-unwrap-abuse - unwrap lints