-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Summary
Configure clippy lints to automatically enforce coding standards and catch inconsistencies during development and CI. This will prevent new inconsistencies from being introduced.
Current State
- No
.clippy.tomlconfiguration file exists - CI runs
cargo clippy --all-targets --all-featuresbut with default settings - Inconsistencies in import ordering, unwrap usage, and documentation are not caught automatically
Target State
Add clippy configuration to enforce:
- Import ordering - Group and sort imports consistently
- Unwrap usage - Warn on
unwrap()in non-test code - Documentation - Require docs on public items
- Error handling - Prefer
expect()overunwrap()where unavoidable
Changes Required
1. Create clippy.toml in project root
# Clippy configuration for trusted-server
# See: https://doc.rust-lang.org/clippy/configuration.html
# Cognitive complexity threshold for functions
cognitive-complexity-threshold = 30
# Maximum number of lines in a function
too-many-lines-threshold = 2002. Add workspace-level clippy lints in Cargo.toml
[workspace.lints.clippy]
# Correctness
unwrap_used = "warn"
expect_used = "allow" # Allow expect with context message
panic = "warn"
# Style
module_name_repetitions = "allow"
must_use_candidate = "warn"
# Pedantic (selective)
doc_markdown = "warn"
missing_errors_doc = "warn"
missing_panics_doc = "warn"
# Restriction (selective)
print_stdout = "warn"
print_stderr = "warn"
dbg_macro = "warn"3. Enable lints in each crate's Cargo.toml
[lints]
workspace = true4. Add lint allows for test modules
In test code, add:
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
// ...
}5. Update CI workflow (.github/workflows/format.yml)
Ensure clippy runs with deny on warnings for enforced lints:
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warningsLints Explanation
| Lint | Purpose |
|---|---|
unwrap_used |
Catch potential panics, encourage proper error handling |
panic |
Explicit panics should be documented or avoided |
doc_markdown |
Enforce proper markdown in documentation |
missing_errors_doc |
Document what errors functions can return |
missing_panics_doc |
Document when functions can panic |
print_stdout/stderr |
Use logging instead of print statements |
dbg_macro |
Remove debug macros before committing |
Testing
cargo clippy --all-targets --all-features- Run clippy with new config- Address any new warnings or add targeted
#[allow(...)]with justification - Ensure CI passes
Complexity
Low - Configuration only, with some targeted allow annotations
Notes
- Start with
warnlevel to identify issues without breaking builds - Gradually promote to
denyas codebase is cleaned up - Individual exceptions can use
#[allow(clippy::...)]with a comment explaining why
Labels
good first issuetech-debtdeveloper-experienceci