mod indent;
mod max_line_length;
mod newline;
pub use indent::Indent;
pub use max_line_length::MaxLineLength;
pub use newline::NewlineStyle;
use schemars::JsonSchema;
use toml_spanner::Toml;
use toml_spanner::helper::display;
use toml_spanner::helper::parse_string;
fn sort_imports_default() -> bool {
true
}
fn sort_inputs_default() -> bool {
false
}
fn trailing_commas_default() -> bool {
true
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Toml, JsonSchema)]
#[toml(Toml, deny_unknown_fields)]
pub struct Config {
#[toml(default)]
#[schemars(default)]
pub indent: Indent,
#[toml(default)]
#[schemars(default)]
pub max_line_length: MaxLineLength,
#[toml(default = sort_imports_default())]
#[schemars(default = "sort_imports_default")]
pub sort_imports: bool,
#[toml(default = sort_inputs_default())]
#[schemars(default = "sort_inputs_default")]
pub sort_inputs: bool,
#[toml(default = trailing_commas_default())]
#[schemars(default = "trailing_commas_default")]
pub trailing_commas: bool,
#[toml(default, FromToml with = parse_string, ToToml with = display)]
#[schemars(default)]
pub newline_style: NewlineStyle,
}
impl Default for Config {
fn default() -> Self {
Self {
indent: Indent::default(),
max_line_length: MaxLineLength::default(),
sort_imports: sort_imports_default(),
sort_inputs: sort_inputs_default(),
trailing_commas: trailing_commas_default(),
newline_style: NewlineStyle::default(),
}
}
}
impl Config {
pub fn indent(mut self, indent: Indent) -> Self {
self.indent = indent;
self
}
pub fn newline_style(mut self, newline_style: NewlineStyle) -> Self {
self.newline_style = newline_style;
self
}
pub fn max_line_length(mut self, max_line_length: MaxLineLength) -> Self {
self.max_line_length = max_line_length;
self
}
pub fn sort_imports(mut self, sort_imports: bool) -> Self {
self.sort_imports = sort_imports;
self
}
pub fn sort_inputs(mut self, sort_inputs: bool) -> Self {
self.sort_inputs = sort_inputs;
self
}
pub fn trailing_commas(mut self, trailing_commas: bool) -> Self {
self.trailing_commas = trailing_commas;
self
}
}