|
1 | 1 | ---
|
2 | 2 | title: .NET coding convention settings For EditorConfig
|
3 |
| -ms.date: 02/21/2020 |
| 3 | +ms.date: 03/17/2020 |
4 | 4 | ms.topic: reference
|
5 | 5 | helpviewer_keywords:
|
6 | 6 | - coding conventions [EditorConfig]
|
@@ -43,158 +43,204 @@ There are three supported .NET coding convention categories:
|
43 | 43 | To help you get started, here is an example *.editorconfig* file with the default options. In Visual Studio, you can generate this file and save it to a project at **Tools** > **Options** > **Text Editor** > [**C#** or **Basic**] > **Code Style** > **General**. Then, click the **Generate .editorconfig file from settings** button. For more information, see [Code style preferences](code-styles-and-code-cleanup.md).
|
44 | 44 |
|
45 | 45 | ```ini
|
46 |
| -############################### |
47 |
| -# Core EditorConfig Options # |
48 |
| -############################### |
49 |
| - |
| 46 | +# Remove the line below if you want to inherit .editorconfig settings from higher directories |
50 | 47 | root = true
|
51 | 48 |
|
52 |
| -# All files |
53 |
| -[*] |
54 |
| -indent_style = space |
| 49 | +# C# files |
| 50 | +[*.cs] |
55 | 51 |
|
56 |
| -# Code files |
57 |
| -[*.{cs,csx,vb,vbx}] |
| 52 | +#### Core EditorConfig Options #### |
| 53 | + |
| 54 | +# Indentation and spacing |
58 | 55 | indent_size = 4
|
59 |
| -insert_final_newline = true |
60 |
| -charset = utf-8-bom |
| 56 | +indent_style = space |
| 57 | +tab_width = 4 |
61 | 58 |
|
62 |
| -############################### |
63 |
| -# .NET Coding Conventions # |
64 |
| -############################### |
| 59 | +# New line preferences |
| 60 | +end_of_line = crlf |
| 61 | +insert_final_newline = false |
65 | 62 |
|
66 |
| -[*.{cs,vb}] |
| 63 | +#### .NET Coding Conventions #### |
67 | 64 |
|
68 | 65 | # Organize usings
|
69 |
| -dotnet_sort_system_directives_first = true |
| 66 | +dotnet_separate_import_directive_groups = false |
| 67 | +dotnet_sort_system_directives_first = false |
70 | 68 |
|
71 |
| -# this. preferences |
| 69 | +# this. and Me. preferences |
| 70 | +dotnet_style_qualification_for_event = false:silent |
72 | 71 | dotnet_style_qualification_for_field = false:silent
|
73 |
| -dotnet_style_qualification_for_property = false:silent |
74 | 72 | dotnet_style_qualification_for_method = false:silent
|
75 |
| -dotnet_style_qualification_for_event = false:silent |
| 73 | +dotnet_style_qualification_for_property = false:silent |
76 | 74 |
|
77 | 75 | # Language keywords vs BCL types preferences
|
78 | 76 | dotnet_style_predefined_type_for_locals_parameters_members = true:silent
|
79 | 77 | dotnet_style_predefined_type_for_member_access = true:silent
|
80 | 78 |
|
81 | 79 | # Parentheses preferences
|
82 | 80 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
|
83 |
| -dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent |
84 | 81 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
|
85 | 82 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
|
| 83 | +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent |
86 | 84 |
|
87 | 85 | # Modifier preferences
|
88 | 86 | dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
|
89 |
| -dotnet_style_readonly_field = true:suggestion |
90 | 87 |
|
91 | 88 | # Expression-level preferences
|
92 |
| -dotnet_style_object_initializer = true:suggestion |
| 89 | +dotnet_style_coalesce_expression = true:suggestion |
93 | 90 | dotnet_style_collection_initializer = true:suggestion
|
94 | 91 | dotnet_style_explicit_tuple_names = true:suggestion
|
95 | 92 | dotnet_style_null_propagation = true:suggestion
|
96 |
| -dotnet_style_coalesce_expression = true:suggestion |
97 |
| -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent |
98 |
| -dotnet_style_prefer_inferred_tuple_names = true:suggestion |
99 |
| -dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion |
| 93 | +dotnet_style_object_initializer = true:suggestion |
100 | 94 | dotnet_style_prefer_auto_properties = true:silent
|
| 95 | +dotnet_style_prefer_compound_assignment = true:suggestion |
101 | 96 | dotnet_style_prefer_conditional_expression_over_assignment = true:silent
|
102 | 97 | dotnet_style_prefer_conditional_expression_over_return = true:silent
|
| 98 | +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion |
| 99 | +dotnet_style_prefer_inferred_tuple_names = true:suggestion |
| 100 | +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion |
| 101 | +dotnet_style_prefer_simplified_interpolation = true:suggestion |
103 | 102 |
|
104 |
| -############################### |
105 |
| -# Naming Conventions # |
106 |
| -############################### |
| 103 | +# Field preferences |
| 104 | +dotnet_style_readonly_field = true:suggestion |
107 | 105 |
|
108 |
| -# Style Definitions |
109 |
| -dotnet_naming_style.pascal_case_style.capitalization = pascal_case |
110 |
| -# Use PascalCase for constant fields |
111 |
| -dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion |
112 |
| -dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields |
113 |
| -dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style |
114 |
| -dotnet_naming_symbols.constant_fields.applicable_kinds = field |
115 |
| -dotnet_naming_symbols.constant_fields.applicable_accessibilities = * |
116 |
| -dotnet_naming_symbols.constant_fields.required_modifiers = const |
| 106 | +# Parameter preferences |
| 107 | +dotnet_code_quality_unused_parameters = all:suggestion |
117 | 108 |
|
118 |
| -############################### |
119 |
| -# C# Coding Conventions # |
120 |
| -############################### |
121 |
| - |
122 |
| -[*.cs] |
| 109 | +#### C# Coding Conventions #### |
123 | 110 |
|
124 | 111 | # var preferences
|
125 |
| -csharp_style_var_for_built_in_types = true:silent |
126 |
| -csharp_style_var_when_type_is_apparent = true:silent |
127 |
| -csharp_style_var_elsewhere = true:silent |
| 112 | +csharp_style_var_elsewhere = false:silent |
| 113 | +csharp_style_var_for_built_in_types = false:silent |
| 114 | +csharp_style_var_when_type_is_apparent = false:silent |
128 | 115 |
|
129 | 116 | # Expression-bodied members
|
130 |
| -csharp_style_expression_bodied_methods = false:silent |
| 117 | +csharp_style_expression_bodied_accessors = true:silent |
131 | 118 | csharp_style_expression_bodied_constructors = false:silent
|
| 119 | +csharp_style_expression_bodied_indexers = true:silent |
| 120 | +csharp_style_expression_bodied_lambdas = true:silent |
| 121 | +csharp_style_expression_bodied_local_functions = false:silent |
| 122 | +csharp_style_expression_bodied_methods = false:silent |
132 | 123 | csharp_style_expression_bodied_operators = false:silent
|
133 | 124 | csharp_style_expression_bodied_properties = true:silent
|
134 |
| -csharp_style_expression_bodied_indexers = true:silent |
135 |
| -csharp_style_expression_bodied_accessors = true:silent |
136 | 125 |
|
137 | 126 | # Pattern matching preferences
|
138 |
| -csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion |
139 | 127 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
|
| 128 | +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion |
| 129 | +csharp_style_prefer_switch_expression = true:suggestion |
140 | 130 |
|
141 | 131 | # Null-checking preferences
|
142 |
| -csharp_style_throw_expression = true:suggestion |
143 | 132 | csharp_style_conditional_delegate_call = true:suggestion
|
144 | 133 |
|
145 | 134 | # Modifier preferences
|
146 |
| -csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion |
| 135 | +csharp_prefer_static_local_function = true:suggestion |
| 136 | +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent |
147 | 137 |
|
148 |
| -# Expression-level preferences |
| 138 | +# Code-block preferences |
149 | 139 | csharp_prefer_braces = true:silent
|
150 |
| -csharp_style_deconstructed_variable_declaration = true:suggestion |
| 140 | +csharp_prefer_simple_using_statement = true:suggestion |
| 141 | + |
| 142 | +# Expression-level preferences |
151 | 143 | csharp_prefer_simple_default_expression = true:suggestion
|
152 |
| -csharp_style_pattern_local_over_anonymous_function = true:suggestion |
| 144 | +csharp_style_deconstructed_variable_declaration = true:suggestion |
153 | 145 | csharp_style_inlined_variable_declaration = true:suggestion
|
| 146 | +csharp_style_pattern_local_over_anonymous_function = true:suggestion |
| 147 | +csharp_style_prefer_index_operator = true:suggestion |
| 148 | +csharp_style_prefer_range_operator = true:suggestion |
| 149 | +csharp_style_throw_expression = true:suggestion |
| 150 | +csharp_style_unused_value_assignment_preference = discard_variable:suggestion |
| 151 | +csharp_style_unused_value_expression_statement_preference = discard_variable:silent |
154 | 152 |
|
155 |
| -############################### |
156 |
| -# C# Formatting Rules # |
157 |
| -############################### |
| 153 | +# 'using' directive preferences |
| 154 | +csharp_using_directive_placement = outside_namespace:silent |
| 155 | + |
| 156 | +#### C# Formatting Rules #### |
158 | 157 |
|
159 | 158 | # New line preferences
|
160 |
| -csharp_new_line_before_open_brace = all |
161 |
| -csharp_new_line_before_else = true |
162 | 159 | csharp_new_line_before_catch = true
|
| 160 | +csharp_new_line_before_else = true |
163 | 161 | csharp_new_line_before_finally = true
|
164 |
| -csharp_new_line_before_members_in_object_initializers = true |
165 | 162 | csharp_new_line_before_members_in_anonymous_types = true
|
| 163 | +csharp_new_line_before_members_in_object_initializers = true |
| 164 | +csharp_new_line_before_open_brace = all |
166 | 165 | csharp_new_line_between_query_expression_clauses = true
|
167 | 166 |
|
168 | 167 | # Indentation preferences
|
| 168 | +csharp_indent_block_contents = true |
| 169 | +csharp_indent_braces = false |
169 | 170 | csharp_indent_case_contents = true
|
| 171 | +csharp_indent_case_contents_when_block = true |
| 172 | +csharp_indent_labels = one_less_than_current |
170 | 173 | csharp_indent_switch_labels = true
|
171 |
| -csharp_indent_labels = flush_left |
172 | 174 |
|
173 | 175 | # Space preferences
|
174 | 176 | csharp_space_after_cast = false
|
| 177 | +csharp_space_after_colon_in_inheritance_clause = true |
| 178 | +csharp_space_after_comma = true |
| 179 | +csharp_space_after_dot = false |
175 | 180 | csharp_space_after_keywords_in_control_flow_statements = true
|
| 181 | +csharp_space_after_semicolon_in_for_statement = true |
| 182 | +csharp_space_around_binary_operators = before_and_after |
| 183 | +csharp_space_around_declaration_statements = false |
| 184 | +csharp_space_before_colon_in_inheritance_clause = true |
| 185 | +csharp_space_before_comma = false |
| 186 | +csharp_space_before_dot = false |
| 187 | +csharp_space_before_open_square_brackets = false |
| 188 | +csharp_space_before_semicolon_in_for_statement = false |
| 189 | +csharp_space_between_empty_square_brackets = false |
| 190 | +csharp_space_between_method_call_empty_parameter_list_parentheses = false |
| 191 | +csharp_space_between_method_call_name_and_opening_parenthesis = false |
176 | 192 | csharp_space_between_method_call_parameter_list_parentheses = false
|
| 193 | +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false |
| 194 | +csharp_space_between_method_declaration_name_and_open_parenthesis = false |
177 | 195 | csharp_space_between_method_declaration_parameter_list_parentheses = false
|
178 | 196 | csharp_space_between_parentheses = false
|
179 |
| -csharp_space_before_colon_in_inheritance_clause = true |
180 |
| -csharp_space_after_colon_in_inheritance_clause = true |
181 |
| -csharp_space_around_binary_operators = before_and_after |
182 |
| -csharp_space_between_method_declaration_empty_parameter_list_parentheses = false |
183 |
| -csharp_space_between_method_call_name_and_opening_parenthesis = false |
184 |
| -csharp_space_between_method_call_empty_parameter_list_parentheses = false |
| 197 | +csharp_space_between_square_brackets = false |
185 | 198 |
|
186 | 199 | # Wrapping preferences
|
187 |
| -csharp_preserve_single_line_statements = true |
188 | 200 | csharp_preserve_single_line_blocks = true
|
| 201 | +csharp_preserve_single_line_statements = true |
189 | 202 |
|
190 |
| -############################### |
191 |
| -# VB Coding Conventions # |
192 |
| -############################### |
| 203 | +#### Naming styles #### |
193 | 204 |
|
194 |
| -[*.vb] |
| 205 | +# Naming rules |
195 | 206 |
|
196 |
| -# Modifier preferences |
197 |
| -visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion |
| 207 | +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion |
| 208 | +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface |
| 209 | +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i |
| 210 | + |
| 211 | +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion |
| 212 | +dotnet_naming_rule.types_should_be_pascal_case.symbols = types |
| 213 | +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case |
| 214 | + |
| 215 | +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion |
| 216 | +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members |
| 217 | +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case |
| 218 | + |
| 219 | +# Symbol specifications |
| 220 | + |
| 221 | +dotnet_naming_symbols.interface.applicable_kinds = interface |
| 222 | +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected |
| 223 | +dotnet_naming_symbols.interface.required_modifiers = |
| 224 | + |
| 225 | +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum |
| 226 | +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected |
| 227 | +dotnet_naming_symbols.types.required_modifiers = |
| 228 | + |
| 229 | +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method |
| 230 | +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected |
| 231 | +dotnet_naming_symbols.non_field_members.required_modifiers = |
| 232 | + |
| 233 | +# Naming styles |
| 234 | + |
| 235 | +dotnet_naming_style.pascal_case.required_prefix = |
| 236 | +dotnet_naming_style.pascal_case.required_suffix = |
| 237 | +dotnet_naming_style.pascal_case.word_separator = |
| 238 | +dotnet_naming_style.pascal_case.capitalization = pascal_case |
| 239 | + |
| 240 | +dotnet_naming_style.begins_with_i.required_prefix = I |
| 241 | +dotnet_naming_style.begins_with_i.required_suffix = |
| 242 | +dotnet_naming_style.begins_with_i.word_separator = |
| 243 | +dotnet_naming_style.begins_with_i.capitalization = pascal_case |
198 | 244 | ```
|
199 | 245 |
|
200 | 246 | ## See also
|
|
0 commit comments