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
185
186
187
188
189
190
191
192
193
194
//! Formatters for language-specific code generation output
//!
//! This module provides a trait-based system for formatting generated code in a way
//! that respects language-specific conventions and tooling requirements. Each language
//! binding (Python, TypeScript, Ruby, PHP) implements the `Formatter` trait to handle
//! header formatting, import organization, docstring styling, and section merging.
//!
//! # Design
//!
//! The `Formatter` trait abstracts away language-specific formatting rules while ensuring
//! consistent code generation across the entire spikard toolkit. Implementers handle:
//!
//! - **Headers**: Shebangs, auto-generation notices, module docstrings
//! - **Imports**: Dependency declarations, type imports, organization
//! - **Docstrings**: Language-specific documentation formatting (`NumPy`, `JSDoc`, etc.)
//! - **Merging**: Combining sections with proper spacing and deduplication
//!
//! # Example
//!
//! ```no_run
//! use spikard_cli::codegen::formatters::{Formatter, Import, HeaderMetadata, PythonFormatter, PhpFormatter, RustFormatter};
//!
//! let formatter = PythonFormatter::new();
//! let metadata = HeaderMetadata {
//! auto_generated: true,
//! schema_file: Some("schema.graphql".to_string()),
//! generator_version: Some("0.6.2".to_string()),
//! };
//!
//! let header = formatter.format_header(&metadata);
//! println!("{}", header);
//! ```
pub use PhpFormatter;
pub use PythonFormatter;
pub use RubyFormatter;
pub use RustFormatter;
pub use TypeScriptFormatter;
/// Metadata about a generated file used when formatting headers
/// Represents an import/require/use statement in any language
/// Represents a section of generated code to be merged
/// Core formatter trait for language-specific code generation output
///
/// Implement this trait to support a new target language. Each method should produce
/// formatted code that adheres to the language's conventions and integrates with its
/// standard tooling (linters, formatters, type checkers).
///
/// # Safety
///
/// Implementations must:
/// - Never panic (return errors via `Result` types where applicable)
/// - Escape special characters appropriately for the language
/// - Handle both empty and non-empty inputs gracefully
/// - Preserve code semantics when reformatting