1use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
7pub struct FormatterConfig {
8 pub line_length: usize,
10 pub tab_width: usize,
12 pub style: IndentStyle,
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, Self::Preserve)
71 }
72
73 #[inline]
75 pub fn is_remove(self) -> bool {
76 matches!(self, Self::Remove)
77 }
78
79 #[inline]
81 pub fn is_thousands(self) -> bool {
82 matches!(self, Self::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, Self::Preserve)
104 }
105
106 #[inline]
108 pub fn is_remove(self) -> bool {
109 matches!(self, Self::Remove)
110 }
111
112 #[inline]
114 pub fn is_bytes(self) -> bool {
115 matches!(self, Self::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 Self::Double => Some('"'),
136 Self::Single => Some('\''),
137 Self::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 ParamsFirstMulti,
162 AttributesFirst,
164 All,
167 AllParams,
169}
170
171#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
173#[serde(rename_all = "snake_case")]
174pub enum IndentStyle {
175 #[default]
176 Space,
177 Tab,
178}
179
180impl Default for FormatterConfig {
181 fn default() -> Self {
182 Self {
183 line_length: 120,
184 tab_width: 4,
185 style: IndentStyle::Space,
186 bracket_spacing: false,
187 int_types: IntTypes::Long,
188 multiline_func_header: MultilineFuncHeaderStyle::AttributesFirst,
189 quote_style: QuoteStyle::Double,
190 number_underscore: NumberUnderscore::Preserve,
191 hex_underscore: HexUnderscore::Remove,
192 single_line_statement_blocks: SingleLineBlockStyle::Preserve,
193 override_spacing: false,
194 wrap_comments: false,
195 ignore: vec![],
196 contract_new_lines: false,
197 sort_imports: false,
198 }
199 }
200}