rust_doctor/lib.rs
1//! # rust-doctor
2//!
3//! A unified code health tool for Rust — scan, score, and fix your codebase.
4//!
5//! rust-doctor analyzes Rust projects for security, performance, correctness,
6//! architecture, and dependency issues, producing a 0–100 health score with
7//! actionable diagnostics.
8//!
9//! ## Quick start (library usage)
10//!
11//! ```rust,no_run
12//! use std::path::Path;
13//!
14//! // Discover the project
15//! let (dir, info, config) = rust_doctor::discovery::bootstrap_project(
16//! Path::new("."), false,
17//! ).unwrap();
18//!
19//! // Resolve config with defaults
20//! let resolved = rust_doctor::config::resolve_config_defaults(config.as_ref());
21//!
22//! // Run the scan
23//! let result = rust_doctor::scan::scan_project(&info, &resolved, false, &[], true).unwrap();
24//! println!("Score: {}/100 ({})", result.score, result.score_label);
25//! ```
26
27#![forbid(unsafe_code)]
28#![warn(clippy::pedantic)]
29// Restriction lints (unwrap/expect/panic) are enforced in prod but normal in
30// tests. Belt for clippy #13981 where allow-*-in-tests misses some contexts.
31#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used, clippy::panic))]
32// Expect these pedantic lints project-wide — they conflict with our design choices.
33// Using #[expect] so the compiler warns if any suppression becomes dead.
34#![expect(
35 clippy::module_name_repetitions,
36 reason = "module prefixes on types are intentional"
37)]
38#![expect(
39 clippy::must_use_candidate,
40 reason = "not all public fns need #[must_use]"
41)]
42#![expect(
43 clippy::missing_errors_doc,
44 reason = "deferred until v1.0 public API stabilization"
45)]
46#![expect(
47 clippy::doc_markdown,
48 reason = "markdown linting too strict for rule names"
49)]
50#![expect(
51 clippy::struct_excessive_bools,
52 reason = "visitor state requires bool fields"
53)]
54#![expect(
55 clippy::cast_possible_truncation,
56 reason = "line/column casts are safe within u32 range"
57)]
58#![expect(
59 clippy::cast_precision_loss,
60 reason = "score penalty math is fine with f64"
61)]
62#![expect(
63 clippy::items_after_statements,
64 reason = "inline test helpers after setup"
65)]
66#![expect(clippy::cast_sign_loss, reason = "score clamped to 0-100 before cast")]
67#![expect(
68 clippy::used_underscore_binding,
69 reason = "underscore prefixes used in destructuring"
70)]
71
72/// Command-line argument parsing and flag definitions.
73pub mod cli;
74/// Configuration loading, merging, and validation.
75pub mod config;
76/// External tool dependency checking and installation.
77pub mod deps;
78/// Core diagnostic types: `Diagnostic`, `Severity`, `Category`, `ScanResult`.
79pub mod diagnostics;
80/// Project discovery via `cargo metadata` and framework detection.
81pub mod discovery;
82/// Error types for the scan pipeline, bootstrapping, and MCP.
83pub mod error;
84/// Auto-fix application for machine-applicable diagnostic fixes.
85pub mod fixer;
86/// MCP (Model Context Protocol) server for AI tool integration.
87#[cfg(feature = "mcp")]
88pub mod mcp;
89/// Terminal, JSON, and score output rendering.
90pub mod output;
91/// Remediation plan generator from scan diagnostics.
92pub mod plan;
93/// SARIF 2.1.0 output for CI/CD integration.
94pub mod sarif;
95/// Top-level scan pipeline that orchestrates all analysis passes.
96pub mod scan;
97/// Interactive setup wizard for AI agent integration.
98pub mod setup;
99
100/// Pipeline helper functions used by the CLI entry point.
101///
102/// This module is public so the binary crate can call these functions,
103/// but its contents are not part of the stable public API.
104#[doc(hidden)]
105pub mod run;
106
107// Internal implementation modules
108pub(crate) mod cache;
109pub(crate) mod diff;
110pub(crate) mod passes;
111pub(crate) mod process;
112pub(crate) mod scanner;
113pub(crate) mod suppression;
114pub(crate) mod workspace;
115
116// Re-export pass modules at crate root so existing `use crate::audit` etc. still work.
117pub(crate) use passes::quality::coverage;
118pub(crate) use passes::quality::machete;
119pub(crate) use passes::quality::msrv;
120pub(crate) use passes::quality::semver_checks;
121pub(crate) use passes::security::audit;
122pub(crate) use passes::security::deny;
123pub(crate) use passes::security::geiger;
124pub(crate) use passes::static_analysis::clippy;
125pub(crate) use passes::static_analysis::rules;