Skip to content

rodnyjoseph200/EditorConfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

.NET EditorConfig

Welcome

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)


Table of Content


Rules

1. indent_size

Description: Defines the number of spaces used for each indentation level.


2. indent_style

Description: Defines whether to use spaces or tabs for indentation.


3. tab_width

Description: Sets the number of columns used to represent a tab character if indent_style=tab.


4. end_of_line

Description: Sets the line ending character(s) to use (e.g., crlf for Windows).


5. insert_final_newline

Description: Specifies whether to ensure the file ends with a newline.


6. dotnet_separate_import_directive_groups

Description: Controls whether using directives are separated into groups by blank lines.


7. dotnet_sort_system_directives_first

Description: Enforces whether 'System' namespaces come first in usings.


8. file_header_template

Description: Controls the file header text inserted in new files.


9. dotnet_style_qualification_for_event

Description: Enforces use of this. qualifier for events.

Examples
When True

this.eventHandler?.Invoke(this, EventArgs.Empty);  

When False

eventHandler?.Invoke(this, EventArgs.Empty);  

10. dotnet_style_qualification_for_field

Description: Enforces use of this. qualifier for fields.

Examples
When True

this.myField = 10;  

When False

myField = 10;  

11. dotnet_style_qualification_for_method

Description: Enforces use of this. qualifier for methods.

Examples
When True

this.DoSomething();  

When False

DoSomething();  

12. dotnet_style_qualification_for_property

Description: Enforces use of this. qualifier for properties.

Examples
When True

this.MyProperty = 5;  

When False

MyProperty = 5;  

13. dotnet_style_predefined_type_for_locals_parameters_members

Description: Prefers language keywords (e.g., int) over BCL types (e.g., Int32).

Examples
When True

int x = 0;  

When False

Int32 x = 0;  

14. dotnet_style_predefined_type_for_member_access

Description: Prefers language keywords when accessing static members.

Examples
When True

string.Empty;  

When False

String.Empty;  

15. dotnet_style_parentheses_in_arithmetic_binary_operators

Description: Enforces parentheses around arithmetic expressions for clarity.

Examples
Option 1

(a + b) * c;  

Option 2

a + b * c;  

16. dotnet_style_parentheses_in_other_binary_operators

Description: Enforces parentheses for non-arithmetic binary operators.

Examples
Option 1

(x & y) == 0;  

Option 2

x & y == 0;  

17. dotnet_style_parentheses_in_other_operators

Description: Controls parentheses usage for cast/unary operators.

Examples
Option 1

(int)x + 1;  

Option 2

(int)x + (1);  

18. dotnet_style_parentheses_in_relational_binary_operators

Description: Enforces parentheses around relational operators.

Examples
Option 1

(a < b) == true;  

Option 2

a < b == true;  

19. dotnet_style_require_accessibility_modifiers

Description: Enforces accessibility keywords on members.

Examples
When True

public void MyMethod() { }  

When False

void MyMethod() { }  

20. dotnet_style_coalesce_expression

Description: Prefers ?? operator over conditional expressions for null checks.

Examples
When True

var result = value ?? "default";  

When False

var result = value != null ? value : "default";  

21. dotnet_style_collection_initializer

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);  

22. dotnet_style_explicit_tuple_names

Description: Ensures tuple elements have explicit names.

Examples
When True

(int Id, string Name) person = (1, "John");  

When False

(int, string) person = (1, "John");  

23. dotnet_style_namespace_match_folder

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;  

24. dotnet_style_null_propagation

Description: Prefers ?. operator over explicit null checks.

Examples
When True

var length = str?.Length;  

When False

var length = str == null ? 0 : str.Length;  

25. dotnet_style_object_initializer

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;  

26. dotnet_style_operator_placement_when_wrapping

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;  

27. dotnet_style_prefer_auto_properties

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; }  

28. dotnet_style_prefer_collection_expression

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 };  

29. dotnet_style_prefer_compound_assignment

Description: Prefers compound assignment operators (e.g., +=).

Examples
When True

x += 1;  

When False

x = x + 1;  

30. dotnet_style_prefer_conditional_expression_over_assignment

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";  

31. dotnet_style_prefer_conditional_expression_over_return

Description: Prefers conditional expressions over if statements for returns.

Examples
When True

return condition ? "Yes" : "No";  

When False

if (condition) return "Yes";  
return "No";  

32. dotnet_style_prefer_foreach_explicit_cast_in_source

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>()) { }  

33. dotnet_style_prefer_inferred_anonymous_type_member_names

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 };  

34. dotnet_style_prefer_inferred_tuple_names

Description: Omits redundant tuple element names.

Examples
When True

var person = (firstName, lastName);  

When False

var person = (firstName: firstName, lastName: lastName);  

35. dotnet_style_prefer_is_null_check_over_reference_equality_method

Description: Prefers is null over ReferenceEquals(obj, null).

Examples
When True

if (obj is null) { }  

When False

if (ReferenceEquals(obj, null)) { }  

36. dotnet_style_prefer_simplified_boolean_expressions

Description: Prefers simplified boolean expressions.

Examples
When True

if (flag) { }  

When False

if (flag == true) { }  

37. dotnet_style_prefer_simplified_interpolation

Description: Prefers simplified string interpolation.

Examples
When True

$"Hello {name}";  

When False

$"Hello {name.ToString()}";  

38. dotnet_style_readonly_field

Description: Enforces readonly for immutable fields.

Examples
When True

private readonly int _count = 0;  

When False

private int _count = 0;  

39. dotnet_code_quality_unused_parameters

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  

40. dotnet_remove_unnecessary_suppression_exclusions

Description: Controls which suppressions are considered unnecessary.


41. dotnet_style_allow_multiple_blank_lines_experimental

Description: Controls whether multiple consecutive blank lines are allowed.


42. dotnet_style_allow_statement_immediately_after_block_experimental

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();  

43. csharp_style_var_elsewhere

Description: Controls var usage for non-built-in types.

Examples
When True

int x = 0;  

When False

var x = 0;  

44. csharp_style_var_for_built_in_types

Description: Enforces var for built-in types.

Examples
When True

var x = 0;  

When False

int x = 0;  

45. csharp_style_var_when_type_is_apparent

Description: Enforces var when the type is obvious.

Examples
When True

var stream = new MemoryStream();  

When False

MemoryStream stream = new MemoryStream();  

46. csharp_style_expression_bodied_accessors

Description: Enforces expression-bodied syntax for property accessors.

Examples
When True

public int Age => _age;  

When False

public int Age { get { return _age; } }  

47. csharp_style_expression_bodied_constructors

Description: Enforces expression-bodied syntax for constructors.

Examples
When True

public Person() => Name = "Unknown";  

When False

public Person()  
{  
    Name = "Unknown";  
}  

48. csharp_style_expression_bodied_indexers

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]; }  
}  

49. csharp_style_expression_bodied_lambdas

Description: Enforces expression-bodied syntax for lambdas.

Examples
When True

var func = x => x * 2;  

When False

var func = x =>  
{  
    return x * 2;  
};  

50. csharp_style_expression_bodied_local_functions

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;  
}  

51. csharp_style_expression_bodied_methods

Description: Enforces expression-bodied syntax for methods.

Examples
When True

public int GetValue() => 42;  

When False

public int GetValue()  
{  
    return 42;  
}  

52. csharp_style_expression_bodied_operators

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);  
}  

53. csharp_style_expression_bodied_properties

Description: Enforces expression-bodied syntax for properties.

Examples
When True

public int MyProperty => _myField;  

When False

public int MyProperty  
{  
    get { return _myField; }  
}  

54. csharp_style_pattern_matching_over_as_with_null_check

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) { }  

55. csharp_style_pattern_matching_over_is_with_cast_check

About

.NET EditorConfig

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published