#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FormatConfig {
pub max_width: usize,
pub indent_width: usize,
pub use_tabs: bool,
pub trailing_comma: TrailingComma,
pub newline: NewlineStyle,
}
impl Default for FormatConfig {
fn default() -> Self {
Self {
max_width: 100,
indent_width: 2,
use_tabs: false,
trailing_comma: TrailingComma::Always,
newline: NewlineStyle::Lf,
}
}
}
impl FormatConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_max_width(mut self, width: usize) -> Self {
self.max_width = width;
self
}
pub fn with_indent_width(mut self, width: usize) -> Self {
self.indent_width = width;
self
}
pub fn with_tabs(mut self, use_tabs: bool) -> Self {
self.use_tabs = use_tabs;
self
}
pub fn with_trailing_comma(mut self, policy: TrailingComma) -> Self {
self.trailing_comma = policy;
self
}
pub fn with_newline(mut self, style: NewlineStyle) -> Self {
self.newline = style;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TrailingComma {
#[default]
Always,
Never,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum NewlineStyle {
#[default]
Lf,
Crlf,
}
impl NewlineStyle {
pub fn as_str(self) -> &'static str {
match self {
NewlineStyle::Lf => "\n",
NewlineStyle::Crlf => "\r\n",
}
}
}