1
+ # Roslyn-analyzer-based code-style rules
2
+ # docs: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview?tabs=net-9
3
+ # docs: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options?source=recommendations
4
+ # docs: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/
5
+
6
+ root = true
7
+
8
+ # C# files
9
+ [* .cs ]
10
+
11
+ # ### Core EditorConfig Options ####
12
+
13
+ # Indentation and spacing
14
+ indent_size = 4
15
+ indent_style = space
16
+ tab_width = 4
17
+
18
+ # New line preferences
19
+ end_of_line = crlf
20
+ insert_final_newline = false
21
+
22
+ # ### .NET Coding Conventions ####
23
+
24
+ # Organize usings
25
+ dotnet_separate_import_directive_groups = false
26
+ dotnet_sort_system_directives_first = true :warning
27
+ file_header_template = unset
28
+
29
+ # this. and Me. preferences
30
+ dotnet_style_qualification_for_event = false
31
+ dotnet_style_qualification_for_field = false
32
+ dotnet_style_qualification_for_method = false
33
+ dotnet_style_qualification_for_property = false
34
+
35
+ # Language keywords vs BCL types preferences
36
+ dotnet_style_predefined_type_for_locals_parameters_members = true
37
+ dotnet_style_predefined_type_for_member_access = true
38
+
39
+ # Parentheses preferences
40
+ dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
41
+ dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
42
+ dotnet_style_parentheses_in_other_operators = never_if_unnecessary
43
+ dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
44
+
45
+ # Modifier preferences
46
+ dotnet_style_require_accessibility_modifiers = for_non_interface_members
47
+
48
+ # Expression-level preferences
49
+ dotnet_style_coalesce_expression = true :warning
50
+ dotnet_style_collection_initializer = true
51
+ dotnet_style_explicit_tuple_names = true
52
+ dotnet_style_namespace_match_folder = true :warning
53
+ dotnet_style_null_propagation = true :warning
54
+ dotnet_style_object_initializer = true
55
+ dotnet_style_operator_placement_when_wrapping = beginning_of_line
56
+ dotnet_style_prefer_auto_properties = true
57
+ dotnet_style_prefer_collection_expression = when_types_loosely_match
58
+ dotnet_style_prefer_compound_assignment = true :warning
59
+ dotnet_style_prefer_conditional_expression_over_assignment = true :warning
60
+ dotnet_style_prefer_conditional_expression_over_return = true :warning
61
+ dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed
62
+ dotnet_style_prefer_inferred_anonymous_type_member_names = true
63
+ dotnet_style_prefer_inferred_tuple_names = true
64
+ dotnet_style_prefer_is_null_check_over_reference_equality_method = true :warning
65
+ dotnet_style_prefer_simplified_boolean_expressions = true :warning
66
+ dotnet_style_prefer_simplified_interpolation = true :warning
67
+
68
+ # Field preferences
69
+ dotnet_style_readonly_field = true
70
+
71
+ # Parameter preferences
72
+ dotnet_code_quality_unused_parameters = all
73
+
74
+ # Suppression preferences
75
+ dotnet_remove_unnecessary_suppression_exclusions = none
76
+
77
+ # New line preferences
78
+ dotnet_style_allow_multiple_blank_lines_experimental = false :warning
79
+ dotnet_style_allow_statement_immediately_after_block_experimental = false :warning
80
+
81
+ # ### C# Coding Conventions ####
82
+
83
+ # var preferences
84
+ csharp_style_var_elsewhere = false
85
+ csharp_style_var_for_built_in_types = true :warning
86
+ csharp_style_var_when_type_is_apparent = true :warning
87
+
88
+ # Expression-bodied members
89
+ csharp_style_expression_bodied_accessors = true :silent
90
+ csharp_style_expression_bodied_constructors = true :suggestion
91
+ csharp_style_expression_bodied_indexers = true :suggestion
92
+ csharp_style_expression_bodied_lambdas = true :suggestion
93
+ csharp_style_expression_bodied_local_functions = true :suggestion
94
+ csharp_style_expression_bodied_methods = true :suggestion
95
+ csharp_style_expression_bodied_operators = true :suggestion
96
+ csharp_style_expression_bodied_properties = true :suggestion
97
+
98
+ # Pattern matching preferences
99
+ csharp_style_pattern_matching_over_as_with_null_check = true
100
+ csharp_style_pattern_matching_over_is_with_cast_check = true
101
+ csharp_style_prefer_extended_property_pattern = true
102
+ csharp_style_prefer_not_pattern = true
103
+ csharp_style_prefer_pattern_matching = true
104
+ csharp_style_prefer_switch_expression = true
105
+
106
+ # Null-checking preferences
107
+ csharp_style_conditional_delegate_call = true
108
+
109
+ # Modifier preferences
110
+ csharp_prefer_static_anonymous_function = true
111
+ csharp_prefer_static_local_function = true
112
+ csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
113
+ csharp_style_prefer_readonly_struct = true
114
+ csharp_style_prefer_readonly_struct_member = true
115
+
116
+ # Code-block preferences
117
+ csharp_prefer_braces = true :suggestion
118
+ csharp_prefer_simple_using_statement = true :warning
119
+ csharp_style_namespace_declarations = file_scoped:warning
120
+ csharp_style_prefer_method_group_conversion = true :warning
121
+ csharp_style_prefer_primary_constructors = true :suggestion
122
+ csharp_style_prefer_top_level_statements = true :suggestion
123
+
124
+ # Expression-level preferences
125
+ csharp_prefer_simple_default_expression = true :warning
126
+ csharp_style_deconstructed_variable_declaration = true
127
+ csharp_style_implicit_object_creation_when_type_is_apparent = true :warning
128
+ csharp_style_inlined_variable_declaration = true :warning
129
+ csharp_style_prefer_index_operator = true
130
+ csharp_style_prefer_local_over_anonymous_function = true :warning
131
+ csharp_style_prefer_null_check_over_type_check = true :warning
132
+ csharp_style_prefer_range_operator = true
133
+ csharp_style_prefer_tuple_swap = true :warning
134
+ csharp_style_prefer_utf8_string_literals = true :warning
135
+ csharp_style_throw_expression = true :warning
136
+ csharp_style_unused_value_assignment_preference = discard_variable:suggestion
137
+ csharp_style_unused_value_expression_statement_preference = discard_variable:warning
138
+
139
+ # 'using' directive preferences
140
+ csharp_using_directive_placement = outside_namespace:warning
141
+
142
+ # New line preferences
143
+ csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
144
+ csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true
145
+ csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true
146
+ csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
147
+ csharp_style_allow_embedded_statements_on_same_line_experimental = true
148
+
149
+ # ### C# Formatting Rules ####
150
+
151
+ # New line preferences
152
+ csharp_new_line_before_catch = true
153
+ csharp_new_line_before_else = true
154
+ csharp_new_line_before_finally = true
155
+ csharp_new_line_before_members_in_anonymous_types = true
156
+ csharp_new_line_before_members_in_object_initializers = true
157
+ csharp_new_line_before_open_brace = all
158
+ csharp_new_line_between_query_expression_clauses = true
159
+
160
+ # Indentation preferences
161
+ csharp_indent_block_contents = true
162
+ csharp_indent_braces = false
163
+ csharp_indent_case_contents = true
164
+ csharp_indent_case_contents_when_block = true
165
+ csharp_indent_labels = one_less_than_current
166
+ csharp_indent_switch_labels = true
167
+
168
+ # Space preferences
169
+ csharp_space_after_cast = false
170
+ csharp_space_after_colon_in_inheritance_clause = true
171
+ csharp_space_after_comma = true
172
+ csharp_space_after_dot = false
173
+ csharp_space_after_keywords_in_control_flow_statements = true
174
+ csharp_space_after_semicolon_in_for_statement = true
175
+ csharp_space_around_binary_operators = before_and_after
176
+ csharp_space_around_declaration_statements = false
177
+ csharp_space_before_colon_in_inheritance_clause = true
178
+ csharp_space_before_comma = false
179
+ csharp_space_before_dot = false
180
+ csharp_space_before_open_square_brackets = false
181
+ csharp_space_before_semicolon_in_for_statement = false
182
+ csharp_space_between_empty_square_brackets = false
183
+ csharp_space_between_method_call_empty_parameter_list_parentheses = false
184
+ csharp_space_between_method_call_name_and_opening_parenthesis = false
185
+ csharp_space_between_method_call_parameter_list_parentheses = false
186
+ csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
187
+ csharp_space_between_method_declaration_name_and_open_parenthesis = false
188
+ csharp_space_between_method_declaration_parameter_list_parentheses = false
189
+ csharp_space_between_parentheses = false
190
+ csharp_space_between_square_brackets = false
191
+
192
+ # Wrapping preferences
193
+ csharp_preserve_single_line_blocks = true
194
+ csharp_preserve_single_line_statements = true
195
+
196
+ # ### Naming styles ####
197
+
198
+ # Naming rules
199
+
200
+ dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
201
+ dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
202
+ dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
203
+
204
+ dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
205
+ dotnet_naming_rule.types_should_be_pascal_case.symbols = types
206
+ dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
207
+
208
+ dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
209
+ dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
210
+ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
211
+
212
+ # Symbol specifications
213
+
214
+ dotnet_naming_symbols.interface.applicable_kinds = interface
215
+ dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
216
+ dotnet_naming_symbols.interface.required_modifiers =
217
+
218
+ dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
219
+ dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
220
+ dotnet_naming_symbols.types.required_modifiers =
221
+
222
+ dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
223
+ dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
224
+ dotnet_naming_symbols.non_field_members.required_modifiers =
225
+
226
+ # Naming styles
227
+
228
+ dotnet_naming_style.pascal_case.required_prefix =
229
+ dotnet_naming_style.pascal_case.required_suffix =
230
+ dotnet_naming_style.pascal_case.word_separator =
231
+ dotnet_naming_style.pascal_case.capitalization = pascal_case
232
+
233
+ dotnet_naming_style.begins_with_i.required_prefix = I
234
+ dotnet_naming_style.begins_with_i.required_suffix =
235
+ dotnet_naming_style.begins_with_i.word_separator =
236
+ dotnet_naming_style.begins_with_i.capitalization = pascal_case
237
+
238
+ # Trim trailing whitespace at the end of lines
239
+ trim_trailing_whitespace = true:warning
240
+
241
+ # Configure unnecessary usings (from Roslyn analyzers)
242
+ dotnet_diagnostic.IDE0005.severity = warning
243
+
244
+ # Configure unnecessary usings (from C# compiler during build)
245
+ dotnet_diagnostic.CS8019.severity = silent
246
+
247
+ # Configure redundant suppression of diagnostics
248
+ dotnet_diagnostic.IDE0079.severity = warning
249
+
250
+ # Configure inconsistent nameof usage
251
+ # Examples
252
+ # throw new ArgumentNullException("parameterName"); // Hardcoded string
253
+ # throw new ArgumentNullException(nameof(parameterName)); // Recommended
254
+ dotnet_diagnostic.IDE0130.severity = suggestion
255
+
256
+ # CS1591: Missing XML comment for publicly visible type or member
257
+ dotnet_diagnostic.CS1591.severity = silent
258
+ csharp_prefer_system_threading_lock = true :suggestion
259
+
260
+ [* .{cs,vb} ]
261
+ dotnet_style_coalesce_expression = true :warning
262
+ dotnet_style_null_propagation = true :warning
263
+ dotnet_style_prefer_is_null_check_over_reference_equality_method = true :warning
264
+ dotnet_style_prefer_auto_properties = true :silent
265
+ dotnet_style_operator_placement_when_wrapping = beginning_of_line
266
+ tab_width = 4
267
+ indent_size = 4
268
+ end_of_line = crlf
269
+ dotnet_style_object_initializer = true :suggestion
270
+ dotnet_style_collection_initializer = true :suggestion
271
+ dotnet_style_prefer_simplified_boolean_expressions = true :warning
0 commit comments