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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// SPDX-FileCopyrightText: 2025 RAprogramm <andrey.rozanov.vl@gmail.com>
// SPDX-License-Identifier: MIT
//! Built-in code quality analyzers.
//!
//! This module contains all analyzers that ship with cargo-quality.
//! Each analyzer detects a specific code quality issue and optionally
//! provides automatic fixes.
//!
//! # Available Analyzers
//!
//! | Analyzer | Issue Detected | Auto-fix |
//! |----------|---------------|----------|
//! | [`PathImportAnalyzer`] | `std::fs::read()` paths | Yes |
//! | [`FormatArgsAnalyzer`] | `println!("{}", x)` positional args | No |
//! | [`EmptyLinesAnalyzer`] | Empty lines in functions | Yes |
//! | [`InlineCommentsAnalyzer`] | `//` comments in code | No |
//!
//! # Usage
//!
//! Get all analyzers:
//!
//! ```rust
//! use cargo_quality::analyzers::get_analyzers;
//!
//! let analyzers = get_analyzers();
//! assert_eq!(analyzers.len(), 4);
//! ```
//!
//! Use a specific analyzer:
//!
//! ```rust
//! use cargo_quality::{analyzer::Analyzer, analyzers::PathImportAnalyzer};
//!
//! let analyzer = PathImportAnalyzer::new();
//! let code = "fn main() { std::fs::read(\"f\"); }";
//! let ast = syn::parse_file(code).unwrap();
//!
//! let result = analyzer.analyze(&ast, code).unwrap();
//! println!("Found {} issues", result.issues.len());
//! ```
//!
//! # Analyzer Details
//!
//! ## Path Import Analyzer
//!
//! Detects module paths with `::` that should be moved to `use` statements.
//! Only flags free functions from modules, not associated functions or enum
//! variants.
//!
//! ```rust
//! # use cargo_quality::{analyzer::Analyzer, analyzers::PathImportAnalyzer};
//! let analyzer = PathImportAnalyzer::new();
//! let code = r#"
//! fn main() {
//! // Flagged: should use `use std::fs::read_to_string;`
//! let _ = std::fs::read_to_string("file.txt");
//!
//! // NOT flagged: associated function on type
//! let _ = Vec::new();
//! }
//! "#;
//! let ast = syn::parse_file(code).unwrap();
//! let result = analyzer.analyze(&ast, code).unwrap();
//! assert_eq!(result.issues.len(), 1);
//! ```
//!
//! ## Format Args Analyzer
//!
//! Detects positional format arguments that should use named arguments
//! for better readability (3+ placeholders triggers a warning).
//!
//! ```rust
//! # use cargo_quality::{analyzer::Analyzer, analyzers::FormatArgsAnalyzer};
//! let analyzer = FormatArgsAnalyzer::new();
//! let code = r#"
//! fn main() {
//! // Flagged: 3+ positional args
//! println!("{} {} {}", a, b, c);
//!
//! // NOT flagged: only 2 args
//! println!("{} {}", a, b);
//! }
//! "#;
//! let ast = syn::parse_file(code).unwrap();
//! let result = analyzer.analyze(&ast, code).unwrap();
//! assert_eq!(result.issues.len(), 1);
//! ```
//!
//! ## Empty Lines Analyzer
//!
//! Detects empty lines inside function bodies that indicate the function
//! is doing multiple things and should be refactored.
//!
//! ```rust
//! # use cargo_quality::{analyzer::Analyzer, analyzers::EmptyLinesAnalyzer};
//! let analyzer = EmptyLinesAnalyzer::new();
//! let code = "fn main() {\n let x = 1;\n\n let y = 2;\n}";
//! let ast = syn::parse_file(code).unwrap();
//! let result = analyzer.analyze(&ast, code).unwrap();
//! assert_eq!(result.issues.len(), 1);
//! ```
//!
//! ## Inline Comments Analyzer
//!
//! Detects `//` comments inside function bodies. These should be moved
//! to doc comments (`///`) in the `# Notes` section.
//!
//! ```rust
//! # use cargo_quality::{analyzer::Analyzer, analyzers::InlineCommentsAnalyzer};
//! let analyzer = InlineCommentsAnalyzer::new();
//! let code = "fn main() {\n // This is flagged\n let x = 1;\n}";
//! let ast = syn::parse_file(code).unwrap();
//! let result = analyzer.analyze(&ast, code).unwrap();
//! assert_eq!(result.issues.len(), 1);
//! ```
pub use EmptyLinesAnalyzer;
pub use FormatArgsAnalyzer;
pub use InlineCommentsAnalyzer;
pub use PathImportAnalyzer;
use crateAnalyzer;
/// Returns all built-in analyzers.
///
/// This function creates new instances of all available analyzers.
/// Use this to run comprehensive code quality checks.
///
/// # Returns
///
/// Vector of boxed analyzer trait objects, in order:
/// 1. [`PathImportAnalyzer`] - path separator detection
/// 2. [`FormatArgsAnalyzer`] - format argument detection
/// 3. [`EmptyLinesAnalyzer`] - empty line detection
/// 4. [`InlineCommentsAnalyzer`] - inline comment detection
///
/// # Examples
///
/// ```rust
/// use cargo_quality::{analyzer::Analyzer, analyzers::get_analyzers};
///
/// let analyzers = get_analyzers();
/// assert_eq!(analyzers.len(), 4);
///
/// for analyzer in &analyzers {
/// println!("Analyzer: {}", analyzer.name());
/// }
/// ```