1use super::resolve_config::resolve_config;
2use super::types::*;
3use dprint_core::configuration::*;
4
5#[derive(Default)]
21pub struct ConfigurationBuilder {
22 pub(super) config: ConfigKeyMap,
23 global_config: Option<GlobalConfiguration>,
24}
25
26impl ConfigurationBuilder {
27 pub fn new() -> ConfigurationBuilder {
29 ConfigurationBuilder::default()
30 }
31
32 pub fn build(&self) -> Configuration {
34 if let Some(global_config) = &self.global_config {
35 resolve_config(self.config.clone(), global_config).config
36 } else {
37 let global_config = GlobalConfiguration::default();
38 resolve_config(self.config.clone(), &global_config).config
39 }
40 }
41
42 pub fn global_config(&mut self, global_config: GlobalConfiguration) -> &mut Self {
44 self.global_config = Some(global_config);
45 self
46 }
47
48 pub fn deno(&mut self) -> &mut Self {
50 self
51 .line_width(80)
52 .indent_width(2)
53 .next_control_flow_position(NextControlFlowPosition::SameLine)
54 .binary_expression_operator_position(OperatorPosition::SameLine)
55 .conditional_expression_operator_position(OperatorPosition::NextLine)
56 .conditional_type_operator_position(OperatorPosition::NextLine)
57 .brace_position(BracePosition::SameLine)
58 .comment_line_force_space_after_slashes(false)
59 .construct_signature_space_after_new_keyword(true)
60 .constructor_type_space_after_new_keyword(true)
61 .arrow_function_use_parentheses(UseParentheses::Force)
62 .new_line_kind(NewLineKind::LineFeed)
63 .function_expression_space_after_function_keyword(true)
64 .tagged_template_space_before_literal(false)
65 .conditional_expression_prefer_single_line(true)
66 .quote_style(QuoteStyle::PreferDouble)
67 .jsx_multi_line_parens(JsxMultiLineParens::Prefer)
68 .ignore_node_comment_text("deno-fmt-ignore")
69 .ignore_file_comment_text("deno-fmt-ignore-file")
70 .module_sort_import_declarations(SortOrder::Maintain)
71 .module_sort_export_declarations(SortOrder::Maintain)
72 .export_declaration_sort_type_only_exports(NamedTypeImportsExportsOrder::None)
73 .import_declaration_sort_type_only_imports(NamedTypeImportsExportsOrder::None)
74 }
75
76 pub fn line_width(&mut self, value: u32) -> &mut Self {
80 self.insert("lineWidth", (value as i32).into())
81 }
82
83 pub fn use_tabs(&mut self, value: bool) -> &mut Self {
87 self.insert("useTabs", value.into())
88 }
89
90 pub fn indent_width(&mut self, value: u8) -> &mut Self {
94 self.insert("indentWidth", (value as i32).into())
95 }
96
97 pub fn new_line_kind(&mut self, value: NewLineKind) -> &mut Self {
101 self.insert("newLineKind", value.to_string().into())
102 }
103
104 pub fn quote_style(&mut self, value: QuoteStyle) -> &mut Self {
108 self.insert("quoteStyle", value.to_string().into())
109 }
110
111 pub fn jsx_quote_style(&mut self, value: JsxQuoteStyle) -> &mut Self {
115 self.insert("jsx.quoteStyle", value.to_string().into())
116 }
117
118 pub fn jsx_multi_line_parens(&mut self, value: JsxMultiLineParens) -> &mut Self {
123 self.insert("jsx.multiLineParens", value.to_string().into())
124 }
125
126 pub fn jsx_force_new_lines_surrounding_content(&mut self, value: bool) -> &mut Self {
130 self.insert("jsx.forceNewLinesSurroundingContent", value.into())
131 }
132
133 pub fn jsx_bracket_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
138 self.insert("jsx.bracketPosition", value.to_string().into())
139 }
140
141 pub fn jsx_opening_element_bracket_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
146 self.insert("jsxOpeningElement.bracketPosition", value.to_string().into())
147 }
148
149 pub fn jsx_self_closing_element_bracket_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
154 self.insert("jsxSelfClosingElement.bracketPosition", value.to_string().into())
155 }
156
157 pub fn semi_colons(&mut self, value: SemiColons) -> &mut Self {
161 self.insert("semiColons", value.to_string().into())
162 }
163
164 pub fn prefer_hanging(&mut self, value: bool) -> &mut Self {
168 self.insert("preferHanging", value.into())
169 }
170
171 pub fn quote_props(&mut self, value: QuoteProps) -> &mut Self {
175 self.insert("quoteProps", value.to_string().into())
176 }
177
178 pub fn brace_position(&mut self, value: BracePosition) -> &mut Self {
182 self.insert("bracePosition", value.to_string().into())
183 }
184
185 pub fn next_control_flow_position(&mut self, value: NextControlFlowPosition) -> &mut Self {
189 self.insert("nextControlFlowPosition", value.to_string().into())
190 }
191
192 pub fn operator_position(&mut self, value: OperatorPosition) -> &mut Self {
196 self.insert("operatorPosition", value.to_string().into())
197 }
198
199 pub fn single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
203 self.insert("singleBodyPosition", value.to_string().into())
204 }
205
206 pub fn file_indent_level(&mut self, value: u16) -> &mut Self {
212 self.insert("fileIndentLevel", (value as i32).into())
213 }
214
215 pub fn trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
219 self.insert("trailingCommas", value.to_string().into())
220 }
221
222 pub fn use_braces(&mut self, value: UseBraces) -> &mut Self {
226 self.insert("useBraces", value.to_string().into())
227 }
228
229 pub fn prefer_single_line(&mut self, value: bool) -> &mut Self {
234 self.insert("preferSingleLine", value.into())
235 }
236
237 pub fn binary_expression_space_surrounding_bitwise_and_arithmetic_operator(&mut self, value: bool) -> &mut Self {
244 self.insert("binaryExpression.spaceSurroundingBitwiseAndArithmeticOperator", value.into())
245 }
246
247 pub fn comment_line_force_space_after_slashes(&mut self, value: bool) -> &mut Self {
252 self.insert("commentLine.forceSpaceAfterSlashes", value.into())
253 }
254
255 pub fn construct_signature_space_after_new_keyword(&mut self, value: bool) -> &mut Self {
260 self.insert("constructSignature.spaceAfterNewKeyword", value.into())
261 }
262
263 pub fn constructor_space_before_parentheses(&mut self, value: bool) -> &mut Self {
268 self.insert("constructor.spaceBeforeParentheses", value.into())
269 }
270
271 pub fn constructor_type_space_after_new_keyword(&mut self, value: bool) -> &mut Self {
276 self.insert("constructorType.spaceAfterNewKeyword", value.into())
277 }
278
279 pub fn do_while_statement_space_after_while_keyword(&mut self, value: bool) -> &mut Self {
284 self.insert("doWhileStatement.spaceAfterWhileKeyword", value.into())
285 }
286
287 pub fn export_declaration_space_surrounding_named_exports(&mut self, value: bool) -> &mut Self {
292 self.insert("exportDeclaration.spaceSurroundingNamedExports", value.into())
293 }
294
295 pub fn for_statement_space_after_for_keyword(&mut self, value: bool) -> &mut Self {
300 self.insert("forStatement.spaceAfterForKeyword", value.into())
301 }
302
303 pub fn for_statement_space_after_semi_colons(&mut self, value: bool) -> &mut Self {
308 self.insert("forStatement.spaceAfterSemiColons", value.into())
309 }
310
311 pub fn for_in_statement_space_after_for_keyword(&mut self, value: bool) -> &mut Self {
316 self.insert("forInStatement.spaceAfterForKeyword", value.into())
317 }
318
319 pub fn for_of_statement_space_after_for_keyword(&mut self, value: bool) -> &mut Self {
324 self.insert("forOfStatement.spaceAfterForKeyword", value.into())
325 }
326
327 pub fn function_declaration_space_before_parentheses(&mut self, value: bool) -> &mut Self {
332 self.insert("functionDeclaration.spaceBeforeParentheses", value.into())
333 }
334
335 pub fn function_expression_space_before_parentheses(&mut self, value: bool) -> &mut Self {
340 self.insert("functionExpression.spaceBeforeParentheses", value.into())
341 }
342
343 pub fn function_expression_space_after_function_keyword(&mut self, value: bool) -> &mut Self {
348 self.insert("functionExpression.spaceAfterFunctionKeyword", value.into())
349 }
350
351 pub fn function_expression_flat_iife(&mut self, value: bool) -> &mut Self {
356 self.insert("functionExpression.flatIife", value.into())
357 }
358
359 pub fn get_accessor_space_before_parentheses(&mut self, value: bool) -> &mut Self {
364 self.insert("getAccessor.spaceBeforeParentheses", value.into())
365 }
366
367 pub fn if_statement_space_after_if_keyword(&mut self, value: bool) -> &mut Self {
372 self.insert("ifStatement.spaceAfterIfKeyword", value.into())
373 }
374
375 pub fn import_declaration_space_surrounding_named_imports(&mut self, value: bool) -> &mut Self {
380 self.insert("importDeclaration.spaceSurroundingNamedImports", value.into())
381 }
382
383 pub fn jsx_expression_container_space_surrounding_expression(&mut self, value: bool) -> &mut Self {
388 self.insert("jsxExpressionContainer.spaceSurroundingExpression", value.into())
389 }
390
391 pub fn jsx_self_closing_element_space_before_slash(&mut self, value: bool) -> &mut Self {
396 self.insert("jsxSelfClosingElement.spaceBeforeSlash", value.into())
397 }
398
399 pub fn object_expression_space_surrounding_properties(&mut self, value: bool) -> &mut Self {
404 self.insert("objectExpression.spaceSurroundingProperties", value.into())
405 }
406
407 pub fn object_pattern_space_surrounding_properties(&mut self, value: bool) -> &mut Self {
412 self.insert("objectPattern.spaceSurroundingProperties", value.into())
413 }
414
415 pub fn method_space_before_parentheses(&mut self, value: bool) -> &mut Self {
420 self.insert("method.spaceBeforeParentheses", value.into())
421 }
422
423 pub fn set_accessor_space_before_parentheses(&mut self, value: bool) -> &mut Self {
428 self.insert("setAccessor.spaceBeforeParentheses", value.into())
429 }
430
431 pub fn space_surrounding_properties(&mut self, value: bool) -> &mut Self {
436 self.insert("spaceSurroundingProperties", value.into())
437 }
438
439 pub fn tagged_template_space_before_literal(&mut self, value: bool) -> &mut Self {
444 self.insert("taggedTemplate.spaceBeforeLiteral", value.into())
445 }
446
447 pub fn type_annotation_space_before_colon(&mut self, value: bool) -> &mut Self {
452 self.insert("typeAnnotation.spaceBeforeColon", value.into())
453 }
454
455 pub fn type_assertion_space_before_expression(&mut self, value: bool) -> &mut Self {
460 self.insert("typeAssertion.spaceBeforeExpression", value.into())
461 }
462
463 pub fn type_literal_space_surrounding_properties(&mut self, value: bool) -> &mut Self {
468 self.insert("typeLiteral.spaceSurroundingProperties", value.into())
469 }
470
471 pub fn while_statement_space_after_while_keyword(&mut self, value: bool) -> &mut Self {
476 self.insert("whileStatement.spaceAfterWhileKeyword", value.into())
477 }
478
479 pub fn space_around(&mut self, value: bool) -> &mut Self {
484 self.insert("spaceAround", value.into())
485 }
486
487 pub fn arrow_function_use_parentheses(&mut self, value: UseParentheses) -> &mut Self {
493 self.insert("arrowFunction.useParentheses", value.to_string().into())
494 }
495
496 pub fn binary_expression_line_per_expression(&mut self, value: bool) -> &mut Self {
501 self.insert("binaryExpression.linePerExpression", value.into())
502 }
503
504 pub fn conditional_expression_line_per_expression(&mut self, value: bool) -> &mut Self {
509 self.insert("conditionalExpression.linePerExpression", value.into())
510 }
511
512 pub fn member_expression_line_per_expression(&mut self, value: bool) -> &mut Self {
517 self.insert("memberExpression.linePerExpression", value.into())
518 }
519
520 pub fn type_literal_separator_kind(&mut self, value: SemiColonOrComma) -> &mut Self {
522 self.insert("typeLiteral.separatorKind", value.to_string().into())
523 }
524
525 pub fn type_literal_separator_kind_single_line(&mut self, value: SemiColonOrComma) -> &mut Self {
527 self.insert("typeLiteral.separatorKind.singleLine", value.to_string().into())
528 }
529
530 pub fn type_literal_separator_kind_multi_line(&mut self, value: SemiColonOrComma) -> &mut Self {
532 self.insert("typeLiteral.separatorKind.multiLine", value.to_string().into())
533 }
534
535 pub fn module_sort_import_declarations(&mut self, value: SortOrder) -> &mut Self {
541 self.insert("module.sortImportDeclarations", value.to_string().into())
542 }
543
544 pub fn module_sort_export_declarations(&mut self, value: SortOrder) -> &mut Self {
548 self.insert("module.sortExportDeclarations", value.to_string().into())
549 }
550
551 pub fn import_declaration_sort_named_imports(&mut self, value: SortOrder) -> &mut Self {
555 self.insert("importDeclaration.sortNamedImports", value.to_string().into())
556 }
557
558 pub fn import_declaration_sort_type_only_imports(&mut self, value: NamedTypeImportsExportsOrder) -> &mut Self {
562 self.insert("importDeclaration.sortTypeOnlyImports", value.to_string().into())
563 }
564
565 pub fn export_declaration_sort_named_exports(&mut self, value: SortOrder) -> &mut Self {
569 self.insert("exportDeclaration.sortNamedExports", value.to_string().into())
570 }
571
572 pub fn export_declaration_sort_type_only_exports(&mut self, value: NamedTypeImportsExportsOrder) -> &mut Self {
576 self.insert("exportDeclaration.sortTypeOnlyExports", value.to_string().into())
577 }
578
579 pub fn ignore_node_comment_text(&mut self, value: &str) -> &mut Self {
585 self.insert("ignoreNodeCommentText", value.into())
586 }
587
588 pub fn ignore_file_comment_text(&mut self, value: &str) -> &mut Self {
592 self.insert("ignoreFileCommentText", value.into())
593 }
594
595 pub fn arrow_function_brace_position(&mut self, value: BracePosition) -> &mut Self {
598 self.insert("arrowFunction.bracePosition", value.to_string().into())
599 }
600
601 pub fn class_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
602 self.insert("classDeclaration.bracePosition", value.to_string().into())
603 }
604
605 pub fn class_expression_brace_position(&mut self, value: BracePosition) -> &mut Self {
606 self.insert("classExpression.bracePosition", value.to_string().into())
607 }
608
609 pub fn constructor_brace_position(&mut self, value: BracePosition) -> &mut Self {
610 self.insert("constructor.bracePosition", value.to_string().into())
611 }
612
613 pub fn do_while_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
614 self.insert("doWhileStatement.bracePosition", value.to_string().into())
615 }
616
617 pub fn enum_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
618 self.insert("enumDeclaration.bracePosition", value.to_string().into())
619 }
620
621 pub fn for_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
622 self.insert("forStatement.bracePosition", value.to_string().into())
623 }
624
625 pub fn for_in_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
626 self.insert("forInStatement.bracePosition", value.to_string().into())
627 }
628
629 pub fn for_of_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
630 self.insert("forOfStatement.bracePosition", value.to_string().into())
631 }
632
633 pub fn get_accessor_brace_position(&mut self, value: BracePosition) -> &mut Self {
634 self.insert("getAccessor.bracePosition", value.to_string().into())
635 }
636
637 pub fn if_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
638 self.insert("ifStatement.bracePosition", value.to_string().into())
639 }
640
641 pub fn interface_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
642 self.insert("interfaceDeclaration.bracePosition", value.to_string().into())
643 }
644
645 pub fn function_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
646 self.insert("functionDeclaration.bracePosition", value.to_string().into())
647 }
648
649 pub fn function_expression_brace_position(&mut self, value: BracePosition) -> &mut Self {
650 self.insert("functionExpression.bracePosition", value.to_string().into())
651 }
652
653 pub fn method_brace_position(&mut self, value: BracePosition) -> &mut Self {
654 self.insert("method.bracePosition", value.to_string().into())
655 }
656
657 pub fn module_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
658 self.insert("moduleDeclaration.bracePosition", value.to_string().into())
659 }
660
661 pub fn set_accessor_brace_position(&mut self, value: BracePosition) -> &mut Self {
662 self.insert("setAccessor.bracePosition", value.to_string().into())
663 }
664
665 pub fn static_block_brace_position(&mut self, value: BracePosition) -> &mut Self {
666 self.insert("staticBlock.bracePosition", value.to_string().into())
667 }
668
669 pub fn switch_case_brace_position(&mut self, value: BracePosition) -> &mut Self {
670 self.insert("switchCase.bracePosition", value.to_string().into())
671 }
672
673 pub fn switch_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
674 self.insert("switchStatement.bracePosition", value.to_string().into())
675 }
676
677 pub fn try_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
678 self.insert("tryStatement.bracePosition", value.to_string().into())
679 }
680
681 pub fn while_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
682 self.insert("whileStatement.bracePosition", value.to_string().into())
683 }
684
685 pub fn arguments_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
688 self.insert("arguments.preferHanging", value.to_string().into())
689 }
690
691 pub fn array_expression_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
692 self.insert("arrayExpression.preferHanging", value.to_string().into())
693 }
694
695 pub fn array_pattern_prefer_hanging(&mut self, value: bool) -> &mut Self {
696 self.insert("arrayPattern.preferHanging", value.into())
697 }
698
699 pub fn do_while_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
700 self.insert("doWhileStatement.preferHanging", value.into())
701 }
702
703 pub fn export_declaration_prefer_hanging(&mut self, value: bool) -> &mut Self {
704 self.insert("exportDeclaration.preferHanging", value.into())
705 }
706
707 pub fn extends_clause_prefer_hanging(&mut self, value: bool) -> &mut Self {
708 self.insert("extendsClause.preferHanging", value.into())
709 }
710
711 pub fn for_in_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
712 self.insert("forInStatement.preferHanging", value.into())
713 }
714
715 pub fn for_of_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
716 self.insert("forOfStatement.preferHanging", value.into())
717 }
718
719 pub fn for_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
720 self.insert("forStatement.preferHanging", value.into())
721 }
722
723 pub fn if_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
724 self.insert("ifStatement.preferHanging", value.into())
725 }
726
727 pub fn implements_clause_prefer_hanging(&mut self, value: bool) -> &mut Self {
728 self.insert("implementsClause.preferHanging", value.into())
729 }
730
731 pub fn import_declaration_prefer_hanging(&mut self, value: bool) -> &mut Self {
732 self.insert("importDeclaration.preferHanging", value.into())
733 }
734
735 pub fn jsx_attributes_prefer_hanging(&mut self, value: bool) -> &mut Self {
736 self.insert("jsxAttributes.preferHanging", value.into())
737 }
738
739 pub fn object_expression_prefer_hanging(&mut self, value: bool) -> &mut Self {
740 self.insert("objectExpression.preferHanging", value.into())
741 }
742
743 pub fn object_pattern_prefer_hanging(&mut self, value: bool) -> &mut Self {
744 self.insert("objectPattern.preferHanging", value.into())
745 }
746
747 pub fn parameters_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
748 self.insert("parameters.preferHanging", value.to_string().into())
749 }
750
751 pub fn sequence_expression_prefer_hanging(&mut self, value: bool) -> &mut Self {
752 self.insert("sequenceExpression.preferHanging", value.into())
753 }
754
755 pub fn switch_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
756 self.insert("switchStatement.preferHanging", value.into())
757 }
758
759 pub fn tuple_type_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
760 self.insert("tupleType.preferHanging", value.to_string().into())
761 }
762
763 pub fn type_literal_prefer_hanging(&mut self, value: bool) -> &mut Self {
764 self.insert("typeLiteral.preferHanging", value.into())
765 }
766
767 pub fn type_parameters_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
768 self.insert("typeParameters.preferHanging", value.to_string().into())
769 }
770
771 pub fn union_and_intersection_type_prefer_hanging(&mut self, value: bool) -> &mut Self {
772 self.insert("unionAndIntersectionType.preferHanging", value.into())
773 }
774
775 pub fn variable_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
776 self.insert("variableStatement.preferHanging", value.into())
777 }
778
779 pub fn while_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
780 self.insert("whileStatement.preferHanging", value.into())
781 }
782
783 pub fn export_declaration_force_single_line(&mut self, value: bool) -> &mut Self {
786 self.insert("exportDeclaration.forceSingleLine", value.into())
787 }
788
789 pub fn import_declaration_force_single_line(&mut self, value: bool) -> &mut Self {
790 self.insert("importDeclaration.forceSingleLine", value.into())
791 }
792
793 pub fn export_declaration_force_multi_line(&mut self, value: ForceMultiLine) -> &mut Self {
796 self.insert("exportDeclaration.forceMultiLine", value.to_string().into())
797 }
798
799 pub fn import_declaration_force_multi_line(&mut self, value: ForceMultiLine) -> &mut Self {
800 self.insert("importDeclaration.forceMultiLine", value.to_string().into())
801 }
802
803 pub fn enum_declaration_member_spacing(&mut self, value: MemberSpacing) -> &mut Self {
806 self.insert("enumDeclaration.memberSpacing", value.to_string().into())
807 }
808
809 pub fn if_statement_next_control_flow_position(&mut self, value: NextControlFlowPosition) -> &mut Self {
812 self.insert("ifStatement.nextControlFlowPosition", value.to_string().into())
813 }
814
815 pub fn try_statement_next_control_flow_position(&mut self, value: NextControlFlowPosition) -> &mut Self {
816 self.insert("tryStatement.nextControlFlowPosition", value.to_string().into())
817 }
818
819 pub fn do_while_statement_next_control_flow_position(&mut self, value: NextControlFlowPosition) -> &mut Self {
820 self.insert("doWhileStatement.nextControlFlowPosition", value.to_string().into())
821 }
822
823 pub fn binary_expression_operator_position(&mut self, value: OperatorPosition) -> &mut Self {
826 self.insert("binaryExpression.operatorPosition", value.to_string().into())
827 }
828
829 pub fn conditional_expression_operator_position(&mut self, value: OperatorPosition) -> &mut Self {
830 self.insert("conditionalExpression.operatorPosition", value.to_string().into())
831 }
832
833 pub fn conditional_type_operator_position(&mut self, value: OperatorPosition) -> &mut Self {
834 self.insert("conditionalType.operatorPosition", value.to_string().into())
835 }
836
837 pub fn if_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
840 self.insert("ifStatement.singleBodyPosition", value.to_string().into())
841 }
842
843 pub fn for_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
844 self.insert("forStatement.singleBodyPosition", value.to_string().into())
845 }
846
847 pub fn for_in_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
848 self.insert("forInStatement.singleBodyPosition", value.to_string().into())
849 }
850
851 pub fn for_of_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
852 self.insert("forOfStatement.singleBodyPosition", value.to_string().into())
853 }
854
855 pub fn while_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
856 self.insert("whileStatement.singleBodyPosition", value.to_string().into())
857 }
858
859 pub fn arguments_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
862 self.insert("arguments.trailingCommas", value.to_string().into())
863 }
864
865 pub fn parameters_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
866 self.insert("parameters.trailingCommas", value.to_string().into())
867 }
868
869 pub fn array_expression_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
870 self.insert("arrayExpression.trailingCommas", value.to_string().into())
871 }
872
873 pub fn array_pattern_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
874 self.insert("arrayPattern.trailingCommas", value.to_string().into())
875 }
876
877 pub fn enum_declaration_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
878 self.insert("enumDeclaration.trailingCommas", value.to_string().into())
879 }
880
881 pub fn export_declaration_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
882 self.insert("exportDeclaration.trailingCommas", value.to_string().into())
883 }
884
885 pub fn import_declaration_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
886 self.insert("importDeclaration.trailingCommas", value.to_string().into())
887 }
888
889 pub fn object_expression_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
890 self.insert("objectExpression.trailingCommas", value.to_string().into())
891 }
892
893 pub fn object_pattern_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
894 self.insert("objectPattern.trailingCommas", value.to_string().into())
895 }
896
897 pub fn tuple_type_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
898 self.insert("tupleType.trailingCommas", value.to_string().into())
899 }
900
901 pub fn type_literal_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
903 self.insert("typeLiteral.trailingCommas", value.to_string().into())
904 }
905
906 pub fn type_parameters_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
907 self.insert("typeParameters.trailingCommas", value.to_string().into())
908 }
909
910 pub fn if_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
913 self.insert("ifStatement.useBraces", value.to_string().into())
914 }
915
916 pub fn for_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
917 self.insert("forStatement.useBraces", value.to_string().into())
918 }
919
920 pub fn for_in_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
921 self.insert("forInStatement.useBraces", value.to_string().into())
922 }
923
924 pub fn for_of_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
925 self.insert("forOfStatement.useBraces", value.to_string().into())
926 }
927
928 pub fn while_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
929 self.insert("whileStatement.useBraces", value.to_string().into())
930 }
931
932 pub fn array_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
935 self.insert("arrayExpression.preferSingleLine", value.into())
936 }
937
938 pub fn array_pattern_prefer_single_line(&mut self, value: bool) -> &mut Self {
939 self.insert("arrayPattern.preferSingleLine", value.into())
940 }
941
942 pub fn arguments_prefer_single_line(&mut self, value: bool) -> &mut Self {
943 self.insert("arguments.preferSingleLine", value.into())
944 }
945
946 pub fn binary_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
947 self.insert("binaryExpression.preferSingleLine", value.into())
948 }
949
950 pub fn computed_prefer_single_line(&mut self, value: bool) -> &mut Self {
951 self.insert("computed.preferSingleLine", value.into())
952 }
953
954 pub fn conditional_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
955 self.insert("conditionalExpression.preferSingleLine", value.into())
956 }
957
958 pub fn conditional_type_prefer_single_line(&mut self, value: bool) -> &mut Self {
959 self.insert("conditionalType.preferSingleLine", value.into())
960 }
961
962 pub fn decorators_prefer_single_line(&mut self, value: bool) -> &mut Self {
963 self.insert("decorators.preferSingleLine", value.into())
964 }
965
966 pub fn export_declaration_prefer_single_line(&mut self, value: bool) -> &mut Self {
967 self.insert("exportDeclaration.preferSingleLine", value.into())
968 }
969
970 pub fn for_statement_prefer_single_line(&mut self, value: bool) -> &mut Self {
971 self.insert("forStatement.preferSingleLine", value.into())
972 }
973
974 pub fn import_declaration_prefer_single_line(&mut self, value: bool) -> &mut Self {
975 self.insert("importDeclaration.preferSingleLine", value.into())
976 }
977
978 pub fn jsx_attributes_prefer_single_line(&mut self, value: bool) -> &mut Self {
979 self.insert("jsxAttributes.preferSingleLine", value.into())
980 }
981
982 pub fn jsx_element_prefer_single_line(&mut self, value: bool) -> &mut Self {
983 self.insert("jsxElement.preferSingleLine", value.into())
984 }
985
986 pub fn mapped_type_prefer_single_line(&mut self, value: bool) -> &mut Self {
987 self.insert("mappedType.preferSingleLine", value.into())
988 }
989
990 pub fn member_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
991 self.insert("memberExpression.preferSingleLine", value.into())
992 }
993
994 pub fn object_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
995 self.insert("objectExpression.preferSingleLine", value.into())
996 }
997
998 pub fn object_pattern_prefer_single_line(&mut self, value: bool) -> &mut Self {
999 self.insert("objectPattern.preferSingleLine", value.into())
1000 }
1001
1002 pub fn parameters_prefer_single_line(&mut self, value: bool) -> &mut Self {
1003 self.insert("parameters.preferSingleLine", value.into())
1004 }
1005
1006 pub fn parentheses_prefer_single_line(&mut self, value: bool) -> &mut Self {
1007 self.insert("parentheses.preferSingleLine", value.into())
1008 }
1009
1010 pub fn tuple_type_prefer_single_line(&mut self, value: bool) -> &mut Self {
1011 self.insert("tupleType.preferSingleLine", value.into())
1012 }
1013
1014 pub fn type_literal_prefer_single_line(&mut self, value: bool) -> &mut Self {
1015 self.insert("typeLiteral.preferSingleLine", value.into())
1016 }
1017
1018 pub fn type_parameters_prefer_single_line(&mut self, value: bool) -> &mut Self {
1019 self.insert("typeParameters.preferSingleLine", value.into())
1020 }
1021
1022 pub fn union_and_intersection_type_prefer_single_line(&mut self, value: bool) -> &mut Self {
1023 self.insert("unionAndIntersectionType.preferSingleLine", value.into())
1024 }
1025
1026 pub fn variable_statement_prefer_single_line(&mut self, value: bool) -> &mut Self {
1027 self.insert("variableStatement.preferSingleLine", value.into())
1028 }
1029
1030 pub fn arguments_space_around(&mut self, value: bool) -> &mut Self {
1033 self.insert("arguments.spaceAround", value.into())
1034 }
1035
1036 pub fn array_expression_space_around(&mut self, value: bool) -> &mut Self {
1037 self.insert("arrayExpression.spaceAround", value.into())
1038 }
1039
1040 pub fn array_pattern_space_around(&mut self, value: bool) -> &mut Self {
1041 self.insert("arrayPattern.spaceAround", value.into())
1042 }
1043
1044 pub fn catch_clause_space_around(&mut self, value: bool) -> &mut Self {
1045 self.insert("catchClause.spaceAround", value.into())
1046 }
1047
1048 pub fn do_while_statement_space_around(&mut self, value: bool) -> &mut Self {
1049 self.insert("doWhileStatement.spaceAround", value.into())
1050 }
1051
1052 pub fn for_in_statement_space_around(&mut self, value: bool) -> &mut Self {
1053 self.insert("forInStatement.spaceAround", value.into())
1054 }
1055
1056 pub fn for_of_statement_space_around(&mut self, value: bool) -> &mut Self {
1057 self.insert("forOfStatement.spaceAround", value.into())
1058 }
1059
1060 pub fn for_statement_space_around(&mut self, value: bool) -> &mut Self {
1061 self.insert("forStatement.spaceAround", value.into())
1062 }
1063
1064 pub fn if_statement_space_around(&mut self, value: bool) -> &mut Self {
1065 self.insert("ifStatement.spaceAround", value.into())
1066 }
1067
1068 pub fn parameters_space_around(&mut self, value: bool) -> &mut Self {
1069 self.insert("parameters.spaceAround", value.into())
1070 }
1071
1072 pub fn paren_expression_space_around(&mut self, value: bool) -> &mut Self {
1073 self.insert("parenExpression.spaceAround", value.into())
1074 }
1075
1076 pub fn switch_statement_space_around(&mut self, value: bool) -> &mut Self {
1077 self.insert("switchStatement.spaceAround", value.into())
1078 }
1079
1080 pub fn tuple_type_space_around(&mut self, value: bool) -> &mut Self {
1081 self.insert("tupleType.spaceAround", value.into())
1082 }
1083
1084 pub fn while_statement_space_around(&mut self, value: bool) -> &mut Self {
1085 self.insert("whileStatement.spaceAround", value.into())
1086 }
1087
1088 #[cfg(test)]
1089 pub(super) fn get_inner_config(&self) -> ConfigKeyMap {
1090 self.config.clone()
1091 }
1092
1093 fn insert(&mut self, name: &str, value: ConfigKeyValue) -> &mut Self {
1094 self.config.insert(String::from(name), value);
1095 self
1096 }
1097}
1098
1099#[cfg(test)]
1100mod tests {
1101 use super::*;
1102
1103 #[test]
1104 fn check_all_values_set() {
1105 let mut config = ConfigurationBuilder::new();
1106 config
1107 .new_line_kind(NewLineKind::Auto)
1108 .line_width(80)
1109 .use_tabs(false)
1110 .indent_width(4)
1111 .quote_style(QuoteStyle::AlwaysDouble)
1113 .jsx_quote_style(JsxQuoteStyle::PreferSingle)
1114 .jsx_multi_line_parens(JsxMultiLineParens::Never)
1115 .jsx_force_new_lines_surrounding_content(true)
1116 .jsx_bracket_position(SameOrNextLinePosition::Maintain)
1117 .jsx_opening_element_bracket_position(SameOrNextLinePosition::Maintain)
1118 .jsx_self_closing_element_bracket_position(SameOrNextLinePosition::Maintain)
1119 .semi_colons(SemiColons::Prefer)
1120 .brace_position(BracePosition::NextLine)
1121 .next_control_flow_position(NextControlFlowPosition::SameLine)
1122 .operator_position(OperatorPosition::SameLine)
1123 .single_body_position(SameOrNextLinePosition::SameLine)
1124 .trailing_commas(TrailingCommas::Never)
1125 .file_indent_level(1)
1126 .use_braces(UseBraces::WhenNotSingleLine)
1127 .quote_props(QuoteProps::AsNeeded)
1128 .prefer_hanging(false)
1129 .arrow_function_use_parentheses(UseParentheses::Maintain)
1131 .binary_expression_line_per_expression(false)
1132 .conditional_expression_line_per_expression(true)
1133 .member_expression_line_per_expression(false)
1134 .type_literal_separator_kind(SemiColonOrComma::Comma)
1135 .type_literal_separator_kind_single_line(SemiColonOrComma::Comma)
1136 .type_literal_separator_kind_multi_line(SemiColonOrComma::Comma)
1137 .module_sort_import_declarations(SortOrder::Maintain)
1139 .module_sort_export_declarations(SortOrder::Maintain)
1140 .import_declaration_sort_named_imports(SortOrder::Maintain)
1141 .export_declaration_sort_named_exports(SortOrder::Maintain)
1142 .import_declaration_sort_type_only_imports(NamedTypeImportsExportsOrder::First)
1143 .export_declaration_sort_type_only_exports(NamedTypeImportsExportsOrder::None)
1144 .ignore_node_comment_text("ignore")
1146 .ignore_file_comment_text("ignore-file")
1147 .arrow_function_brace_position(BracePosition::NextLine)
1149 .class_declaration_brace_position(BracePosition::NextLine)
1150 .class_expression_brace_position(BracePosition::NextLine)
1151 .constructor_brace_position(BracePosition::NextLine)
1152 .do_while_statement_brace_position(BracePosition::NextLine)
1153 .enum_declaration_brace_position(BracePosition::NextLine)
1154 .for_statement_brace_position(BracePosition::NextLine)
1155 .for_in_statement_brace_position(BracePosition::NextLine)
1156 .for_of_statement_brace_position(BracePosition::NextLine)
1157 .get_accessor_brace_position(BracePosition::NextLine)
1158 .if_statement_brace_position(BracePosition::NextLine)
1159 .interface_declaration_brace_position(BracePosition::NextLine)
1160 .function_declaration_brace_position(BracePosition::NextLine)
1161 .function_expression_brace_position(BracePosition::NextLine)
1162 .method_brace_position(BracePosition::NextLine)
1163 .module_declaration_brace_position(BracePosition::NextLine)
1164 .set_accessor_brace_position(BracePosition::NextLine)
1165 .static_block_brace_position(BracePosition::NextLine)
1166 .switch_case_brace_position(BracePosition::NextLine)
1167 .switch_statement_brace_position(BracePosition::NextLine)
1168 .try_statement_brace_position(BracePosition::NextLine)
1169 .while_statement_brace_position(BracePosition::NextLine)
1170 .arguments_prefer_hanging(PreferHanging::OnlySingleItem)
1172 .array_expression_prefer_hanging(PreferHanging::OnlySingleItem)
1173 .array_pattern_prefer_hanging(true)
1174 .do_while_statement_prefer_hanging(true)
1175 .export_declaration_prefer_hanging(true)
1176 .extends_clause_prefer_hanging(true)
1177 .for_in_statement_prefer_hanging(true)
1178 .for_of_statement_prefer_hanging(true)
1179 .for_statement_prefer_hanging(true)
1180 .if_statement_prefer_hanging(true)
1181 .implements_clause_prefer_hanging(true)
1182 .import_declaration_prefer_hanging(true)
1183 .jsx_attributes_prefer_hanging(true)
1184 .object_expression_prefer_hanging(true)
1185 .object_pattern_prefer_hanging(true)
1186 .parameters_prefer_hanging(PreferHanging::OnlySingleItem)
1187 .sequence_expression_prefer_hanging(true)
1188 .switch_statement_prefer_hanging(true)
1189 .tuple_type_prefer_hanging(PreferHanging::OnlySingleItem)
1190 .type_literal_prefer_hanging(true)
1191 .type_parameters_prefer_hanging(PreferHanging::OnlySingleItem)
1192 .union_and_intersection_type_prefer_hanging(true)
1193 .variable_statement_prefer_hanging(true)
1194 .while_statement_prefer_hanging(true)
1195 .enum_declaration_member_spacing(MemberSpacing::Maintain)
1197 .if_statement_next_control_flow_position(NextControlFlowPosition::SameLine)
1199 .try_statement_next_control_flow_position(NextControlFlowPosition::SameLine)
1200 .do_while_statement_next_control_flow_position(NextControlFlowPosition::SameLine)
1201 .binary_expression_operator_position(OperatorPosition::SameLine)
1203 .conditional_expression_operator_position(OperatorPosition::SameLine)
1204 .conditional_type_operator_position(OperatorPosition::SameLine)
1205 .if_statement_single_body_position(SameOrNextLinePosition::SameLine)
1207 .for_statement_single_body_position(SameOrNextLinePosition::SameLine)
1208 .for_in_statement_single_body_position(SameOrNextLinePosition::SameLine)
1209 .for_of_statement_single_body_position(SameOrNextLinePosition::SameLine)
1210 .while_statement_single_body_position(SameOrNextLinePosition::SameLine)
1211 .arguments_trailing_commas(TrailingCommas::Never)
1213 .parameters_trailing_commas(TrailingCommas::Never)
1214 .array_expression_trailing_commas(TrailingCommas::Never)
1215 .array_pattern_trailing_commas(TrailingCommas::Never)
1216 .enum_declaration_trailing_commas(TrailingCommas::Never)
1217 .import_declaration_trailing_commas(TrailingCommas::Never)
1218 .export_declaration_trailing_commas(TrailingCommas::Never)
1219 .object_expression_trailing_commas(TrailingCommas::Never)
1220 .object_pattern_trailing_commas(TrailingCommas::Never)
1221 .type_parameters_trailing_commas(TrailingCommas::Never)
1222 .tuple_type_trailing_commas(TrailingCommas::Never)
1223 .type_literal_trailing_commas(TrailingCommas::Never)
1224 .if_statement_use_braces(UseBraces::Always)
1226 .for_statement_use_braces(UseBraces::Always)
1227 .for_in_statement_use_braces(UseBraces::Always)
1228 .for_of_statement_use_braces(UseBraces::Always)
1229 .while_statement_use_braces(UseBraces::Always)
1230 .array_expression_prefer_single_line(false)
1232 .array_pattern_prefer_single_line(false)
1233 .arguments_prefer_single_line(false)
1234 .binary_expression_prefer_single_line(false)
1235 .computed_prefer_single_line(false)
1236 .conditional_expression_prefer_single_line(false)
1237 .conditional_type_prefer_single_line(false)
1238 .decorators_prefer_single_line(false)
1239 .export_declaration_prefer_single_line(false)
1240 .for_statement_prefer_single_line(false)
1241 .import_declaration_prefer_single_line(false)
1242 .jsx_attributes_prefer_single_line(false)
1243 .jsx_element_prefer_single_line(false)
1244 .mapped_type_prefer_single_line(false)
1245 .member_expression_prefer_single_line(false)
1246 .object_expression_prefer_single_line(false)
1247 .object_pattern_prefer_single_line(false)
1248 .parameters_prefer_single_line(false)
1249 .parentheses_prefer_single_line(false)
1250 .tuple_type_prefer_single_line(false)
1251 .type_literal_prefer_single_line(false)
1252 .type_parameters_prefer_single_line(false)
1253 .union_and_intersection_type_prefer_single_line(false)
1254 .variable_statement_prefer_single_line(false)
1255 .export_declaration_force_single_line(true)
1257 .import_declaration_force_single_line(true)
1258 .export_declaration_force_multi_line(ForceMultiLine::Always)
1260 .import_declaration_force_multi_line(ForceMultiLine::Always)
1261 .binary_expression_space_surrounding_bitwise_and_arithmetic_operator(true)
1263 .comment_line_force_space_after_slashes(false)
1264 .construct_signature_space_after_new_keyword(true)
1265 .constructor_space_before_parentheses(true)
1266 .constructor_type_space_after_new_keyword(true)
1267 .do_while_statement_space_after_while_keyword(true)
1268 .export_declaration_space_surrounding_named_exports(true)
1269 .for_statement_space_after_for_keyword(true)
1270 .for_statement_space_after_semi_colons(true)
1271 .for_in_statement_space_after_for_keyword(true)
1272 .for_of_statement_space_after_for_keyword(true)
1273 .function_declaration_space_before_parentheses(true)
1274 .function_expression_space_before_parentheses(true)
1275 .function_expression_space_after_function_keyword(true)
1276 .get_accessor_space_before_parentheses(true)
1277 .if_statement_space_after_if_keyword(true)
1278 .import_declaration_space_surrounding_named_imports(true)
1279 .jsx_expression_container_space_surrounding_expression(true)
1280 .jsx_self_closing_element_space_before_slash(true)
1281 .method_space_before_parentheses(true)
1282 .object_expression_space_surrounding_properties(false)
1283 .object_pattern_space_surrounding_properties(false)
1284 .set_accessor_space_before_parentheses(true)
1285 .space_surrounding_properties(false)
1286 .tagged_template_space_before_literal(false)
1287 .type_annotation_space_before_colon(true)
1288 .type_assertion_space_before_expression(true)
1289 .type_literal_space_surrounding_properties(false)
1290 .while_statement_space_after_while_keyword(true)
1291 .arguments_space_around(true)
1293 .array_expression_space_around(true)
1294 .array_pattern_space_around(true)
1295 .catch_clause_space_around(true)
1296 .do_while_statement_space_around(true)
1297 .for_in_statement_space_around(true)
1298 .for_of_statement_space_around(true)
1299 .for_statement_space_around(true)
1300 .if_statement_space_around(true)
1301 .parameters_space_around(true)
1302 .paren_expression_space_around(true)
1303 .switch_statement_space_around(true)
1304 .tuple_type_space_around(true)
1305 .while_statement_space_around(true);
1306
1307 let inner_config = config.get_inner_config();
1308 assert_eq!(inner_config.len(), 182);
1309 let diagnostics = resolve_config(inner_config, &Default::default()).diagnostics;
1310 assert_eq!(diagnostics.len(), 0);
1311 }
1312}