cargo_quality/lib.rs
1// SPDX-FileCopyrightText: 2025 RAprogramm <andrey.rozanov.vl@gmail.com>
2// SPDX-License-Identifier: MIT
3
4//! Professional Rust code quality analysis with hardcoded standards.
5//!
6//! `cargo-quality` is a zero-configuration code quality tool that enforces
7//! consistent standards across Rust projects. All rules are embedded in the
8//! binary, ensuring uniform analysis across your entire codebase.
9//!
10//! # Overview
11//!
12//! This library provides:
13//!
14//! - **[`analyzer`]** - Core trait and types for building analyzers
15//! - **[`analyzers`]** - Built-in analyzers for common code quality issues
16//! - **[`formatter`]** - Code formatting with hardcoded standards
17//! - **[`differ`]** - Diff generation and visualization
18//! - **[`report`]** - Analysis report generation
19//! - **[`error`]** - Error types for quality operations
20//!
21//! # Quick Start
22//!
23//! Analyze code for path imports that should be extracted:
24//!
25//! ```rust
26//! use cargo_quality::{analyzer::Analyzer, analyzers::PathImportAnalyzer};
27//!
28//! let analyzer = PathImportAnalyzer::new();
29//! let code = r#"
30//! fn main() {
31//! let content = std::fs::read_to_string("file.txt");
32//! }
33//! "#;
34//! let ast = syn::parse_file(code).unwrap();
35//! let result = analyzer.analyze(&ast, code).unwrap();
36//!
37//! assert!(!result.issues.is_empty());
38//! assert!(result.issues[0].message.contains("Use import"));
39//! ```
40//!
41//! # Available Analyzers
42//!
43//! | Analyzer | Description |
44//! |----------|-------------|
45//! | [`PathImportAnalyzer`] | Detects `std::fs::read` paths that should use `use` |
46//! | [`FormatArgsAnalyzer`] | Finds `println!("{}", x)` that should use `{x}` |
47//! | [`EmptyLinesAnalyzer`] | Finds empty lines in function bodies |
48//! | [`InlineCommentsAnalyzer`] | Finds `//` comments that should be `///` |
49//!
50//! [`PathImportAnalyzer`]: analyzers::PathImportAnalyzer
51//! [`FormatArgsAnalyzer`]: analyzers::FormatArgsAnalyzer
52//! [`EmptyLinesAnalyzer`]: analyzers::EmptyLinesAnalyzer
53//! [`InlineCommentsAnalyzer`]: analyzers::InlineCommentsAnalyzer
54//!
55//! # Running All Analyzers
56//!
57//! Use [`analyzers::get_analyzers()`] to get all built-in analyzers:
58//!
59//! ```rust
60//! use cargo_quality::{analyzer::Analyzer, analyzers::get_analyzers};
61//!
62//! let code = r#"
63//! fn main() {
64//! let x = std::fs::read("file");
65//! }
66//! "#;
67//! let ast = syn::parse_file(code).unwrap();
68//!
69//! for analyzer in get_analyzers() {
70//! let result = analyzer.analyze(&ast, code).unwrap();
71//! println!("[{}] {} issues", analyzer.name(), result.issues.len());
72//! }
73//! ```
74//!
75//! # Custom Analyzers
76//!
77//! Implement the [`analyzer::Analyzer`] trait to create custom analyzers:
78//!
79//! ```rust
80//! use cargo_quality::analyzer::{AnalysisResult, Analyzer};
81//! use masterror::AppResult;
82//! use syn::File;
83//!
84//! struct MyAnalyzer;
85//!
86//! impl Analyzer for MyAnalyzer {
87//! fn name(&self) -> &'static str {
88//! "my_analyzer"
89//! }
90//!
91//! fn analyze(&self, _ast: &File, _content: &str) -> AppResult<AnalysisResult> {
92//! Ok(AnalysisResult::default())
93//! }
94//!
95//! fn fix(&self, _ast: &mut File) -> AppResult<usize> {
96//! Ok(0)
97//! }
98//! }
99//! ```
100//!
101//! # Feature Flags
102//!
103//! This crate has no optional features. All functionality is enabled by
104//! default.
105//!
106//! # Standards
107//!
108//! This tool enforces standards from [RustManifest](https://github.com/RAprogramm/RustManifest):
109//!
110//! - No inline `::` paths in code (use `use` statements)
111//! - Named format arguments for readability
112//! - No empty lines inside function bodies
113//! - Doc comments only (no inline `//` comments)
114
115pub mod analyzer;
116pub mod analyzers;
117pub mod differ;
118pub mod error;
119pub mod file_utils;
120pub mod formatter;
121pub mod mod_rs;
122pub mod report;