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
//! Clippy Integration: Bridge between Clippy diagnostics and ryo-mutations
//!
//! This module provides integration with [Clippy](https://github.com/rust-lang/rust-clippy),
//! Rust's official linting tool. It enables automatic code transformations based on
//! Clippy's suggestions.
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │ Clippy Integration │
//! ├─────────────────────────────────────────────────────────────┤
//! │ cargo clippy --message-format=json │
//! │ ↓ │
//! │ ┌─────────────────────────────────────────────────────┐ │
//! │ │ ClippyDiagnostic │ │
//! │ │ - lint_name: "bool_comparison" │ │
//! │ │ - applicability: MachineApplicable │ │
//! │ │ - suggestion_span: ByteRange │ │
//! │ │ - replacement: String │ │
//! │ └─────────────────────────────────────────────────────┘ │
//! │ ↓ │
//! │ ┌─────────────────────────────────────────────────────┐ │
//! │ │ ClippyToMutation::convert() │ │
//! │ │ - Parse span to locate in PureFile │ │
//! │ │ - Generate appropriate Mutation │ │
//! │ └─────────────────────────────────────────────────────┘ │
//! │ ↓ │
//! │ Box<dyn Mutation> │
//! └─────────────────────────────────────────────────────────────┘
//! ```
//!
//! # Integration Modes
//!
//! ## Direct Mode
//! Apply Clippy's suggestion text directly (text-based replacement).
//! Fastest but less semantic understanding.
//!
//! ```rust,ignore
//! // Clippy provides: span=(10, 20), replacement="x"
//! // Direct mode: replace bytes 10..20 with "x"
//! ```
//!
//! ## Semantic Mode
//! Generate appropriate Mutation based on lint type (AST-level transformation).
//! More robust and composable with other mutations.
//!
//! ```rust,ignore
//! // Clippy reports: lint="bool_comparison"
//! // Semantic mode: generate BoolSimplifyMutation
//! ```
//!
//! ## Hybrid Mode (Recommended)
//! - MachineApplicable lints → Direct Mode (safe, fast)
//! - Other lints → Semantic Mode (needs human review)
//!
//! # Supported Lints
//!
//! ## Tier 1: High-frequency, MachineApplicable
//!
//! | Lint | Transformation | Idiom Mutation |
//! |------|----------------|----------------|
//! | `bool_comparison` | `x == true` → `x` | [`BoolSimplifyMutation`] |
//! | `collapsible_if` | `if a { if b { } }` → `if a && b { }` | [`CollapsibleIfMutation`] |
//! | `comparison_to_empty` | `s == ""` → `s.is_empty()` | [`ComparisonToMethodMutation`] |
//! | `assign_op_pattern` | `a = a + b` → `a += b` | [`AssignOpMutation`] |
//! | `clone_on_copy` | Remove `.clone()` on Copy types | [`CloneOnCopyMutation`] |
//! | `redundant_closure` | `\|x\| foo(x)` → `foo` | [`RedundantClosureMutation`] |
//!
//! ## Tier 2: Iterator Chain Optimization
//!
//! | Lint | Transformation | Idiom Mutation |
//! |------|----------------|----------------|
//! | `map_clone` | `.map(\|x\| x.clone())` → `.cloned()` | [`MapClonedMutation`] |
//! | `iter_cloned_collect` | `.iter().cloned().collect()` → `.to_vec()` | [`IterClonedCollectMutation`] |
//! | `bind_instead_of_map` | `.and_then(\|x\| Some(y))` → `.map(\|x\| y)` | [`BindToMapMutation`] |
//! | `option_map_unwrap_or` | `.map(f).unwrap_or(d)` → `.map_or(d, f)` | [`MapUnwrapOrMutation`] |
//! | `manual_filter_map` | `.filter(p).map(f)` → `.filter_map(...)` | [`ManualFilterMapMutation`] |
//!
//! ## Tier 3: Manual Pattern Detection
//!
//! | Lint | Transformation | Idiom Mutation |
//! |------|----------------|----------------|
//! | `manual_map` | `match opt { Some(x) => Some(f(x)), None => None }` → `opt.map(f)` | [`ManualMapMutation`] |
//! | `manual_unwrap_or` | `match opt { Some(x) => x, None => default }` → `opt.unwrap_or(default)` | (planned) |
//!
//! # CLI Usage (Planned)
//!
//! ```bash
//! # Apply all MachineApplicable Clippy fixes
//! ryo fix --clippy
//!
//! # Apply specific lint category
//! ryo fix --clippy --category idiom
//! ryo fix --clippy --category perf
//!
//! # Apply specific lint
//! ryo fix --lint bool_comparison
//!
//! # Dry-run (preview changes)
//! ryo fix --clippy --dry-run
//!
//! # Interactive mode (select which fixes to apply)
//! ryo fix --clippy --interactive
//! ```
//!
//! # Example: Programmatic Usage
//!
//! ```rust,ignore
//! use ryo_mutations::clippy::{ClippyRunner, ClippyConfig};
//!
//! // Run clippy and collect diagnostics
//! let config = ClippyConfig::default()
//! .with_category(LintCategory::Idiom)
//! .machine_applicable_only();
//!
//! let runner = ClippyRunner::new(config);
//! let diagnostics = runner.run(".")?;
//!
//! // Convert to mutations
//! for diag in diagnostics {
//! if let Some(mutation) = diag.to_mutation() {
//! println!("Would apply: {}", mutation.describe());
//! }
//! }
//! ```
//!
//! # Relationship with rust-analyzer
//!
//! While Clippy focuses on linting and suggestions, rust-analyzer provides
//! code actions (assists) for refactoring. Some transformations overlap:
//!
//! | Transformation | Clippy | rust-analyzer |
//! |----------------|--------|---------------|
//! | `if let` ↔ `match` | `single_match` | `replace_if_let_with_match` |
//! | `unwrap` → `?` | `unwrap_used` | (n/a) |
//! | Iterator patterns | Various | `convert_iter_for_each_to_for` |
//!
//! The Idiom mutations in [`crate::idiom`] can be invoked directly
//! without running Clippy, enabling use in automated pipelines or editors
//! without external tool dependencies.
//!
//! # Future Extensions
//!
//! - [ ] Parse `cargo clippy --message-format=json` output
//! - [ ] Batch application with conflict detection
//! - [ ] Integration with workspace-wide refactoring
//! - [ ] Custom lint rule to Mutation mapping
pub use ;
pub use ;
/// Lint names for direct reference