rust-code-quality

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rust Code Quality Review

Rust代码质量审查

Systematically review Rust code quality against best practices.
依据最佳实践对Rust代码质量进行系统性审查。

Quality Dimensions

质量维度

DimensionFocusTools
StructureFiles <500 LOC, module hierarchy
find . -name "*.rs"
Error HandlingCustom Error, Result<T>, no unwrap
rg "unwrap|Result<"
Async Patternsasync fn, spawn_blocking, no blocking
rg "async fn|spawn_blocking"
Testing>90% coverage, integration tests
cargo tarpaulin
DocumentationPublic APIs 100% documented
cargo doc --no-deps
维度审查重点工具
项目结构单个文件代码行数<500,模块层级清晰
find . -name "*.rs"
错误处理自定义错误类型、使用Result<T>、不使用unwrap
rg "unwrap|Result<"
异步模式使用async fn、spawn_blocking、无阻塞操作
rg "async fn|spawn_blocking"
测试测试覆盖率>90%、集成测试
cargo tarpaulin
文档公开API 100%配有文档
cargo doc --no-deps

Analysis Commands

分析命令

bash
undefined
bash
undefined

Project structure

项目结构

find . -name ".rs" -not -path "/target/*" -exec wc -l {} + | sort -rn
find . -name ".rs" -not -path "/target/*" -exec wc -l {} + | sort -rn

Error handling

错误处理

rg "unwrap()" --glob "!/tests/" --glob "*.rs"
rg "unwrap()" --glob "!/tests/" --glob "*.rs"

Async patterns

异步模式

rg "async fn|spawn_blocking|tokio::" --glob "*.rs"
rg "async fn|spawn_blocking|tokio::" --glob "*.rs"

Testing

测试

cargo test --all cargo tarpaulin --out Html
cargo test --all cargo tarpaulin --out Html

Linting

代码检查

./scripts/code-quality.sh fmt ./scripts/code-quality.sh clippy --workspace cargo audit
undefined
./scripts/code-quality.sh fmt ./scripts/code-quality.sh clippy --workspace cargo audit
undefined

Output Format

输出格式

markdown
undefined
markdown
undefined

Rust Code Quality Report

Rust代码质量报告

Summary

摘要

  • Score: X/100
  • Critical Issues: N
  • Warnings: M
  • 得分: X/100
  • 严重问题: N
  • 警告: M

By Dimension

按维度划分

  • Structure: X/10 - [Status]
  • Error Handling: X/10 - [Status]
  • Async Patterns: X/10 - [Status]
  • Testing: X/10 - [Status]
  • Documentation: X/10 - [Status]
  • 项目结构: X/10 - [状态]
  • 错误处理: X/10 - [状态]
  • 异步模式: X/10 - [状态]
  • 测试: X/10 - [状态]
  • 文档: X/10 - [状态]

Critical Issues

严重问题

  1. [Issue] - File:line
    • Fix: [Recommendation]
  1. [问题描述] - 文件:行号
    • 修复建议: [具体方案]

Action Items

行动项

High Priority

高优先级

  • Fix critical issues
  • 修复严重问题

Medium Priority

中优先级

  • Address warnings
undefined
  • 处理警告
undefined

Best Practices Checklist

最佳实践检查清单

✓ Files <500 LOC ✓ Clear module hierarchy ✓ Custom Error enum ✓ Result<T> for fallible ops ✓ No unwrap() in production ✓ async fn for IO operations ✓ spawn_blocking for CPU work ✓ >90% test coverage ✓ Public APIs documented
✓ 单个文件代码行数<500 ✓ 模块层级清晰 ✓ 自定义Error枚举 ✓ 对可能失败的操作使用Result<T> ✓ 生产代码中不使用unwrap() ✓ IO操作使用async fn ✓ CPU密集型工作使用spawn_blocking ✓ 测试覆盖率>90% ✓ 公开API均有文档