1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct FormatterConfig {
9 pub max_line_length: usize,
11 pub indentation: IndentationConfig,
13 pub spacing: SpacingConfig,
15 pub alignment: AlignmentConfig,
17 pub comments: CommentConfig,
19 pub organization: OrganizationConfig,
21 pub optimization: OptimizationConfig,
23 pub style_enforcement: StyleEnforcementConfig,
25 pub scirs2_analysis: SciRS2AnalysisConfig,
27 pub auto_correction: AutoCorrectionConfig,
29}
30
31impl Default for FormatterConfig {
32 fn default() -> Self {
33 Self {
34 max_line_length: 100,
35 indentation: IndentationConfig::default(),
36 spacing: SpacingConfig::default(),
37 alignment: AlignmentConfig::default(),
38 comments: CommentConfig::default(),
39 organization: OrganizationConfig::default(),
40 optimization: OptimizationConfig::default(),
41 style_enforcement: StyleEnforcementConfig::default(),
42 scirs2_analysis: SciRS2AnalysisConfig::default(),
43 auto_correction: AutoCorrectionConfig::default(),
44 }
45 }
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct IndentationConfig {
51 pub style: IndentationStyle,
52 pub spaces_per_level: usize,
53 pub tab_size: usize,
54 pub continuation_indent: usize,
55 pub align_closing_brackets: bool,
56}
57
58impl Default for IndentationConfig {
59 fn default() -> Self {
60 Self {
61 style: IndentationStyle::Spaces,
62 spaces_per_level: 4,
63 tab_size: 4,
64 continuation_indent: 4,
65 align_closing_brackets: true,
66 }
67 }
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
72pub enum IndentationStyle {
73 Spaces,
74 Tabs,
75 Smart,
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct SpacingConfig {
81 pub around_operators: bool,
82 pub after_commas: bool,
83 pub around_parentheses: SpacingStyle,
84 pub around_brackets: SpacingStyle,
85 pub around_braces: SpacingStyle,
86 pub before_function_calls: bool,
87 pub in_empty_parentheses: bool,
88 pub blank_lines_between_sections: usize,
89 pub blank_lines_around_classes: usize,
90}
91
92impl Default for SpacingConfig {
93 fn default() -> Self {
94 Self {
95 around_operators: true,
96 after_commas: true,
97 around_parentheses: SpacingStyle::Outside,
98 around_brackets: SpacingStyle::None,
99 around_braces: SpacingStyle::Inside,
100 before_function_calls: false,
101 in_empty_parentheses: false,
102 blank_lines_between_sections: 2,
103 blank_lines_around_classes: 2,
104 }
105 }
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize)]
110pub enum SpacingStyle {
111 None,
112 Inside,
113 Outside,
114 Both,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct AlignmentConfig {
120 pub align_gate_parameters: bool,
121 pub align_comments: bool,
122 pub align_variable_declarations: bool,
123 pub align_circuit_definitions: bool,
124 pub column_alignment_threshold: usize,
125 pub max_alignment_columns: usize,
126}
127
128impl Default for AlignmentConfig {
129 fn default() -> Self {
130 Self {
131 align_gate_parameters: true,
132 align_comments: true,
133 align_variable_declarations: true,
134 align_circuit_definitions: true,
135 column_alignment_threshold: 3,
136 max_alignment_columns: 10,
137 }
138 }
139}
140
141#[derive(Debug, Clone, Serialize, Deserialize)]
143pub struct CommentConfig {
144 pub format_block_comments: bool,
145 pub format_inline_comments: bool,
146 pub comment_line_length: usize,
147 pub comment_alignment: CommentAlignment,
148 pub preserve_formatting: bool,
149 pub auto_generate_comments: bool,
150 pub target_comment_density: f64,
151}
152
153impl Default for CommentConfig {
154 fn default() -> Self {
155 Self {
156 format_block_comments: true,
157 format_inline_comments: true,
158 comment_line_length: 80,
159 comment_alignment: CommentAlignment::Left,
160 preserve_formatting: false,
161 auto_generate_comments: false,
162 target_comment_density: 0.2,
163 }
164 }
165}
166
167#[derive(Debug, Clone, Serialize, Deserialize)]
169pub enum CommentAlignment {
170 Left,
171 Right,
172 Center,
173 Column,
174}
175
176#[derive(Debug, Clone, Serialize, Deserialize)]
178pub struct OrganizationConfig {
179 pub group_related_gates: bool,
180 pub sort_imports: bool,
181 pub organize_functions: bool,
182 pub grouping_strategy: GroupingStrategy,
183 pub section_ordering: Vec<String>,
184 pub enforce_section_separation: bool,
185}
186
187impl Default for OrganizationConfig {
188 fn default() -> Self {
189 Self {
190 group_related_gates: true,
191 sort_imports: true,
192 organize_functions: true,
193 grouping_strategy: GroupingStrategy::Logical,
194 section_ordering: vec![
195 "imports".to_string(),
196 "constants".to_string(),
197 "variables".to_string(),
198 "gates".to_string(),
199 "measurements".to_string(),
200 ],
201 enforce_section_separation: true,
202 }
203 }
204}
205
206#[derive(Debug, Clone, Serialize, Deserialize)]
208pub enum GroupingStrategy {
209 Logical,
210 ByQubit,
211 ByGateType,
212 ByDepth,
213 None,
214}
215
216#[derive(Debug, Clone, Serialize, Deserialize)]
218pub struct OptimizationConfig {
219 pub optimize_line_breaks: bool,
220 pub optimize_whitespace: bool,
221 pub minimize_changes: bool,
222 pub preserve_structure: bool,
223}
224
225impl Default for OptimizationConfig {
226 fn default() -> Self {
227 Self {
228 optimize_line_breaks: true,
229 optimize_whitespace: true,
230 minimize_changes: false,
231 preserve_structure: true,
232 }
233 }
234}
235
236#[derive(Debug, Clone, Serialize, Deserialize)]
238pub struct StyleEnforcementConfig {
239 pub enforce_naming_conventions: bool,
240 pub enforce_spacing_rules: bool,
241 pub enforce_alignment_rules: bool,
242 pub severity_level: SeverityLevel,
243}
244
245impl Default for StyleEnforcementConfig {
246 fn default() -> Self {
247 Self {
248 enforce_naming_conventions: true,
249 enforce_spacing_rules: true,
250 enforce_alignment_rules: true,
251 severity_level: SeverityLevel::Warning,
252 }
253 }
254}
255
256#[derive(Debug, Clone, Serialize, Deserialize)]
258pub enum SeverityLevel {
259 Info,
260 Warning,
261 Error,
262}
263
264#[derive(Debug, Clone, Serialize, Deserialize)]
266pub struct SciRS2AnalysisConfig {
267 pub enable_graph_analysis: bool,
268 pub enable_pattern_recognition: bool,
269 pub analysis_depth: usize,
270}
271
272impl Default for SciRS2AnalysisConfig {
273 fn default() -> Self {
274 Self {
275 enable_graph_analysis: true,
276 enable_pattern_recognition: true,
277 analysis_depth: 3,
278 }
279 }
280}
281
282#[derive(Debug, Clone, Serialize, Deserialize)]
284pub struct AutoCorrectionConfig {
285 pub auto_fix_indentation: bool,
286 pub auto_fix_spacing: bool,
287 pub auto_fix_alignment: bool,
288 pub suggest_improvements: bool,
289}
290
291impl Default for AutoCorrectionConfig {
292 fn default() -> Self {
293 Self {
294 auto_fix_indentation: true,
295 auto_fix_spacing: true,
296 auto_fix_alignment: true,
297 suggest_improvements: true,
298 }
299 }
300}