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 get_accessor_space_before_parentheses(&mut self, value: bool) -> &mut Self {
356 self.insert("getAccessor.spaceBeforeParentheses", value.into())
357 }
358
359 pub fn if_statement_space_after_if_keyword(&mut self, value: bool) -> &mut Self {
364 self.insert("ifStatement.spaceAfterIfKeyword", value.into())
365 }
366
367 pub fn import_declaration_space_surrounding_named_imports(&mut self, value: bool) -> &mut Self {
372 self.insert("importDeclaration.spaceSurroundingNamedImports", value.into())
373 }
374
375 pub fn jsx_expression_container_space_surrounding_expression(&mut self, value: bool) -> &mut Self {
380 self.insert("jsxExpressionContainer.spaceSurroundingExpression", value.into())
381 }
382
383 pub fn jsx_self_closing_element_space_before_slash(&mut self, value: bool) -> &mut Self {
388 self.insert("jsxSelfClosingElement.spaceBeforeSlash", value.into())
389 }
390
391 pub fn object_expression_space_surrounding_properties(&mut self, value: bool) -> &mut Self {
396 self.insert("objectExpression.spaceSurroundingProperties", value.into())
397 }
398
399 pub fn object_pattern_space_surrounding_properties(&mut self, value: bool) -> &mut Self {
404 self.insert("objectPattern.spaceSurroundingProperties", value.into())
405 }
406
407 pub fn method_space_before_parentheses(&mut self, value: bool) -> &mut Self {
412 self.insert("method.spaceBeforeParentheses", value.into())
413 }
414
415 pub fn set_accessor_space_before_parentheses(&mut self, value: bool) -> &mut Self {
420 self.insert("setAccessor.spaceBeforeParentheses", value.into())
421 }
422
423 pub fn space_surrounding_properties(&mut self, value: bool) -> &mut Self {
428 self.insert("spaceSurroundingProperties", value.into())
429 }
430
431 pub fn tagged_template_space_before_literal(&mut self, value: bool) -> &mut Self {
436 self.insert("taggedTemplate.spaceBeforeLiteral", value.into())
437 }
438
439 pub fn type_annotation_space_before_colon(&mut self, value: bool) -> &mut Self {
444 self.insert("typeAnnotation.spaceBeforeColon", value.into())
445 }
446
447 pub fn type_assertion_space_before_expression(&mut self, value: bool) -> &mut Self {
452 self.insert("typeAssertion.spaceBeforeExpression", value.into())
453 }
454
455 pub fn type_literal_space_surrounding_properties(&mut self, value: bool) -> &mut Self {
460 self.insert("typeLiteral.spaceSurroundingProperties", value.into())
461 }
462
463 pub fn while_statement_space_after_while_keyword(&mut self, value: bool) -> &mut Self {
468 self.insert("whileStatement.spaceAfterWhileKeyword", value.into())
469 }
470
471 pub fn space_around(&mut self, value: bool) -> &mut Self {
476 self.insert("spaceAround", value.into())
477 }
478
479 pub fn arrow_function_use_parentheses(&mut self, value: UseParentheses) -> &mut Self {
485 self.insert("arrowFunction.useParentheses", value.to_string().into())
486 }
487
488 pub fn binary_expression_line_per_expression(&mut self, value: bool) -> &mut Self {
493 self.insert("binaryExpression.linePerExpression", value.into())
494 }
495
496 pub fn conditional_expression_line_per_expression(&mut self, value: bool) -> &mut Self {
501 self.insert("conditionalExpression.linePerExpression", value.into())
502 }
503
504 pub fn member_expression_line_per_expression(&mut self, value: bool) -> &mut Self {
509 self.insert("memberExpression.linePerExpression", value.into())
510 }
511
512 pub fn type_literal_separator_kind(&mut self, value: SemiColonOrComma) -> &mut Self {
514 self.insert("typeLiteral.separatorKind", value.to_string().into())
515 }
516
517 pub fn type_literal_separator_kind_single_line(&mut self, value: SemiColonOrComma) -> &mut Self {
519 self.insert("typeLiteral.separatorKind.singleLine", value.to_string().into())
520 }
521
522 pub fn type_literal_separator_kind_multi_line(&mut self, value: SemiColonOrComma) -> &mut Self {
524 self.insert("typeLiteral.separatorKind.multiLine", value.to_string().into())
525 }
526
527 pub fn module_sort_import_declarations(&mut self, value: SortOrder) -> &mut Self {
533 self.insert("module.sortImportDeclarations", value.to_string().into())
534 }
535
536 pub fn module_sort_export_declarations(&mut self, value: SortOrder) -> &mut Self {
540 self.insert("module.sortExportDeclarations", value.to_string().into())
541 }
542
543 pub fn import_declaration_sort_named_imports(&mut self, value: SortOrder) -> &mut Self {
547 self.insert("importDeclaration.sortNamedImports", value.to_string().into())
548 }
549
550 pub fn import_declaration_sort_type_only_imports(&mut self, value: NamedTypeImportsExportsOrder) -> &mut Self {
554 self.insert("importDeclaration.sortTypeOnlyImports", value.to_string().into())
555 }
556
557 pub fn export_declaration_sort_named_exports(&mut self, value: SortOrder) -> &mut Self {
561 self.insert("exportDeclaration.sortNamedExports", value.to_string().into())
562 }
563
564 pub fn export_declaration_sort_type_only_exports(&mut self, value: NamedTypeImportsExportsOrder) -> &mut Self {
568 self.insert("exportDeclaration.sortTypeOnlyExports", value.to_string().into())
569 }
570
571 pub fn ignore_node_comment_text(&mut self, value: &str) -> &mut Self {
577 self.insert("ignoreNodeCommentText", value.into())
578 }
579
580 pub fn ignore_file_comment_text(&mut self, value: &str) -> &mut Self {
584 self.insert("ignoreFileCommentText", value.into())
585 }
586
587 pub fn arrow_function_brace_position(&mut self, value: BracePosition) -> &mut Self {
590 self.insert("arrowFunction.bracePosition", value.to_string().into())
591 }
592
593 pub fn class_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
594 self.insert("classDeclaration.bracePosition", value.to_string().into())
595 }
596
597 pub fn class_expression_brace_position(&mut self, value: BracePosition) -> &mut Self {
598 self.insert("classExpression.bracePosition", value.to_string().into())
599 }
600
601 pub fn constructor_brace_position(&mut self, value: BracePosition) -> &mut Self {
602 self.insert("constructor.bracePosition", value.to_string().into())
603 }
604
605 pub fn do_while_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
606 self.insert("doWhileStatement.bracePosition", value.to_string().into())
607 }
608
609 pub fn enum_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
610 self.insert("enumDeclaration.bracePosition", value.to_string().into())
611 }
612
613 pub fn for_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
614 self.insert("forStatement.bracePosition", value.to_string().into())
615 }
616
617 pub fn for_in_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
618 self.insert("forInStatement.bracePosition", value.to_string().into())
619 }
620
621 pub fn for_of_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
622 self.insert("forOfStatement.bracePosition", value.to_string().into())
623 }
624
625 pub fn get_accessor_brace_position(&mut self, value: BracePosition) -> &mut Self {
626 self.insert("getAccessor.bracePosition", value.to_string().into())
627 }
628
629 pub fn if_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
630 self.insert("ifStatement.bracePosition", value.to_string().into())
631 }
632
633 pub fn interface_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
634 self.insert("interfaceDeclaration.bracePosition", value.to_string().into())
635 }
636
637 pub fn function_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
638 self.insert("functionDeclaration.bracePosition", value.to_string().into())
639 }
640
641 pub fn function_expression_brace_position(&mut self, value: BracePosition) -> &mut Self {
642 self.insert("functionExpression.bracePosition", value.to_string().into())
643 }
644
645 pub fn method_brace_position(&mut self, value: BracePosition) -> &mut Self {
646 self.insert("method.bracePosition", value.to_string().into())
647 }
648
649 pub fn module_declaration_brace_position(&mut self, value: BracePosition) -> &mut Self {
650 self.insert("moduleDeclaration.bracePosition", value.to_string().into())
651 }
652
653 pub fn set_accessor_brace_position(&mut self, value: BracePosition) -> &mut Self {
654 self.insert("setAccessor.bracePosition", value.to_string().into())
655 }
656
657 pub fn static_block_brace_position(&mut self, value: BracePosition) -> &mut Self {
658 self.insert("staticBlock.bracePosition", value.to_string().into())
659 }
660
661 pub fn switch_case_brace_position(&mut self, value: BracePosition) -> &mut Self {
662 self.insert("switchCase.bracePosition", value.to_string().into())
663 }
664
665 pub fn switch_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
666 self.insert("switchStatement.bracePosition", value.to_string().into())
667 }
668
669 pub fn try_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
670 self.insert("tryStatement.bracePosition", value.to_string().into())
671 }
672
673 pub fn while_statement_brace_position(&mut self, value: BracePosition) -> &mut Self {
674 self.insert("whileStatement.bracePosition", value.to_string().into())
675 }
676
677 pub fn arguments_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
680 self.insert("arguments.preferHanging", value.to_string().into())
681 }
682
683 pub fn array_expression_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
684 self.insert("arrayExpression.preferHanging", value.to_string().into())
685 }
686
687 pub fn array_pattern_prefer_hanging(&mut self, value: bool) -> &mut Self {
688 self.insert("arrayPattern.preferHanging", value.into())
689 }
690
691 pub fn do_while_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
692 self.insert("doWhileStatement.preferHanging", value.into())
693 }
694
695 pub fn export_declaration_prefer_hanging(&mut self, value: bool) -> &mut Self {
696 self.insert("exportDeclaration.preferHanging", value.into())
697 }
698
699 pub fn extends_clause_prefer_hanging(&mut self, value: bool) -> &mut Self {
700 self.insert("extendsClause.preferHanging", value.into())
701 }
702
703 pub fn for_in_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
704 self.insert("forInStatement.preferHanging", value.into())
705 }
706
707 pub fn for_of_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
708 self.insert("forOfStatement.preferHanging", value.into())
709 }
710
711 pub fn for_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
712 self.insert("forStatement.preferHanging", value.into())
713 }
714
715 pub fn if_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
716 self.insert("ifStatement.preferHanging", value.into())
717 }
718
719 pub fn implements_clause_prefer_hanging(&mut self, value: bool) -> &mut Self {
720 self.insert("implementsClause.preferHanging", value.into())
721 }
722
723 pub fn import_declaration_prefer_hanging(&mut self, value: bool) -> &mut Self {
724 self.insert("importDeclaration.preferHanging", value.into())
725 }
726
727 pub fn jsx_attributes_prefer_hanging(&mut self, value: bool) -> &mut Self {
728 self.insert("jsxAttributes.preferHanging", value.into())
729 }
730
731 pub fn object_expression_prefer_hanging(&mut self, value: bool) -> &mut Self {
732 self.insert("objectExpression.preferHanging", value.into())
733 }
734
735 pub fn object_pattern_prefer_hanging(&mut self, value: bool) -> &mut Self {
736 self.insert("objectPattern.preferHanging", value.into())
737 }
738
739 pub fn parameters_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
740 self.insert("parameters.preferHanging", value.to_string().into())
741 }
742
743 pub fn sequence_expression_prefer_hanging(&mut self, value: bool) -> &mut Self {
744 self.insert("sequenceExpression.preferHanging", value.into())
745 }
746
747 pub fn switch_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
748 self.insert("switchStatement.preferHanging", value.into())
749 }
750
751 pub fn tuple_type_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
752 self.insert("tupleType.preferHanging", value.to_string().into())
753 }
754
755 pub fn type_literal_prefer_hanging(&mut self, value: bool) -> &mut Self {
756 self.insert("typeLiteral.preferHanging", value.into())
757 }
758
759 pub fn type_parameters_prefer_hanging(&mut self, value: PreferHanging) -> &mut Self {
760 self.insert("typeParameters.preferHanging", value.to_string().into())
761 }
762
763 pub fn union_and_intersection_type_prefer_hanging(&mut self, value: bool) -> &mut Self {
764 self.insert("unionAndIntersectionType.preferHanging", value.into())
765 }
766
767 pub fn variable_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
768 self.insert("variableStatement.preferHanging", value.into())
769 }
770
771 pub fn while_statement_prefer_hanging(&mut self, value: bool) -> &mut Self {
772 self.insert("whileStatement.preferHanging", value.into())
773 }
774
775 pub fn export_declaration_force_single_line(&mut self, value: bool) -> &mut Self {
778 self.insert("exportDeclaration.forceSingleLine", value.into())
779 }
780
781 pub fn import_declaration_force_single_line(&mut self, value: bool) -> &mut Self {
782 self.insert("importDeclaration.forceSingleLine", value.into())
783 }
784
785 pub fn export_declaration_force_multi_line(&mut self, value: ForceMultiLine) -> &mut Self {
788 self.insert("exportDeclaration.forceMultiLine", value.to_string().into())
789 }
790
791 pub fn import_declaration_force_multi_line(&mut self, value: ForceMultiLine) -> &mut Self {
792 self.insert("importDeclaration.forceMultiLine", value.to_string().into())
793 }
794
795 pub fn enum_declaration_member_spacing(&mut self, value: MemberSpacing) -> &mut Self {
798 self.insert("enumDeclaration.memberSpacing", value.to_string().into())
799 }
800
801 pub fn if_statement_next_control_flow_position(&mut self, value: NextControlFlowPosition) -> &mut Self {
804 self.insert("ifStatement.nextControlFlowPosition", value.to_string().into())
805 }
806
807 pub fn try_statement_next_control_flow_position(&mut self, value: NextControlFlowPosition) -> &mut Self {
808 self.insert("tryStatement.nextControlFlowPosition", value.to_string().into())
809 }
810
811 pub fn do_while_statement_next_control_flow_position(&mut self, value: NextControlFlowPosition) -> &mut Self {
812 self.insert("doWhileStatement.nextControlFlowPosition", value.to_string().into())
813 }
814
815 pub fn binary_expression_operator_position(&mut self, value: OperatorPosition) -> &mut Self {
818 self.insert("binaryExpression.operatorPosition", value.to_string().into())
819 }
820
821 pub fn conditional_expression_operator_position(&mut self, value: OperatorPosition) -> &mut Self {
822 self.insert("conditionalExpression.operatorPosition", value.to_string().into())
823 }
824
825 pub fn conditional_type_operator_position(&mut self, value: OperatorPosition) -> &mut Self {
826 self.insert("conditionalType.operatorPosition", value.to_string().into())
827 }
828
829 pub fn if_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
832 self.insert("ifStatement.singleBodyPosition", value.to_string().into())
833 }
834
835 pub fn for_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
836 self.insert("forStatement.singleBodyPosition", value.to_string().into())
837 }
838
839 pub fn for_in_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
840 self.insert("forInStatement.singleBodyPosition", value.to_string().into())
841 }
842
843 pub fn for_of_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
844 self.insert("forOfStatement.singleBodyPosition", value.to_string().into())
845 }
846
847 pub fn while_statement_single_body_position(&mut self, value: SameOrNextLinePosition) -> &mut Self {
848 self.insert("whileStatement.singleBodyPosition", value.to_string().into())
849 }
850
851 pub fn arguments_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
854 self.insert("arguments.trailingCommas", value.to_string().into())
855 }
856
857 pub fn parameters_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
858 self.insert("parameters.trailingCommas", value.to_string().into())
859 }
860
861 pub fn array_expression_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
862 self.insert("arrayExpression.trailingCommas", value.to_string().into())
863 }
864
865 pub fn array_pattern_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
866 self.insert("arrayPattern.trailingCommas", value.to_string().into())
867 }
868
869 pub fn enum_declaration_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
870 self.insert("enumDeclaration.trailingCommas", value.to_string().into())
871 }
872
873 pub fn export_declaration_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
874 self.insert("exportDeclaration.trailingCommas", value.to_string().into())
875 }
876
877 pub fn import_declaration_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
878 self.insert("importDeclaration.trailingCommas", value.to_string().into())
879 }
880
881 pub fn object_expression_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
882 self.insert("objectExpression.trailingCommas", value.to_string().into())
883 }
884
885 pub fn object_pattern_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
886 self.insert("objectPattern.trailingCommas", value.to_string().into())
887 }
888
889 pub fn tuple_type_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
890 self.insert("tupleType.trailingCommas", value.to_string().into())
891 }
892
893 pub fn type_literal_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
895 self.insert("typeLiteral.trailingCommas", value.to_string().into())
896 }
897
898 pub fn type_parameters_trailing_commas(&mut self, value: TrailingCommas) -> &mut Self {
899 self.insert("typeParameters.trailingCommas", value.to_string().into())
900 }
901
902 pub fn if_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
905 self.insert("ifStatement.useBraces", value.to_string().into())
906 }
907
908 pub fn for_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
909 self.insert("forStatement.useBraces", value.to_string().into())
910 }
911
912 pub fn for_in_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
913 self.insert("forInStatement.useBraces", value.to_string().into())
914 }
915
916 pub fn for_of_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
917 self.insert("forOfStatement.useBraces", value.to_string().into())
918 }
919
920 pub fn while_statement_use_braces(&mut self, value: UseBraces) -> &mut Self {
921 self.insert("whileStatement.useBraces", value.to_string().into())
922 }
923
924 pub fn array_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
927 self.insert("arrayExpression.preferSingleLine", value.into())
928 }
929
930 pub fn array_pattern_prefer_single_line(&mut self, value: bool) -> &mut Self {
931 self.insert("arrayPattern.preferSingleLine", value.into())
932 }
933
934 pub fn arguments_prefer_single_line(&mut self, value: bool) -> &mut Self {
935 self.insert("arguments.preferSingleLine", value.into())
936 }
937
938 pub fn binary_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
939 self.insert("binaryExpression.preferSingleLine", value.into())
940 }
941
942 pub fn computed_prefer_single_line(&mut self, value: bool) -> &mut Self {
943 self.insert("computed.preferSingleLine", value.into())
944 }
945
946 pub fn conditional_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
947 self.insert("conditionalExpression.preferSingleLine", value.into())
948 }
949
950 pub fn conditional_type_prefer_single_line(&mut self, value: bool) -> &mut Self {
951 self.insert("conditionalType.preferSingleLine", value.into())
952 }
953
954 pub fn decorators_prefer_single_line(&mut self, value: bool) -> &mut Self {
955 self.insert("decorators.preferSingleLine", value.into())
956 }
957
958 pub fn export_declaration_prefer_single_line(&mut self, value: bool) -> &mut Self {
959 self.insert("exportDeclaration.preferSingleLine", value.into())
960 }
961
962 pub fn for_statement_prefer_single_line(&mut self, value: bool) -> &mut Self {
963 self.insert("forStatement.preferSingleLine", value.into())
964 }
965
966 pub fn import_declaration_prefer_single_line(&mut self, value: bool) -> &mut Self {
967 self.insert("importDeclaration.preferSingleLine", value.into())
968 }
969
970 pub fn jsx_attributes_prefer_single_line(&mut self, value: bool) -> &mut Self {
971 self.insert("jsxAttributes.preferSingleLine", value.into())
972 }
973
974 pub fn jsx_element_prefer_single_line(&mut self, value: bool) -> &mut Self {
975 self.insert("jsxElement.preferSingleLine", value.into())
976 }
977
978 pub fn mapped_type_prefer_single_line(&mut self, value: bool) -> &mut Self {
979 self.insert("mappedType.preferSingleLine", value.into())
980 }
981
982 pub fn member_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
983 self.insert("memberExpression.preferSingleLine", value.into())
984 }
985
986 pub fn object_expression_prefer_single_line(&mut self, value: bool) -> &mut Self {
987 self.insert("objectExpression.preferSingleLine", value.into())
988 }
989
990 pub fn object_pattern_prefer_single_line(&mut self, value: bool) -> &mut Self {
991 self.insert("objectPattern.preferSingleLine", value.into())
992 }
993
994 pub fn parameters_prefer_single_line(&mut self, value: bool) -> &mut Self {
995 self.insert("parameters.preferSingleLine", value.into())
996 }
997
998 pub fn parentheses_prefer_single_line(&mut self, value: bool) -> &mut Self {
999 self.insert("parentheses.preferSingleLine", value.into())
1000 }
1001
1002 pub fn tuple_type_prefer_single_line(&mut self, value: bool) -> &mut Self {
1003 self.insert("tupleType.preferSingleLine", value.into())
1004 }
1005
1006 pub fn type_literal_prefer_single_line(&mut self, value: bool) -> &mut Self {
1007 self.insert("typeLiteral.preferSingleLine", value.into())
1008 }
1009
1010 pub fn type_parameters_prefer_single_line(&mut self, value: bool) -> &mut Self {
1011 self.insert("typeParameters.preferSingleLine", value.into())
1012 }
1013
1014 pub fn union_and_intersection_type_prefer_single_line(&mut self, value: bool) -> &mut Self {
1015 self.insert("unionAndIntersectionType.preferSingleLine", value.into())
1016 }
1017
1018 pub fn variable_statement_prefer_single_line(&mut self, value: bool) -> &mut Self {
1019 self.insert("variableStatement.preferSingleLine", value.into())
1020 }
1021
1022 pub fn arguments_space_around(&mut self, value: bool) -> &mut Self {
1025 self.insert("arguments.spaceAround", value.into())
1026 }
1027
1028 pub fn array_expression_space_around(&mut self, value: bool) -> &mut Self {
1029 self.insert("arrayExpression.spaceAround", value.into())
1030 }
1031
1032 pub fn array_pattern_space_around(&mut self, value: bool) -> &mut Self {
1033 self.insert("arrayPattern.spaceAround", value.into())
1034 }
1035
1036 pub fn catch_clause_space_around(&mut self, value: bool) -> &mut Self {
1037 self.insert("catchClause.spaceAround", value.into())
1038 }
1039
1040 pub fn do_while_statement_space_around(&mut self, value: bool) -> &mut Self {
1041 self.insert("doWhileStatement.spaceAround", value.into())
1042 }
1043
1044 pub fn for_in_statement_space_around(&mut self, value: bool) -> &mut Self {
1045 self.insert("forInStatement.spaceAround", value.into())
1046 }
1047
1048 pub fn for_of_statement_space_around(&mut self, value: bool) -> &mut Self {
1049 self.insert("forOfStatement.spaceAround", value.into())
1050 }
1051
1052 pub fn for_statement_space_around(&mut self, value: bool) -> &mut Self {
1053 self.insert("forStatement.spaceAround", value.into())
1054 }
1055
1056 pub fn if_statement_space_around(&mut self, value: bool) -> &mut Self {
1057 self.insert("ifStatement.spaceAround", value.into())
1058 }
1059
1060 pub fn parameters_space_around(&mut self, value: bool) -> &mut Self {
1061 self.insert("parameters.spaceAround", value.into())
1062 }
1063
1064 pub fn paren_expression_space_around(&mut self, value: bool) -> &mut Self {
1065 self.insert("parenExpression.spaceAround", value.into())
1066 }
1067
1068 pub fn switch_statement_space_around(&mut self, value: bool) -> &mut Self {
1069 self.insert("switchStatement.spaceAround", value.into())
1070 }
1071
1072 pub fn tuple_type_space_around(&mut self, value: bool) -> &mut Self {
1073 self.insert("tupleType.spaceAround", value.into())
1074 }
1075
1076 pub fn while_statement_space_around(&mut self, value: bool) -> &mut Self {
1077 self.insert("whileStatement.spaceAround", value.into())
1078 }
1079
1080 #[cfg(test)]
1081 pub(super) fn get_inner_config(&self) -> ConfigKeyMap {
1082 self.config.clone()
1083 }
1084
1085 fn insert(&mut self, name: &str, value: ConfigKeyValue) -> &mut Self {
1086 self.config.insert(String::from(name), value);
1087 self
1088 }
1089}
1090
1091#[cfg(test)]
1092mod tests {
1093 use super::*;
1094
1095 #[test]
1096 fn check_all_values_set() {
1097 let mut config = ConfigurationBuilder::new();
1098 config
1099 .new_line_kind(NewLineKind::Auto)
1100 .line_width(80)
1101 .use_tabs(false)
1102 .indent_width(4)
1103 .quote_style(QuoteStyle::AlwaysDouble)
1105 .jsx_quote_style(JsxQuoteStyle::PreferSingle)
1106 .jsx_multi_line_parens(JsxMultiLineParens::Never)
1107 .jsx_force_new_lines_surrounding_content(true)
1108 .jsx_bracket_position(SameOrNextLinePosition::Maintain)
1109 .jsx_opening_element_bracket_position(SameOrNextLinePosition::Maintain)
1110 .jsx_self_closing_element_bracket_position(SameOrNextLinePosition::Maintain)
1111 .semi_colons(SemiColons::Prefer)
1112 .brace_position(BracePosition::NextLine)
1113 .next_control_flow_position(NextControlFlowPosition::SameLine)
1114 .operator_position(OperatorPosition::SameLine)
1115 .single_body_position(SameOrNextLinePosition::SameLine)
1116 .trailing_commas(TrailingCommas::Never)
1117 .file_indent_level(1)
1118 .use_braces(UseBraces::WhenNotSingleLine)
1119 .quote_props(QuoteProps::AsNeeded)
1120 .prefer_hanging(false)
1121 .arrow_function_use_parentheses(UseParentheses::Maintain)
1123 .binary_expression_line_per_expression(false)
1124 .conditional_expression_line_per_expression(true)
1125 .member_expression_line_per_expression(false)
1126 .type_literal_separator_kind(SemiColonOrComma::Comma)
1127 .type_literal_separator_kind_single_line(SemiColonOrComma::Comma)
1128 .type_literal_separator_kind_multi_line(SemiColonOrComma::Comma)
1129 .module_sort_import_declarations(SortOrder::Maintain)
1131 .module_sort_export_declarations(SortOrder::Maintain)
1132 .import_declaration_sort_named_imports(SortOrder::Maintain)
1133 .export_declaration_sort_named_exports(SortOrder::Maintain)
1134 .import_declaration_sort_type_only_imports(NamedTypeImportsExportsOrder::First)
1135 .export_declaration_sort_type_only_exports(NamedTypeImportsExportsOrder::None)
1136 .ignore_node_comment_text("ignore")
1138 .ignore_file_comment_text("ignore-file")
1139 .arrow_function_brace_position(BracePosition::NextLine)
1141 .class_declaration_brace_position(BracePosition::NextLine)
1142 .class_expression_brace_position(BracePosition::NextLine)
1143 .constructor_brace_position(BracePosition::NextLine)
1144 .do_while_statement_brace_position(BracePosition::NextLine)
1145 .enum_declaration_brace_position(BracePosition::NextLine)
1146 .for_statement_brace_position(BracePosition::NextLine)
1147 .for_in_statement_brace_position(BracePosition::NextLine)
1148 .for_of_statement_brace_position(BracePosition::NextLine)
1149 .get_accessor_brace_position(BracePosition::NextLine)
1150 .if_statement_brace_position(BracePosition::NextLine)
1151 .interface_declaration_brace_position(BracePosition::NextLine)
1152 .function_declaration_brace_position(BracePosition::NextLine)
1153 .function_expression_brace_position(BracePosition::NextLine)
1154 .method_brace_position(BracePosition::NextLine)
1155 .module_declaration_brace_position(BracePosition::NextLine)
1156 .set_accessor_brace_position(BracePosition::NextLine)
1157 .static_block_brace_position(BracePosition::NextLine)
1158 .switch_case_brace_position(BracePosition::NextLine)
1159 .switch_statement_brace_position(BracePosition::NextLine)
1160 .try_statement_brace_position(BracePosition::NextLine)
1161 .while_statement_brace_position(BracePosition::NextLine)
1162 .arguments_prefer_hanging(PreferHanging::OnlySingleItem)
1164 .array_expression_prefer_hanging(PreferHanging::OnlySingleItem)
1165 .array_pattern_prefer_hanging(true)
1166 .do_while_statement_prefer_hanging(true)
1167 .export_declaration_prefer_hanging(true)
1168 .extends_clause_prefer_hanging(true)
1169 .for_in_statement_prefer_hanging(true)
1170 .for_of_statement_prefer_hanging(true)
1171 .for_statement_prefer_hanging(true)
1172 .if_statement_prefer_hanging(true)
1173 .implements_clause_prefer_hanging(true)
1174 .import_declaration_prefer_hanging(true)
1175 .jsx_attributes_prefer_hanging(true)
1176 .object_expression_prefer_hanging(true)
1177 .object_pattern_prefer_hanging(true)
1178 .parameters_prefer_hanging(PreferHanging::OnlySingleItem)
1179 .sequence_expression_prefer_hanging(true)
1180 .switch_statement_prefer_hanging(true)
1181 .tuple_type_prefer_hanging(PreferHanging::OnlySingleItem)
1182 .type_literal_prefer_hanging(true)
1183 .type_parameters_prefer_hanging(PreferHanging::OnlySingleItem)
1184 .union_and_intersection_type_prefer_hanging(true)
1185 .variable_statement_prefer_hanging(true)
1186 .while_statement_prefer_hanging(true)
1187 .enum_declaration_member_spacing(MemberSpacing::Maintain)
1189 .if_statement_next_control_flow_position(NextControlFlowPosition::SameLine)
1191 .try_statement_next_control_flow_position(NextControlFlowPosition::SameLine)
1192 .do_while_statement_next_control_flow_position(NextControlFlowPosition::SameLine)
1193 .binary_expression_operator_position(OperatorPosition::SameLine)
1195 .conditional_expression_operator_position(OperatorPosition::SameLine)
1196 .conditional_type_operator_position(OperatorPosition::SameLine)
1197 .if_statement_single_body_position(SameOrNextLinePosition::SameLine)
1199 .for_statement_single_body_position(SameOrNextLinePosition::SameLine)
1200 .for_in_statement_single_body_position(SameOrNextLinePosition::SameLine)
1201 .for_of_statement_single_body_position(SameOrNextLinePosition::SameLine)
1202 .while_statement_single_body_position(SameOrNextLinePosition::SameLine)
1203 .arguments_trailing_commas(TrailingCommas::Never)
1205 .parameters_trailing_commas(TrailingCommas::Never)
1206 .array_expression_trailing_commas(TrailingCommas::Never)
1207 .array_pattern_trailing_commas(TrailingCommas::Never)
1208 .enum_declaration_trailing_commas(TrailingCommas::Never)
1209 .import_declaration_trailing_commas(TrailingCommas::Never)
1210 .export_declaration_trailing_commas(TrailingCommas::Never)
1211 .object_expression_trailing_commas(TrailingCommas::Never)
1212 .object_pattern_trailing_commas(TrailingCommas::Never)
1213 .type_parameters_trailing_commas(TrailingCommas::Never)
1214 .tuple_type_trailing_commas(TrailingCommas::Never)
1215 .type_literal_trailing_commas(TrailingCommas::Never)
1216 .if_statement_use_braces(UseBraces::Always)
1218 .for_statement_use_braces(UseBraces::Always)
1219 .for_in_statement_use_braces(UseBraces::Always)
1220 .for_of_statement_use_braces(UseBraces::Always)
1221 .while_statement_use_braces(UseBraces::Always)
1222 .array_expression_prefer_single_line(false)
1224 .array_pattern_prefer_single_line(false)
1225 .arguments_prefer_single_line(false)
1226 .binary_expression_prefer_single_line(false)
1227 .computed_prefer_single_line(false)
1228 .conditional_expression_prefer_single_line(false)
1229 .conditional_type_prefer_single_line(false)
1230 .decorators_prefer_single_line(false)
1231 .export_declaration_prefer_single_line(false)
1232 .for_statement_prefer_single_line(false)
1233 .import_declaration_prefer_single_line(false)
1234 .jsx_attributes_prefer_single_line(false)
1235 .jsx_element_prefer_single_line(false)
1236 .mapped_type_prefer_single_line(false)
1237 .member_expression_prefer_single_line(false)
1238 .object_expression_prefer_single_line(false)
1239 .object_pattern_prefer_single_line(false)
1240 .parameters_prefer_single_line(false)
1241 .parentheses_prefer_single_line(false)
1242 .tuple_type_prefer_single_line(false)
1243 .type_literal_prefer_single_line(false)
1244 .type_parameters_prefer_single_line(false)
1245 .union_and_intersection_type_prefer_single_line(false)
1246 .variable_statement_prefer_single_line(false)
1247 .export_declaration_force_single_line(true)
1249 .import_declaration_force_single_line(true)
1250 .export_declaration_force_multi_line(ForceMultiLine::Always)
1252 .import_declaration_force_multi_line(ForceMultiLine::Always)
1253 .binary_expression_space_surrounding_bitwise_and_arithmetic_operator(true)
1255 .comment_line_force_space_after_slashes(false)
1256 .construct_signature_space_after_new_keyword(true)
1257 .constructor_space_before_parentheses(true)
1258 .constructor_type_space_after_new_keyword(true)
1259 .do_while_statement_space_after_while_keyword(true)
1260 .export_declaration_space_surrounding_named_exports(true)
1261 .for_statement_space_after_for_keyword(true)
1262 .for_statement_space_after_semi_colons(true)
1263 .for_in_statement_space_after_for_keyword(true)
1264 .for_of_statement_space_after_for_keyword(true)
1265 .function_declaration_space_before_parentheses(true)
1266 .function_expression_space_before_parentheses(true)
1267 .function_expression_space_after_function_keyword(true)
1268 .get_accessor_space_before_parentheses(true)
1269 .if_statement_space_after_if_keyword(true)
1270 .import_declaration_space_surrounding_named_imports(true)
1271 .jsx_expression_container_space_surrounding_expression(true)
1272 .jsx_self_closing_element_space_before_slash(true)
1273 .method_space_before_parentheses(true)
1274 .object_expression_space_surrounding_properties(false)
1275 .object_pattern_space_surrounding_properties(false)
1276 .set_accessor_space_before_parentheses(true)
1277 .space_surrounding_properties(false)
1278 .tagged_template_space_before_literal(false)
1279 .type_annotation_space_before_colon(true)
1280 .type_assertion_space_before_expression(true)
1281 .type_literal_space_surrounding_properties(false)
1282 .while_statement_space_after_while_keyword(true)
1283 .arguments_space_around(true)
1285 .array_expression_space_around(true)
1286 .array_pattern_space_around(true)
1287 .catch_clause_space_around(true)
1288 .do_while_statement_space_around(true)
1289 .for_in_statement_space_around(true)
1290 .for_of_statement_space_around(true)
1291 .for_statement_space_around(true)
1292 .if_statement_space_around(true)
1293 .parameters_space_around(true)
1294 .paren_expression_space_around(true)
1295 .switch_statement_space_around(true)
1296 .tuple_type_space_around(true)
1297 .while_statement_space_around(true);
1298
1299 let inner_config = config.get_inner_config();
1300 assert_eq!(inner_config.len(), 182);
1301 let diagnostics = resolve_config(inner_config, &Default::default()).diagnostics;
1302 assert_eq!(diagnostics.len(), 0);
1303 }
1304}