use super::resolve_config::resolve_config;
use super::types::*;
use dprint_core::configuration::*;
#[derive(Default)]
pub struct ConfigurationBuilder {
pub(super) config: ConfigKeyMap,
global_config: Option<GlobalConfiguration>,
}
impl ConfigurationBuilder {
pub fn new() -> ConfigurationBuilder {
ConfigurationBuilder::default()
}
pub fn build(&self) -> Configuration {
if let Some(global_config) = &self.global_config {
resolve_config(self.config.clone(), global_config).config
} else {
let global_config = GlobalConfiguration::default();
resolve_config(self.config.clone(), &global_config).config
}
}
pub fn global_config(&mut self, global_config: GlobalConfiguration) -> &mut Self {
self.global_config = Some(global_config);
self
}
pub fn deno(&mut self) -> &mut Self {
self
.line_width(80)
.indent_width(2)
.next_control_flow_position(NextControlFlowPosition::SameLine)
.binary_expression_operator_position(OperatorPosition::SameLine)
.conditional_expression_operator_position(OperatorPosition::NextLine)
.conditional_type_operator_position(OperatorPosition::NextLine)
.brace_position(BracePosition::SameLine)
.comment_line_force_space_after_slashes(false)
.construct_signature_space_after_new_keyword(true)
.constructor_type_space_after_new_keyword(true)
.arrow_function_use_parentheses(UseParentheses::Force)
.new_line_kind(NewLineKind::LineFeed)
.function_expression_space_after_function_keyword(true)
.tagged_template_space_before_literal(false)
.conditional_expression_prefer_single_line(true)
.quote_style(QuoteStyle::PreferDouble)
.jsx_multi_line_parens(JsxMultiLineParens::Prefer)
.ignore_node_comment_text("deno-fmt-ignore")
.ignore_file_comment_text("deno-fmt-ignore-file")
.module_sort_import_declarations(SortOrder::Maintain)
.module_sort_export_declarations(SortOrder::Maintain)
.export_declaration_sort_type_only_exports(NamedTypeImportsExportsOrder::None)
.import_declaration_sort_type_only_imports(NamedTypeImportsExportsOrder::None)
}
pub fn line_width(&mut self, value: u32) -> &mut Self {
self.insert("lineWidth", (value as i32).into())
}
pub fn use_tabs(&mut self, value: bool) -> &mut Self {
self.insert("useTabs", value.into())
}
pub fn indent_width(&mut self, value: u8) -> &mut Self {
self.insert("indentWidth", (value as i32).into())
}
pub fn new_line_kind(&mut self, value: NewLineKind) -> &mut Self {
self.insert("newLineKind", value.to_string().into())
}
pub fn quote_style(&mut self, value: QuoteStyle) -> &mut Self {
self.insert("quoteStyle", value.to_string().into())
}
pub fn jsx_quote_style(&mut self, value: JsxQuoteStyle) -> &mut Self {
self.insert("jsx.quoteStyle", value.to_string().into())
}
pub fn jsx_multi_line_parens(&mut self, value: JsxMultiLineParens) -> &mut Self {
self.insert("jsx.multiLineParens", value.to_string().into())
}
pub fn jsx_force_new_lines_surrounding_content(&mut self, value: bool) -> &mut Self {
self.insert("jsx.forceNewLinesSurroundingContent", value.into())
}
pub fn jsx_bracket_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
self.insert("jsx.bracketPosition", value.to_string().into())
}
pub fn jsx_opening_element_bracket_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
self.insert("jsxOpeningElement.bracketPosition", value.to_string().into())
}
pub fn jsx_self_closing_element_bracket_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
self.insert("jsxSelfClosingElement.bracketPosition", value.to_string().into())
}
pub fn semi_colons(&mut self, value: SemiColons) -> &mut Self {
self.insert("semiColons", value.to_string().into())
}
pub fn prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("preferHanging", value.into())
}
pub fn quote_props(&mut self, value: QuoteProps) -> &mut Self {
self.insert("quoteProps", value.to_string().into())
}
pub fn brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("bracePosition", value.to_string().into())
}
pub fn next_control_flow_position(&mut self, value: NextControlFlowPosition) -> &mut Self {
self.insert("nextControlFlowPosition", value.to_string().into())
}
pub fn operator_position(&mut self, value: OperatorPosition) -> &mut Self {
self.insert("operatorPosition", value.to_string().into())
}
pub fn single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
self.insert("singleBodyPosition", value.to_string().into())
}
pub fn trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("trailingCommas", value.to_string().into())
}
pub fn use_braces(&mut self, value: UseBraces) -> &mut Self {
self.insert("useBraces", value.to_string().into())
}
pub fn prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("preferSingleLine", value.into())
}
pub fn binary_expression_space_surrounding_bitwise_and_arithmetic_operator(&mut self, value: bool) -> &mut Self {
self.insert("binaryExpression.spaceSurroundingBitwiseAndArithmeticOperator", value.into())
}
pub fn comment_line_force_space_after_slashes(&mut self, value: bool) -> &mut Self {
self.insert("commentLine.forceSpaceAfterSlashes", value.into())
}
pub fn construct_signature_space_after_new_keyword(&mut self, value: bool) -> &mut Self {
self.insert("constructSignature.spaceAfterNewKeyword", value.into())
}
pub fn constructor_space_before_parentheses(&mut self, value: bool) -> &mut Self {
self.insert("constructor.spaceBeforeParentheses", value.into())
}
pub fn constructor_type_space_after_new_keyword(&mut self, value: bool) -> &mut Self {
self.insert("constructorType.spaceAfterNewKeyword", value.into())
}
pub fn do_while_statement_space_after_while_keyword(&mut self, value: bool) -> &mut Self {
self.insert("doWhileStatement.spaceAfterWhileKeyword", value.into())
}
pub fn export_declaration_space_surrounding_named_exports(&mut self, value: bool) -> &mut Self {
self.insert("exportDeclaration.spaceSurroundingNamedExports", value.into())
}
pub fn for_statement_space_after_for_keyword(&mut self, value: bool) -> &mut Self {
self.insert("forStatement.spaceAfterForKeyword", value.into())
}
pub fn for_statement_space_after_semi_colons(&mut self, value: bool) -> &mut Self {
self.insert("forStatement.spaceAfterSemiColons", value.into())
}
pub fn for_in_statement_space_after_for_keyword(&mut self, value: bool) -> &mut Self {
self.insert("forInStatement.spaceAfterForKeyword", value.into())
}
pub fn for_of_statement_space_after_for_keyword(&mut self, value: bool) -> &mut Self {
self.insert("forOfStatement.spaceAfterForKeyword", value.into())
}
pub fn function_declaration_space_before_parentheses(&mut self, value: bool) -> &mut Self {
self.insert("functionDeclaration.spaceBeforeParentheses", value.into())
}
pub fn function_expression_space_before_parentheses(&mut self, value: bool) -> &mut Self {
self.insert("functionExpression.spaceBeforeParentheses", value.into())
}
pub fn function_expression_space_after_function_keyword(&mut self, value: bool) -> &mut Self {
self.insert("functionExpression.spaceAfterFunctionKeyword", value.into())
}
pub fn get_accessor_space_before_parentheses(&mut self, value: bool) -> &mut Self {
self.insert("getAccessor.spaceBeforeParentheses", value.into())
}
pub fn if_statement_space_after_if_keyword(&mut self, value: bool) -> &mut Self {
self.insert("ifStatement.spaceAfterIfKeyword", value.into())
}
pub fn import_declaration_space_surrounding_named_imports(&mut self, value: bool) -> &mut Self {
self.insert("importDeclaration.spaceSurroundingNamedImports", value.into())
}
pub fn jsx_expression_container_space_surrounding_expression(&mut self, value: bool) -> &mut Self {
self.insert("jsxExpressionContainer.spaceSurroundingExpression", value.into())
}
pub fn jsx_self_closing_element_space_before_slash(&mut self, value: bool) -> &mut Self {
self.insert("jsxSelfClosingElement.spaceBeforeSlash", value.into())
}
pub fn object_expression_space_surrounding_properties(&mut self, value: bool) -> &mut Self {
self.insert("objectExpression.spaceSurroundingProperties", value.into())
}
pub fn object_pattern_space_surrounding_properties(&mut self, value: bool) -> &mut Self {
self.insert("objectPattern.spaceSurroundingProperties", value.into())
}
pub fn method_space_before_parentheses(&mut self, value: bool) -> &mut Self {
self.insert("method.spaceBeforeParentheses", value.into())
}
pub fn set_accessor_space_before_parentheses(&mut self, value: bool) -> &mut Self {
self.insert("setAccessor.spaceBeforeParentheses", value.into())
}
pub fn space_surrounding_properties(&mut self, value: bool) -> &mut Self {
self.insert("spaceSurroundingProperties", value.into())
}
pub fn tagged_template_space_before_literal(&mut self, value: bool) -> &mut Self {
self.insert("taggedTemplate.spaceBeforeLiteral", value.into())
}
pub fn type_annotation_space_before_colon(&mut self, value: bool) -> &mut Self {
self.insert("typeAnnotation.spaceBeforeColon", value.into())
}
pub fn type_assertion_space_before_expression(&mut self, value: bool) -> &mut Self {
self.insert("typeAssertion.spaceBeforeExpression", value.into())
}
pub fn type_literal_space_surrounding_properties(&mut self, value: bool) -> &mut Self {
self.insert("typeLiteral.spaceSurroundingProperties", value.into())
}
pub fn while_statement_space_after_while_keyword(&mut self, value: bool) -> &mut Self {
self.insert("whileStatement.spaceAfterWhileKeyword", value.into())
}
pub fn space_around(&mut self, value: bool) -> &mut Self {
self.insert("spaceAround", value.into())
}
pub fn arrow_function_use_parentheses(&mut self, value: UseParentheses) -> &mut Self {
self.insert("arrowFunction.useParentheses", value.to_string().into())
}
pub fn binary_expression_line_per_expression(&mut self, value: bool) -> &mut Self {
self.insert("binaryExpression.linePerExpression", value.into())
}
pub fn conditional_expression_line_per_expression(&mut self, value: bool) -> &mut Self {
self.insert("conditionalExpression.linePerExpression", value.into())
}
pub fn member_expression_line_per_expression(&mut self, value: bool) -> &mut Self {
self.insert("memberExpression.linePerExpression", value.into())
}
pub fn type_literal_separator_kind(&mut self, value: SemiColonOrComma) -> &mut Self {
self.insert("typeLiteral.separatorKind", value.to_string().into())
}
pub fn type_literal_separator_kind_single_line(&mut self, value: SemiColonOrComma) -> &mut Self {
self.insert("typeLiteral.separatorKind.singleLine", value.to_string().into())
}
pub fn type_literal_separator_kind_multi_line(&mut self, value: SemiColonOrComma) -> &mut Self {
self.insert("typeLiteral.separatorKind.multiLine", value.to_string().into())
}
pub fn module_sort_import_declarations(&mut self, value: SortOrder) -> &mut Self {
self.insert("module.sortImportDeclarations", value.to_string().into())
}
pub fn module_sort_export_declarations(&mut self, value: SortOrder) -> &mut Self {
self.insert("module.sortExportDeclarations", value.to_string().into())
}
pub fn import_declaration_sort_named_imports(&mut self, value: SortOrder) -> &mut Self {
self.insert("importDeclaration.sortNamedImports", value.to_string().into())
}
pub fn import_declaration_sort_type_only_imports(&mut self, value: NamedTypeImportsExportsOrder) -> &mut Self {
self.insert("importDeclaration.sortTypeOnlyImports", value.to_string().into())
}
pub fn export_declaration_sort_named_exports(&mut self, value: SortOrder) -> &mut Self {
self.insert("exportDeclaration.sortNamedExports", value.to_string().into())
}
pub fn export_declaration_sort_type_only_exports(&mut self, value: NamedTypeImportsExportsOrder) -> &mut Self {
self.insert("exportDeclaration.sortTypeOnlyExports", value.to_string().into())
}
pub fn ignore_node_comment_text(&mut self, value: &str) -> &mut Self {
self.insert("ignoreNodeCommentText", value.into())
}
pub fn ignore_file_comment_text(&mut self, value: &str) -> &mut Self {
self.insert("ignoreFileCommentText", value.into())
}
pub fn arrow_function_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("arrowFunction.bracePosition", value.to_string().into())
}
pub fn class_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("classDeclaration.bracePosition", value.to_string().into())
}
pub fn class_expression_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("classExpression.bracePosition", value.to_string().into())
}
pub fn constructor_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("constructor.bracePosition", value.to_string().into())
}
pub fn do_while_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("doWhileStatement.bracePosition", value.to_string().into())
}
pub fn enum_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("enumDeclaration.bracePosition", value.to_string().into())
}
pub fn for_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("forStatement.bracePosition", value.to_string().into())
}
pub fn for_in_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("forInStatement.bracePosition", value.to_string().into())
}
pub fn for_of_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("forOfStatement.bracePosition", value.to_string().into())
}
pub fn get_accessor_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("getAccessor.bracePosition", value.to_string().into())
}
pub fn if_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("ifStatement.bracePosition", value.to_string().into())
}
pub fn interface_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("interfaceDeclaration.bracePosition", value.to_string().into())
}
pub fn function_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("functionDeclaration.bracePosition", value.to_string().into())
}
pub fn function_expression_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("functionExpression.bracePosition", value.to_string().into())
}
pub fn method_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("method.bracePosition", value.to_string().into())
}
pub fn module_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("moduleDeclaration.bracePosition", value.to_string().into())
}
pub fn set_accessor_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("setAccessor.bracePosition", value.to_string().into())
}
pub fn static_block_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("staticBlock.bracePosition", value.to_string().into())
}
pub fn switch_case_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("switchCase.bracePosition", value.to_string().into())
}
pub fn switch_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("switchStatement.bracePosition", value.to_string().into())
}
pub fn try_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("tryStatement.bracePosition", value.to_string().into())
}
pub fn while_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
self.insert("whileStatement.bracePosition", value.to_string().into())
}
pub fn arguments_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
self.insert("arguments.preferHanging", value.to_string().into())
}
pub fn array_expression_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
self.insert("arrayExpression.preferHanging", value.to_string().into())
}
pub fn array_pattern_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("arrayPattern.preferHanging", value.into())
}
pub fn do_while_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("doWhileStatement.preferHanging", value.into())
}
pub fn export_declaration_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("exportDeclaration.preferHanging", value.into())
}
pub fn extends_clause_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("extendsClause.preferHanging", value.into())
}
pub fn for_in_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("forInStatement.preferHanging", value.into())
}
pub fn for_of_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("forOfStatement.preferHanging", value.into())
}
pub fn for_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("forStatement.preferHanging", value.into())
}
pub fn if_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("ifStatement.preferHanging", value.into())
}
pub fn implements_clause_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("implementsClause.preferHanging", value.into())
}
pub fn import_declaration_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("importDeclaration.preferHanging", value.into())
}
pub fn jsx_attributes_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("jsxAttributes.preferHanging", value.into())
}
pub fn object_expression_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("objectExpression.preferHanging", value.into())
}
pub fn object_pattern_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("objectPattern.preferHanging", value.into())
}
pub fn parameters_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
self.insert("parameters.preferHanging", value.to_string().into())
}
pub fn sequence_expression_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("sequenceExpression.preferHanging", value.into())
}
pub fn switch_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("switchStatement.preferHanging", value.into())
}
pub fn tuple_type_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
self.insert("tupleType.preferHanging", value.to_string().into())
}
pub fn type_literal_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("typeLiteral.preferHanging", value.into())
}
pub fn type_parameters_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
self.insert("typeParameters.preferHanging", value.to_string().into())
}
pub fn union_and_intersection_type_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("unionAndIntersectionType.preferHanging", value.into())
}
pub fn variable_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("variableStatement.preferHanging", value.into())
}
pub fn while_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
self.insert("whileStatement.preferHanging", value.into())
}
pub fn export_declaration_force_single_line(&mut self, value: bool) -> &mut Self {
self.insert("exportDeclaration.forceSingleLine", value.into())
}
pub fn import_declaration_force_single_line(&mut self, value: bool) -> &mut Self {
self.insert("importDeclaration.forceSingleLine", value.into())
}
pub fn export_declaration_force_multi_line(&mut self, value: ForceMultiLine) -> &mut Self {
self.insert("exportDeclaration.forceMultiLine", value.to_string().into())
}
pub fn import_declaration_force_multi_line(&mut self, value: ForceMultiLine) -> &mut Self {
self.insert("importDeclaration.forceMultiLine", value.to_string().into())
}
pub fn enum_declaration_member_spacing(&mut self, value: MemberSpacing) -> &mut Self {
self.insert("enumDeclaration.memberSpacing", value.to_string().into())
}
pub fn if_statement_next_control_flow_position(&mut self, value: NextControlFlowPosition) -> &mut Self {
self.insert("ifStatement.nextControlFlowPosition", value.to_string().into())
}
pub fn try_statement_next_control_flow_position(&mut self, value: NextControlFlowPosition) -> &mut Self {
self.insert("tryStatement.nextControlFlowPosition", value.to_string().into())
}
pub fn do_while_statement_next_control_flow_position(&mut self, value: NextControlFlowPosition) -> &mut Self {
self.insert("doWhileStatement.nextControlFlowPosition", value.to_string().into())
}
pub fn binary_expression_operator_position(&mut self, value: OperatorPosition) -> &mut Self {
self.insert("binaryExpression.operatorPosition", value.to_string().into())
}
pub fn conditional_expression_operator_position(&mut self, value: OperatorPosition) -> &mut Self {
self.insert("conditionalExpression.operatorPosition", value.to_string().into())
}
pub fn conditional_type_operator_position(&mut self, value: OperatorPosition) -> &mut Self {
self.insert("conditionalType.operatorPosition", value.to_string().into())
}
pub fn if_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
self.insert("ifStatement.singleBodyPosition", value.to_string().into())
}
pub fn for_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
self.insert("forStatement.singleBodyPosition", value.to_string().into())
}
pub fn for_in_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
self.insert("forInStatement.singleBodyPosition", value.to_string().into())
}
pub fn for_of_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
self.insert("forOfStatement.singleBodyPosition", value.to_string().into())
}
pub fn while_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
self.insert("whileStatement.singleBodyPosition", value.to_string().into())
}
pub fn arguments_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("arguments.trailingCommas", value.to_string().into())
}
pub fn parameters_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("parameters.trailingCommas", value.to_string().into())
}
pub fn array_expression_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("arrayExpression.trailingCommas", value.to_string().into())
}
pub fn array_pattern_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("arrayPattern.trailingCommas", value.to_string().into())
}
pub fn enum_declaration_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("enumDeclaration.trailingCommas", value.to_string().into())
}
pub fn export_declaration_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("exportDeclaration.trailingCommas", value.to_string().into())
}
pub fn import_declaration_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("importDeclaration.trailingCommas", value.to_string().into())
}
pub fn object_expression_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("objectExpression.trailingCommas", value.to_string().into())
}
pub fn object_pattern_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("objectPattern.trailingCommas", value.to_string().into())
}
pub fn tuple_type_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("tupleType.trailingCommas", value.to_string().into())
}
pub fn type_literal_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("typeLiteral.trailingCommas", value.to_string().into())
}
pub fn type_parameters_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
self.insert("typeParameters.trailingCommas", value.to_string().into())
}
pub fn if_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
self.insert("ifStatement.useBraces", value.to_string().into())
}
pub fn for_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
self.insert("forStatement.useBraces", value.to_string().into())
}
pub fn for_in_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
self.insert("forInStatement.useBraces", value.to_string().into())
}
pub fn for_of_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
self.insert("forOfStatement.useBraces", value.to_string().into())
}
pub fn while_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
self.insert("whileStatement.useBraces", value.to_string().into())
}
pub fn array_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("arrayExpression.preferSingleLine", value.into())
}
pub fn array_pattern_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("arrayPattern.preferSingleLine", value.into())
}
pub fn arguments_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("arguments.preferSingleLine", value.into())
}
pub fn binary_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("binaryExpression.preferSingleLine", value.into())
}
pub fn computed_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("computed.preferSingleLine", value.into())
}
pub fn conditional_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("conditionalExpression.preferSingleLine", value.into())
}
pub fn conditional_type_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("conditionalType.preferSingleLine", value.into())
}
pub fn decorators_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("decorators.preferSingleLine", value.into())
}
pub fn export_declaration_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("exportDeclaration.preferSingleLine", value.into())
}
pub fn for_statement_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("forStatement.preferSingleLine", value.into())
}
pub fn import_declaration_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("importDeclaration.preferSingleLine", value.into())
}
pub fn jsx_attributes_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("jsxAttributes.preferSingleLine", value.into())
}
pub fn jsx_element_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("jsxElement.preferSingleLine", value.into())
}
pub fn mapped_type_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("mappedType.preferSingleLine", value.into())
}
pub fn member_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("memberExpression.preferSingleLine", value.into())
}
pub fn object_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("objectExpression.preferSingleLine", value.into())
}
pub fn object_pattern_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("objectPattern.preferSingleLine", value.into())
}
pub fn parameters_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("parameters.preferSingleLine", value.into())
}
pub fn parentheses_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("parentheses.preferSingleLine", value.into())
}
pub fn tuple_type_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("tupleType.preferSingleLine", value.into())
}
pub fn type_literal_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("typeLiteral.preferSingleLine", value.into())
}
pub fn type_parameters_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("typeParameters.preferSingleLine", value.into())
}
pub fn union_and_intersection_type_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("unionAndIntersectionType.preferSingleLine", value.into())
}
pub fn variable_statement_prefer_single_line(&mut self, value: bool) -> &mut Self {
self.insert("variableStatement.preferSingleLine", value.into())
}
pub fn arguments_space_around(&mut self, value: bool) -> &mut Self {
self.insert("arguments.spaceAround", value.into())
}
pub fn array_expression_space_around(&mut self, value: bool) -> &mut Self {
self.insert("arrayExpression.spaceAround", value.into())
}
pub fn array_pattern_space_around(&mut self, value: bool) -> &mut Self {
self.insert("arrayPattern.spaceAround", value.into())
}
pub fn catch_clause_space_around(&mut self, value: bool) -> &mut Self {
self.insert("catchClause.spaceAround", value.into())
}
pub fn do_while_statement_space_around(&mut self, value: bool) -> &mut Self {
self.insert("doWhileStatement.spaceAround", value.into())
}
pub fn for_in_statement_space_around(&mut self, value: bool) -> &mut Self {
self.insert("forInStatement.spaceAround", value.into())
}
pub fn for_of_statement_space_around(&mut self, value: bool) -> &mut Self {
self.insert("forOfStatement.spaceAround", value.into())
}
pub fn for_statement_space_around(&mut self, value: bool) -> &mut Self {
self.insert("forStatement.spaceAround", value.into())
}
pub fn if_statement_space_around(&mut self, value: bool) -> &mut Self {
self.insert("ifStatement.spaceAround", value.into())
}
pub fn parameters_space_around(&mut self, value: bool) -> &mut Self {
self.insert("parameters.spaceAround", value.into())
}
pub fn paren_expression_space_around(&mut self, value: bool) -> &mut Self {
self.insert("parenExpression.spaceAround", value.into())
}
pub fn switch_statement_space_around(&mut self, value: bool) -> &mut Self {
self.insert("switchStatement.spaceAround", value.into())
}
pub fn tuple_type_space_around(&mut self, value: bool) -> &mut Self {
self.insert("tupleType.spaceAround", value.into())
}
pub fn while_statement_space_around(&mut self, value: bool) -> &mut Self {
self.insert("whileStatement.spaceAround", value.into())
}
#[cfg(test)]
pub(super) fn get_inner_config(&self) -> ConfigKeyMap {
self.config.clone()
}
fn insert(&mut self, name: &str, value: ConfigKeyValue) -> &mut Self {
self.config.insert(String::from(name), value);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn check_all_values_set() {
let mut config = ConfigurationBuilder::new();
config
.new_line_kind(NewLineKind::Auto)
.line_width(80)
.use_tabs(false)
.indent_width(4)
.quote_style(QuoteStyle::AlwaysDouble)
.jsx_quote_style(JsxQuoteStyle::PreferSingle)
.jsx_multi_line_parens(JsxMultiLineParens::Never)
.jsx_force_new_lines_surrounding_content(true)
.jsx_bracket_position(SameOrNextLinePosition::Maintain)
.jsx_opening_element_bracket_position(SameOrNextLinePosition::Maintain)
.jsx_self_closing_element_bracket_position(SameOrNextLinePosition::Maintain)
.semi_colons(SemiColons::Prefer)
.brace_position(BracePosition::NextLine)
.next_control_flow_position(NextControlFlowPosition::SameLine)
.operator_position(OperatorPosition::SameLine)
.single_body_position(SameOrNextLinePosition::SameLine)
.trailing_commas(TrailingCommas::Never)
.use_braces(UseBraces::WhenNotSingleLine)
.quote_props(QuoteProps::AsNeeded)
.prefer_hanging(false)
.arrow_function_use_parentheses(UseParentheses::Maintain)
.binary_expression_line_per_expression(false)
.conditional_expression_line_per_expression(true)
.member_expression_line_per_expression(false)
.type_literal_separator_kind(SemiColonOrComma::Comma)
.type_literal_separator_kind_single_line(SemiColonOrComma::Comma)
.type_literal_separator_kind_multi_line(SemiColonOrComma::Comma)
.module_sort_import_declarations(SortOrder::Maintain)
.module_sort_export_declarations(SortOrder::Maintain)
.import_declaration_sort_named_imports(SortOrder::Maintain)
.export_declaration_sort_named_exports(SortOrder::Maintain)
.import_declaration_sort_type_only_imports(NamedTypeImportsExportsOrder::First)
.export_declaration_sort_type_only_exports(NamedTypeImportsExportsOrder::None)
.ignore_node_comment_text("ignore")
.ignore_file_comment_text("ignore-file")
.arrow_function_brace_position(BracePosition::NextLine)
.class_declaration_brace_position(BracePosition::NextLine)
.class_expression_brace_position(BracePosition::NextLine)
.constructor_brace_position(BracePosition::NextLine)
.do_while_statement_brace_position(BracePosition::NextLine)
.enum_declaration_brace_position(BracePosition::NextLine)
.for_statement_brace_position(BracePosition::NextLine)
.for_in_statement_brace_position(BracePosition::NextLine)
.for_of_statement_brace_position(BracePosition::NextLine)
.get_accessor_brace_position(BracePosition::NextLine)
.if_statement_brace_position(BracePosition::NextLine)
.interface_declaration_brace_position(BracePosition::NextLine)
.function_declaration_brace_position(BracePosition::NextLine)
.function_expression_brace_position(BracePosition::NextLine)
.method_brace_position(BracePosition::NextLine)
.module_declaration_brace_position(BracePosition::NextLine)
.set_accessor_brace_position(BracePosition::NextLine)
.static_block_brace_position(BracePosition::NextLine)
.switch_case_brace_position(BracePosition::NextLine)
.switch_statement_brace_position(BracePosition::NextLine)
.try_statement_brace_position(BracePosition::NextLine)
.while_statement_brace_position(BracePosition::NextLine)
.arguments_prefer_hanging(PreferHanging::OnlySingleItem)
.array_expression_prefer_hanging(PreferHanging::OnlySingleItem)
.array_pattern_prefer_hanging(true)
.do_while_statement_prefer_hanging(true)
.export_declaration_prefer_hanging(true)
.extends_clause_prefer_hanging(true)
.for_in_statement_prefer_hanging(true)
.for_of_statement_prefer_hanging(true)
.for_statement_prefer_hanging(true)
.if_statement_prefer_hanging(true)
.implements_clause_prefer_hanging(true)
.import_declaration_prefer_hanging(true)
.jsx_attributes_prefer_hanging(true)
.object_expression_prefer_hanging(true)
.object_pattern_prefer_hanging(true)
.parameters_prefer_hanging(PreferHanging::OnlySingleItem)
.sequence_expression_prefer_hanging(true)
.switch_statement_prefer_hanging(true)
.tuple_type_prefer_hanging(PreferHanging::OnlySingleItem)
.type_literal_prefer_hanging(true)
.type_parameters_prefer_hanging(PreferHanging::OnlySingleItem)
.union_and_intersection_type_prefer_hanging(true)
.variable_statement_prefer_hanging(true)
.while_statement_prefer_hanging(true)
.enum_declaration_member_spacing(MemberSpacing::Maintain)
.if_statement_next_control_flow_position(NextControlFlowPosition::SameLine)
.try_statement_next_control_flow_position(NextControlFlowPosition::SameLine)
.do_while_statement_next_control_flow_position(NextControlFlowPosition::SameLine)
.binary_expression_operator_position(OperatorPosition::SameLine)
.conditional_expression_operator_position(OperatorPosition::SameLine)
.conditional_type_operator_position(OperatorPosition::SameLine)
.if_statement_single_body_position(SameOrNextLinePosition::SameLine)
.for_statement_single_body_position(SameOrNextLinePosition::SameLine)
.for_in_statement_single_body_position(SameOrNextLinePosition::SameLine)
.for_of_statement_single_body_position(SameOrNextLinePosition::SameLine)
.while_statement_single_body_position(SameOrNextLinePosition::SameLine)
.arguments_trailing_commas(TrailingCommas::Never)
.parameters_trailing_commas(TrailingCommas::Never)
.array_expression_trailing_commas(TrailingCommas::Never)
.array_pattern_trailing_commas(TrailingCommas::Never)
.enum_declaration_trailing_commas(TrailingCommas::Never)
.import_declaration_trailing_commas(TrailingCommas::Never)
.export_declaration_trailing_commas(TrailingCommas::Never)
.object_expression_trailing_commas(TrailingCommas::Never)
.object_pattern_trailing_commas(TrailingCommas::Never)
.type_parameters_trailing_commas(TrailingCommas::Never)
.tuple_type_trailing_commas(TrailingCommas::Never)
.type_literal_trailing_commas(TrailingCommas::Never)
.if_statement_use_braces(UseBraces::Always)
.for_statement_use_braces(UseBraces::Always)
.for_in_statement_use_braces(UseBraces::Always)
.for_of_statement_use_braces(UseBraces::Always)
.while_statement_use_braces(UseBraces::Always)
.array_expression_prefer_single_line(false)
.array_pattern_prefer_single_line(false)
.arguments_prefer_single_line(false)
.binary_expression_prefer_single_line(false)
.computed_prefer_single_line(false)
.conditional_expression_prefer_single_line(false)
.conditional_type_prefer_single_line(false)
.decorators_prefer_single_line(false)
.export_declaration_prefer_single_line(false)
.for_statement_prefer_single_line(false)
.import_declaration_prefer_single_line(false)
.jsx_attributes_prefer_single_line(false)
.jsx_element_prefer_single_line(false)
.mapped_type_prefer_single_line(false)
.member_expression_prefer_single_line(false)
.object_expression_prefer_single_line(false)
.object_pattern_prefer_single_line(false)
.parameters_prefer_single_line(false)
.parentheses_prefer_single_line(false)
.tuple_type_prefer_single_line(false)
.type_literal_prefer_single_line(false)
.type_parameters_prefer_single_line(false)
.union_and_intersection_type_prefer_single_line(false)
.variable_statement_prefer_single_line(false)
.export_declaration_force_single_line(true)
.import_declaration_force_single_line(true)
.export_declaration_force_multi_line(ForceMultiLine::Always)
.import_declaration_force_multi_line(ForceMultiLine::Always)
.binary_expression_space_surrounding_bitwise_and_arithmetic_operator(true)
.comment_line_force_space_after_slashes(false)
.construct_signature_space_after_new_keyword(true)
.constructor_space_before_parentheses(true)
.constructor_type_space_after_new_keyword(true)
.do_while_statement_space_after_while_keyword(true)
.export_declaration_space_surrounding_named_exports(true)
.for_statement_space_after_for_keyword(true)
.for_statement_space_after_semi_colons(true)
.for_in_statement_space_after_for_keyword(true)
.for_of_statement_space_after_for_keyword(true)
.function_declaration_space_before_parentheses(true)
.function_expression_space_before_parentheses(true)
.function_expression_space_after_function_keyword(true)
.get_accessor_space_before_parentheses(true)
.if_statement_space_after_if_keyword(true)
.import_declaration_space_surrounding_named_imports(true)
.jsx_expression_container_space_surrounding_expression(true)
.jsx_self_closing_element_space_before_slash(true)
.method_space_before_parentheses(true)
.object_expression_space_surrounding_properties(false)
.object_pattern_space_surrounding_properties(false)
.set_accessor_space_before_parentheses(true)
.space_surrounding_properties(false)
.tagged_template_space_before_literal(false)
.type_annotation_space_before_colon(true)
.type_assertion_space_before_expression(true)
.type_literal_space_surrounding_properties(false)
.while_statement_space_after_while_keyword(true)
.arguments_space_around(true)
.array_expression_space_around(true)
.array_pattern_space_around(true)
.catch_clause_space_around(true)
.do_while_statement_space_around(true)
.for_in_statement_space_around(true)
.for_of_statement_space_around(true)
.for_statement_space_around(true)
.if_statement_space_around(true)
.parameters_space_around(true)
.paren_expression_space_around(true)
.switch_statement_space_around(true)
.tuple_type_space_around(true)
.while_statement_space_around(true);
let inner_config = config.get_inner_config();
assert_eq!(inner_config.len(), 181);
let diagnostics = resolve_config(inner_config, &Default::default()).diagnostics;
assert_eq!(diagnostics.len(), 0);
}
}