Skip to content

Instantly share code, notes, and snippets.

@akamsteeg
Last active February 22, 2025 07:53
Show Gist options
  • Select an option

  • Save akamsteeg/f712a1e2aba8a6ac3be3a2ae3df18508 to your computer and use it in GitHub Desktop.

Select an option

Save akamsteeg/f712a1e2aba8a6ac3be3a2ae3df18508 to your computer and use it in GitHub Desktop.
.editorconfig for C#
root = true
[*]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
charset = utf-8
[*.cs]
# Enable "this."
dotnet_style_qualification_for_field = true:warning
dotnet_style_qualification_for_property = true:warning
dotnet_style_qualification_for_method = true:warning
dotnet_style_qualification_for_method = true:warning
# use predefined type ("int") instead of framework names ("Int32")
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
# Access modifiers
dotnet_style_require_accessibility_modifiers = for_non_interface_members:error
# Prefer "var"
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion
# Pattern match ("object is int i") over "is..as" dance
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
csharp_style_pattern_matching_over_as_with_null_check = true:warning
# Inline out variable
csharp_style_inlined_variable_declaration = true:warning
# Throw expressions
csharp_style_throw_expression = true:error
# File scoped namespaces
csharp_style_namespace_declarations = file_scoped:error
# Primary constructors
csharp_style_prefer_primary_constructors = file_scoped:warning
# Sort order of usings
dotnet_sort_system_directives_first = true
# Allow expression bodied methods, properties
dotnet_diagnostic.IDE0022.severity = none
dotnet_diagnostic.IDE0023.severity = none
dotnet_diagnostic.IDE0024.severity = none
# Suggest modern language features
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true;warning
# Newline settings
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
# File header
file_header_template = Copyright (c) Alex Kamsteeg (https://atlex.nl/) and contributors\nLicense: MIT (See LICENSE file)
# Code metrics
## Avoid excessive inheritance
dotnet_diagnostic.CA1501.severity = suggestion
## Cyclomatic complexity
dotnet_diagnostic.CA1502.severity = suggestion
## Avoid unmaintainable code
dotnet_diagnostic.CA1505.severity = suggestion
## Avoid excessive class coupling
dotnet_diagnostic.CA1506.severity = suggestion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment