1use serde::{Deserialize, Serialize};
6
7#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
9pub struct FormatterConfig {
10 pub line_length: usize,
12 pub tab_width: usize,
14 pub bracket_spacing: bool,
16 pub int_types: IntTypes,
18 pub multiline_func_header: MultilineFuncHeaderStyle,
20 pub quote_style: QuoteStyle,
22 pub number_underscore: NumberUnderscore,
24 pub hex_underscore: HexUnderscore,
26 pub single_line_statement_blocks: SingleLineBlockStyle,
28 pub override_spacing: bool,
30 pub wrap_comments: bool,
32 pub ignore: Vec<String>,
34 pub contract_new_lines: bool,
36 pub sort_imports: bool,
38}
39
40#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
42#[serde(rename_all = "snake_case")]
43pub enum IntTypes {
44 Long,
46 Short,
48 Preserve,
50}
51
52#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
54#[serde(rename_all = "snake_case")]
55pub enum NumberUnderscore {
56 Preserve,
58 #[default]
60 Remove,
61 Thousands,
64}
65
66impl NumberUnderscore {
67 #[inline]
69 pub fn is_preserve(self) -> bool {
70 matches!(self, NumberUnderscore::Preserve)
71 }
72
73 #[inline]
75 pub fn is_remove(self) -> bool {
76 matches!(self, NumberUnderscore::Remove)
77 }
78
79 #[inline]
81 pub fn is_thousands(self) -> bool {
82 matches!(self, NumberUnderscore::Thousands)
83 }
84}
85
86#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
88#[serde(rename_all = "snake_case")]
89pub enum HexUnderscore {
90 Preserve,
92 #[default]
94 Remove,
95 Bytes,
97}
98
99impl HexUnderscore {
100 #[inline]
102 pub fn is_preserve(self) -> bool {
103 matches!(self, HexUnderscore::Preserve)
104 }
105
106 #[inline]
108 pub fn is_remove(self) -> bool {
109 matches!(self, HexUnderscore::Remove)
110 }
111
112 #[inline]
114 pub fn is_bytes(self) -> bool {
115 matches!(self, HexUnderscore::Bytes)
116 }
117}
118
119#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
121#[serde(rename_all = "snake_case")]
122pub enum QuoteStyle {
123 Double,
125 Single,
127 Preserve,
129}
130
131impl QuoteStyle {
132 pub fn quote(self) -> Option<char> {
134 match self {
135 QuoteStyle::Double => Some('"'),
136 QuoteStyle::Single => Some('\''),
137 QuoteStyle::Preserve => None,
138 }
139 }
140}
141
142#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
144#[serde(rename_all = "snake_case")]
145pub enum SingleLineBlockStyle {
146 Single,
148 Multi,
150 Preserve,
152}
153
154#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
156#[serde(rename_all = "snake_case")]
157pub enum MultilineFuncHeaderStyle {
158 ParamsFirst,
160 AttributesFirst,
162 All,
165}
166
167impl Default for FormatterConfig {
168 fn default() -> Self {
169 FormatterConfig {
170 line_length: 120,
171 tab_width: 4,
172 bracket_spacing: false,
173 int_types: IntTypes::Long,
174 multiline_func_header: MultilineFuncHeaderStyle::AttributesFirst,
175 quote_style: QuoteStyle::Double,
176 number_underscore: NumberUnderscore::Preserve,
177 hex_underscore: HexUnderscore::Remove,
178 single_line_statement_blocks: SingleLineBlockStyle::Preserve,
179 override_spacing: false,
180 wrap_comments: false,
181 ignore: vec![],
182 contract_new_lines: false,
183 sort_imports: false,
184 }
185 }
186}