fob_gen/
format.rs

1//! Code formatting options for generated JavaScript
2
3/// Quote style for string literals
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5pub enum QuoteStyle {
6    /// Single quotes: `'hello'`
7    Single,
8    /// Double quotes: `"hello"`
9    #[default]
10    Double,
11}
12
13/// Indentation style
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15pub enum IndentStyle {
16    /// Tabs
17    Tabs,
18    /// Spaces with specified width
19    Spaces(u8),
20}
21
22impl Default for IndentStyle {
23    fn default() -> Self {
24        IndentStyle::Spaces(2)
25    }
26}
27
28/// Formatting options for code generation
29#[derive(Debug, Clone)]
30pub struct FormatOptions {
31    /// Use semicolons at end of statements
32    pub use_semicolons: bool,
33    /// Quote style for string literals
34    pub quote_style: QuoteStyle,
35    /// Indentation style
36    pub indent: IndentStyle,
37    /// Add trailing commas in arrays/objects
38    pub trailing_commas: bool,
39    /// Line width for formatting (0 = no limit)
40    pub line_width: usize,
41}
42
43impl Default for FormatOptions {
44    fn default() -> Self {
45        Self {
46            use_semicolons: true,
47            quote_style: QuoteStyle::default(),
48            indent: IndentStyle::default(),
49            trailing_commas: false,
50            line_width: 80,
51        }
52    }
53}
54
55impl FormatOptions {
56    /// Create formatting options matching fob-cli output expectations
57    pub fn fob_default() -> Self {
58        Self::default()
59    }
60
61    /// Create formatting options for minified output
62    pub fn minified() -> Self {
63        Self {
64            use_semicolons: true,
65            quote_style: QuoteStyle::Double,
66            indent: IndentStyle::Spaces(0),
67            trailing_commas: false,
68            line_width: 0,
69        }
70    }
71}