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