The .editorconfig file provided in this repo contains opinionated settings. Feel free to use as is or update to your liking.
For descriptions and examples of the rules in the editor config, see below
(Includes Table of Content)
- 1. indent_size
- 2. indent_style
- 3. tab_width
- 4. end_of_line
- 5. insert_final_newline
- 6. dotnet_separate_import_directive_groups
- 7. dotnet_sort_system_directives_first
- 8. file_header_template
- 9. dotnet_style_qualification_for_event
- 10. dotnet_style_qualification_for_field
- 11. dotnet_style_qualification_for_method
- 12. dotnet_style_qualification_for_property
- 13. dotnet_style_predefined_type_for_locals_parameters_members
- 14. dotnet_style_predefined_type_for_member_access
- 15. dotnet_style_parentheses_in_arithmetic_binary_operators
- 16. dotnet_style_parentheses_in_other_binary_operators
- 17. dotnet_style_parentheses_in_other_operators
- 18. dotnet_style_parentheses_in_relational_binary_operators
- 19. dotnet_style_require_accessibility_modifiers
- 20. dotnet_style_coalesce_expression
- 21. dotnet_style_collection_initializer
- 22. dotnet_style_explicit_tuple_names
- 23. dotnet_style_namespace_match_folder
- 24. dotnet_style_null_propagation
- 25. dotnet_style_object_initializer
- 26. dotnet_style_operator_placement_when_wrapping
- 27. dotnet_style_prefer_auto_properties
- 28. dotnet_style_prefer_collection_expression
- 29. dotnet_style_prefer_compound_assignment
- 30. dotnet_style_prefer_conditional_expression_over_assignment
- 31. dotnet_style_prefer_conditional_expression_over_return
- 32. dotnet_style_prefer_foreach_explicit_cast_in_source
- 33. dotnet_style_prefer_inferred_anonymous_type_member_names
- 34. dotnet_style_prefer_inferred_tuple_names
- 35. dotnet_style_prefer_is_null_check_over_reference_equality_method
- 36. dotnet_style_prefer_simplified_boolean_expressions
- 37. dotnet_style_prefer_simplified_interpolation
- 38. dotnet_style_readonly_field
- 39. dotnet_code_quality_unused_parameters
- 40. dotnet_remove_unnecessary_suppression_exclusions
- 41. dotnet_style_allow_multiple_blank_lines_experimental
- 42. dotnet_style_allow_statement_immediately_after_block_experimental
- 43. csharp_style_var_elsewhere
- 44. csharp_style_var_for_built_in_types
- 45. csharp_style_var_when_type_is_apparent
- 46. csharp_style_expression_bodied_accessors
- 47. csharp_style_expression_bodied_constructors
- 48. csharp_style_expression_bodied_indexers
- 49. csharp_style_expression_bodied_lambdas
- 50. csharp_style_expression_bodied_local_functions
- 51. csharp_style_expression_bodied_methods
- 52. csharp_style_expression_bodied_operators
- 53. csharp_style_expression_bodied_properties
- 54. csharp_style_pattern_matching_over_as_with_null_check
- 55. csharp_style_pattern_matching_over_is_with_cast_check
- 56. csharp_style_prefer_extended_property_pattern
- 57. csharp_style_prefer_not_pattern
- 58. csharp_style_prefer_pattern_matching
- 59. csharp_style_prefer_switch_expression
- 60. csharp_style_conditional_delegate_call
- 61. csharp_prefer_static_anonymous_function
- 62. csharp_prefer_static_local_function
- 63. csharp_preferred_modifier_order
- 64. csharp_style_prefer_readonly_struct
- 65. csharp_style_prefer_readonly_struct_member
- 66. csharp_prefer_braces
- 67. csharp_prefer_simple_using_statement
- 68. csharp_style_namespace_declarations
- 69. csharp_style_prefer_method_group_conversion
- 70. csharp_style_prefer_primary_constructors
- 71. csharp_style_prefer_top_level_statements
- 72. csharp_prefer_simple_default_expression
- 73. csharp_style_deconstructed_variable_declaration
- 74. csharp_style_implicit_object_creation_when_type_is_apparent
- 75. csharp_style_inlined_variable_declaration
- 76. csharp_style_prefer_index_operator
- 77. csharp_style_prefer_local_over_anonymous_function
- 78. csharp_style_prefer_null_check_over_type_check
- 79. csharp_style_prefer_range_operator
- 80. csharp_style_prefer_tuple_swap
- 81. csharp_style_prefer_utf8_string_literals
- 82. csharp_style_throw_expression
- 83. csharp_style_unused_value_assignment_preference
- 84. csharp_style_unused_value_expression_statement_preference
- 85. csharp_using_directive_placement
- 86. csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental
- 87. csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental
- 88. csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental
- 89. csharp_style_allow_blank_lines_between_consecutive_braces_experimental
- 90. csharp_style_allow_embedded_statements_on_same_line_experimental
- 91. csharp_new_line_before_catch
- 92. csharp_new_line_before_else
- 93. csharp_new_line_before_finally
- 94. csharp_new_line_before_members_in_anonymous_types
- 95. csharp_new_line_before_members_in_object_initializers
- 96. csharp_new_line_before_open_brace
- 97. csharp_new_line_between_query_expression_clauses
- 98. csharp_indent_block_contents
- 99. csharp_indent_braces
- 100. csharp_indent_case_contents
- 101. csharp_indent_case_contents_when_block
- 102. csharp_indent_labels
- 103. csharp_indent_switch_labels
- 104. csharp_space_after_cast
- 105. csharp_space_after_colon_in_inheritance_clause
- 106. csharp_space_after_comma
- 107. csharp_space_after_dot
- 108. csharp_space_after_keywords_in_control_flow_statements
- 109. csharp_space_after_semicolon_in_for_statement
- 110. csharp_space_around_binary_operators
- 111. csharp_space_around_declaration_statements
- 112. csharp_space_before_colon_in_inheritance_clause
- 113. csharp_space_before_comma
- 114. csharp_space_before_dot
- 115. csharp_space_before_open_square_brackets
- 116. csharp_space_before_semicolon_in_for_statement
- 117. csharp_space_between_empty_square_brackets
- 118. csharp_space_between_method_call_empty_parameter_list_parentheses
- 119. csharp_space_between_method_call_name_and_opening_parenthesis
- 120. csharp_space_between_method_call_parameter_list_parentheses
- 121. csharp_space_between_method_declaration_empty_parameter_list_parentheses
- 122. csharp_space_between_method_declaration_name_and_open_parenthesis
- 123. csharp_space_between_method_declaration_parameter_list_parentheses
- 124. csharp_space_between_parentheses
- 125. csharp_space_between_square_brackets
- 126. csharp_preserve_single_line_blocks
- 127. csharp_preserve_single_line_statements
- 128. dotnet_naming_rule.interface_should_be_begins_with_i
- 129. dotnet_naming_rule.types_should_be_pascal_case
- 130. dotnet_naming_rule.non_field_members_should_be_pascal_case
- 131. trim_trailing_whitespace
- 132. dotnet_diagnostic.IDE0005.severity
- 133. dotnet_diagnostic.IDE1006.severity
- 134. dotnet_diagnostic.CS8019.severity
- 135. dotnet_diagnostic.IDE0079.severity
- 136. dotnet_diagnostic.IDE0130.severity
- 137. dotnet_diagnostic.CS1591.severity
- 138. csharp_prefer_system_threading_lock
Description: Defines the number of spaces used for each indentation level.
Description: Defines whether to use spaces or tabs for indentation.
Description: Sets the number of columns used to represent a tab character if indent_style=tab
.
Description: Sets the line ending character(s) to use (e.g., crlf
for Windows).
Description: Specifies whether to ensure the file ends with a newline.
Description: Controls whether using directives are separated into groups by blank lines.
Description: Enforces whether 'System' namespaces come first in usings.
Description: Controls the file header text inserted in new files.
Description: Enforces use of this.
qualifier for events.
Examples
When True
this.eventHandler?.Invoke(this, EventArgs.Empty);
When False
eventHandler?.Invoke(this, EventArgs.Empty);
Description: Enforces use of this.
qualifier for fields.
Examples
When True
this.myField = 10;
When False
myField = 10;
Description: Enforces use of this.
qualifier for methods.
Examples
When True
this.DoSomething();
When False
DoSomething();
Description: Enforces use of this.
qualifier for properties.
Examples
When True
this.MyProperty = 5;
When False
MyProperty = 5;
Description: Prefers language keywords (e.g., int
) over BCL types (e.g., Int32
).
Examples
When True
int x = 0;
When False
Int32 x = 0;
Description: Prefers language keywords when accessing static members.
Examples
When True
string.Empty;
When False
String.Empty;
Description: Enforces parentheses around arithmetic expressions for clarity.
Examples
Option 1
(a + b) * c;
Option 2
a + b * c;
Description: Enforces parentheses for non-arithmetic binary operators.
Examples
Option 1
(x & y) == 0;
Option 2
x & y == 0;
Description: Controls parentheses usage for cast/unary operators.
Examples
Option 1
(int)x + 1;
Option 2
(int)x + (1);
Description: Enforces parentheses around relational operators.
Examples
Option 1
(a < b) == true;
Option 2
a < b == true;
Description: Enforces accessibility keywords on members.
Examples
When True
public void MyMethod() { }
When False
void MyMethod() { }
Description: Prefers ??
operator over conditional expressions for null checks.
Examples
When True
var result = value ?? "default";
When False
var result = value != null ? value : "default";
Description: Enforces using collection initializers.
Examples
When True
var list = new List<int> { 1, 2, 3 };
When False
var list = new List<int>();
list.Add(1);
list.Add(2);
list.Add(3);
Description: Ensures tuple elements have explicit names.
Examples
When True
(int Id, string Name) person = (1, "John");
When False
(int, string) person = (1, "John");
Description: Enforces that namespaces match the folder structure.
Examples
When True
// File: MyProject/Utilities/Logger.cs
namespace MyProject.Utilities;
When False
// File: MyProject/Utilities/Logger.cs
namespace SomeRandomName;
Description: Prefers ?.
operator over explicit null checks.
Examples
When True
var length = str?.Length;
When False
var length = str == null ? 0 : str.Length;
Description: Enforces using object initializers.
Examples
When True
var person = new Person { Name = "Alice", Age = 30 };
When False
var person = new Person();
person.Name = "Alice";
person.Age = 30;
Description: Sets operator placement when wrapping lines.
Examples
Option 1 (beginning_of_line):
var sum = a
+ b
+ c;
Option 2 (end_of_line):
var sum = a +
b +
c;
Description: Prefers auto-properties over explicit backing fields.
Examples
When True
public int Age { get; set; }
When False
private int _age;
public int Age { get => _age; set => _age = value; }
Description: Prefers collection expressions (e.g., [1, 2, 3]
).
Examples
Option 1
var list = [1, 2, 3];
Option 2
var list = new List<int> { 1, 2, 3 };
Description: Prefers compound assignment operators (e.g., +=
).
Examples
When True
x += 1;
When False
x = x + 1;
Description: Prefers conditional expressions over if
statements for assignments.
Examples
When True
var result = condition ? "Yes" : "No";
When False
string result;
if (condition) result = "Yes";
else result = "No";
Description: Prefers conditional expressions over if
statements for returns.
Examples
When True
return condition ? "Yes" : "No";
When False
if (condition) return "Yes";
return "No";
Description: Prefers explicit casting in foreach
loops when types are known.
Examples
Option 1
foreach (string x in collectionOfObjects) { }
Option 2
foreach (var x in collectionOfObjects.Cast<string>()) { }
Description: Omits redundant property names in anonymous types.
Examples
When True
var anon = new { FirstName, LastName };
When False
var anon = new { FirstName = FirstName, LastName = LastName };
Description: Omits redundant tuple element names.
Examples
When True
var person = (firstName, lastName);
When False
var person = (firstName: firstName, lastName: lastName);
Description: Prefers is null
over ReferenceEquals(obj, null)
.
Examples
When True
if (obj is null) { }
When False
if (ReferenceEquals(obj, null)) { }
Description: Prefers simplified boolean expressions.
Examples
When True
if (flag) { }
When False
if (flag == true) { }
Description: Prefers simplified string interpolation.
Examples
When True
$"Hello {name}";
When False
$"Hello {name.ToString()}";
Description: Enforces readonly
for immutable fields.
Examples
When True
private readonly int _count = 0;
When False
private int _count = 0;
Description: Configures how unused parameters are handled.
Examples
Option 1 (align with interface):
void IInterface.Method(int unused) { }
Option 2 (warning):
void Method(int unused) { } // Warning
Description: Controls which suppressions are considered unnecessary.
Description: Controls whether multiple consecutive blank lines are allowed.
Description: Controls whether statements can follow closing braces on the same line.
Examples
When True
if (condition)
{
DoSomething();
} DoSomethingElse();
When False
if (condition)
{
DoSomething();
}
DoSomethingElse();
Description: Controls var
usage for non-built-in types.
Examples
When True
int x = 0;
When False
var x = 0;
Description: Enforces var
for built-in types.
Examples
When True
var x = 0;
When False
int x = 0;
Description: Enforces var
when the type is obvious.
Examples
When True
var stream = new MemoryStream();
When False
MemoryStream stream = new MemoryStream();
Description: Enforces expression-bodied syntax for property accessors.
Examples
When True
public int Age => _age;
When False
public int Age { get { return _age; } }
Description: Enforces expression-bodied syntax for constructors.
Examples
When True
public Person() => Name = "Unknown";
When False
public Person()
{
Name = "Unknown";
}
Description: Enforces expression-bodied syntax for indexers.
Examples
When True
public int this[int index] => _items[index];
When False
public int this[int index]
{
get { return _items[index]; }
}
Description: Enforces expression-bodied syntax for lambdas.
Examples
When True
var func = x => x * 2;
When False
var func = x =>
{
return x * 2;
};
Description: Enforces expression-bodied syntax for local functions.
Examples
When True
int Sum(int a, int b) => a + b;
When False
int Sum(int a, int b)
{
return a + b;
}
Description: Enforces expression-bodied syntax for methods.
Examples
When True
public int GetValue() => 42;
When False
public int GetValue()
{
return 42;
}
Description: Enforces expression-bodied syntax for operator overloads.
Examples
When True
public static Vector operator +(Vector a, Vector b) => new(a.X + b.X, a.Y + b.Y);
When False
public static Vector operator +(Vector a, Vector b)
{
return new Vector(a.X + b.X, a.Y + b.Y);
}
Description: Enforces expression-bodied syntax for properties.
Examples
When True
public int MyProperty => _myField;
When False
public int MyProperty
{
get { return _myField; }
}
Description: Prefers pattern matching over as
+ null check.
Examples
When True
if (obj is MyClass c) { }
When False
var c = obj as MyClass;
if (c != null) { }