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 bracket_spacing: bool,
14 pub int_types: IntTypes,
16 pub multiline_func_header: MultilineFuncHeaderStyle,
18 pub quote_style: QuoteStyle,
20 pub number_underscore: NumberUnderscore,
22 pub hex_underscore: HexUnderscore,
24 pub single_line_statement_blocks: SingleLineBlockStyle,
26 pub override_spacing: bool,
28 pub wrap_comments: bool,
30 pub ignore: Vec<String>,
32 pub contract_new_lines: bool,
34 pub sort_imports: bool,
36}
37
38#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
40#[serde(rename_all = "snake_case")]
41pub enum IntTypes {
42 Long,
44 Short,
46 Preserve,
48}
49
50#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
52#[serde(rename_all = "snake_case")]
53pub enum NumberUnderscore {
54 Preserve,
56 #[default]
58 Remove,
59 Thousands,
62}
63
64impl NumberUnderscore {
65 #[inline]
67 pub fn is_preserve(self) -> bool {
68 matches!(self, Self::Preserve)
69 }
70
71 #[inline]
73 pub fn is_remove(self) -> bool {
74 matches!(self, Self::Remove)
75 }
76
77 #[inline]
79 pub fn is_thousands(self) -> bool {
80 matches!(self, Self::Thousands)
81 }
82}
83
84#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
86#[serde(rename_all = "snake_case")]
87pub enum HexUnderscore {
88 Preserve,
90 #[default]
92 Remove,
93 Bytes,
95}
96
97impl HexUnderscore {
98 #[inline]
100 pub fn is_preserve(self) -> bool {
101 matches!(self, Self::Preserve)
102 }
103
104 #[inline]
106 pub fn is_remove(self) -> bool {
107 matches!(self, Self::Remove)
108 }
109
110 #[inline]
112 pub fn is_bytes(self) -> bool {
113 matches!(self, Self::Bytes)
114 }
115}
116
117#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
119#[serde(rename_all = "snake_case")]
120pub enum QuoteStyle {
121 Double,
123 Single,
125 Preserve,
127}
128
129impl QuoteStyle {
130 pub fn quote(self) -> Option<char> {
132 match self {
133 Self::Double => Some('"'),
134 Self::Single => Some('\''),
135 Self::Preserve => None,
136 }
137 }
138}
139
140#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
142#[serde(rename_all = "snake_case")]
143pub enum SingleLineBlockStyle {
144 Single,
146 Multi,
148 Preserve,
150}
151
152#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
154#[serde(rename_all = "snake_case")]
155pub enum MultilineFuncHeaderStyle {
156 ParamsFirst,
158 ParamsFirstMulti,
160 AttributesFirst,
162 All,
165 AllParams,
167}
168
169impl Default for FormatterConfig {
170 fn default() -> Self {
171 Self {
172 line_length: 120,
173 tab_width: 4,
174 bracket_spacing: false,
175 int_types: IntTypes::Long,
176 multiline_func_header: MultilineFuncHeaderStyle::AttributesFirst,
177 quote_style: QuoteStyle::Double,
178 number_underscore: NumberUnderscore::Preserve,
179 hex_underscore: HexUnderscore::Remove,
180 single_line_statement_blocks: SingleLineBlockStyle::Preserve,
181 override_spacing: false,
182 wrap_comments: false,
183 ignore: vec![],
184 contract_new_lines: false,
185 sort_imports: false,
186 }
187 }
188}