1 // Copyright Brian Schott 2015. 2 // Distributed under the Boost Software License, Version 1.0. 3 // (See accompanying file LICENSE.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 6 module dfmt.config; 7 8 import dfmt.editorconfig; 9 10 /// Brace styles 11 enum BraceStyle 12 { 13 unspecified, 14 /// $(LINK https://en.wikipedia.org/wiki/Indent_style#Allman_style) 15 allman, 16 /// $(LINK https://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS) 17 otbs, 18 /// $(LINK https://en.wikipedia.org/wiki/Indent_style#Variant:_Stroustrup) 19 stroustrup 20 } 21 22 enum TemplateConstraintStyle 23 { 24 unspecified, 25 conditional_newline_indent, 26 conditional_newline, 27 always_newline, 28 always_newline_indent 29 } 30 31 /// Configuration options for formatting 32 struct Config 33 { 34 /// 35 OptionalBoolean dfmt_align_switch_statements; 36 /// 37 BraceStyle dfmt_brace_style; 38 /// 39 OptionalBoolean dfmt_outdent_attributes; 40 /// 41 int dfmt_soft_max_line_length = -1; 42 /// 43 OptionalBoolean dfmt_space_after_cast; 44 /// 45 OptionalBoolean dfmt_space_after_keywords; 46 /// 47 OptionalBoolean dfmt_space_before_function_parameters; 48 /// 49 OptionalBoolean dfmt_split_operator_at_line_end; 50 /// 51 OptionalBoolean dfmt_selective_import_space; 52 /// 53 OptionalBoolean dfmt_compact_labeled_statements; 54 /// 55 TemplateConstraintStyle dfmt_template_constraint_style; 56 /// 57 OptionalBoolean dfmt_single_template_constraint_indent; 58 59 mixin StandardEditorConfigFields; 60 61 /** 62 * Initializes the standard EditorConfig properties with default values that 63 * make sense for D code. 64 */ 65 void initializeWithDefaults() 66 { 67 pattern = "*.d"; 68 end_of_line = EOL.lf; 69 indent_style = IndentStyle.space; 70 indent_size = 4; 71 tab_width = 4; 72 max_line_length = 120; 73 dfmt_align_switch_statements = OptionalBoolean.t; 74 dfmt_brace_style = BraceStyle.allman; 75 dfmt_outdent_attributes = OptionalBoolean.t; 76 dfmt_soft_max_line_length = 80; 77 dfmt_space_after_cast = OptionalBoolean.t; 78 dfmt_space_after_keywords = OptionalBoolean.t; 79 dfmt_space_before_function_parameters = OptionalBoolean.f; 80 dfmt_split_operator_at_line_end = OptionalBoolean.f; 81 dfmt_selective_import_space = OptionalBoolean.t; 82 dfmt_compact_labeled_statements = OptionalBoolean.t; 83 dfmt_template_constraint_style = TemplateConstraintStyle.conditional_newline_indent; 84 dfmt_single_template_constraint_indent = OptionalBoolean.f; 85 } 86 87 /** 88 * Returns: 89 * true if the configuration is valid 90 */ 91 bool isValid() 92 { 93 import std.stdio : stderr; 94 95 if (dfmt_soft_max_line_length > max_line_length) 96 { 97 stderr.writefln("Column hard limit (%d) must be greater than or equal to column soft limit (%d)", 98 max_line_length, dfmt_soft_max_line_length); 99 return false; 100 } 101 return true; 102 } 103 }