Skip to content

Instantly share code, notes, and snippets.

@kuhlenh
Last active September 1, 2020 14:43
Show Gist options
  • Save kuhlenh/50fdabc40918255747c156cc1412f491 to your computer and use it in GitHub Desktop.
Save kuhlenh/50fdabc40918255747c156cc1412f491 to your computer and use it in GitHub Desktop.
Learn how to use EditorConfig for your team
# When opening a file, EditorConfig plugins look for a file named .editorconfig in the
# directory of the opened file and in every parent directory. A search for .editorconfig
# files will stop if the root filepath is reached or an EditorConfig file with root=true
#is found. (source: http://editorconfig.org/)
# top-most EditorConfig file
root = true
# Don't use tabs for indentation for any file.
[*]
indent_style = space
# Code files indent size
[*.{cs,csx,vb,vbx}]
indent_size = 4
# Xml project files indent size
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2
# Xml config files indent size
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2
# JSON files indent size
[*.json]
indent_size = 2
# Dotnet Coding Conventions
# These rules are universal across C# and VB files.
# Documentation: https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options
[*.{cs,vb}]
# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = false
# Avoid "this." and "Me." if not necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
# Suggest more modern language features when available
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
# CSharp-Specific Coding Conventions
# These rules can only be applied to .cs files
# Documentation: https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options
[*.cs]
# Do not prefer "var" everywhere
csharp_style_var_for_built_in_types = false:suggestion
csharp_style_var_when_type_is_apparent = false:suggestion
csharp_style_var_elsewhere = false:suggestion
# Prefer method-like constructs to have a block body
csharp_style_expression_bodied_methods = true:suggestion
csharp_style_expression_bodied_constructors = true:none
csharp_style_expression_bodied_operators = true:none
# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none
# Suggest more modern language features when available
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
# Naming Conventions
# These are not yet documented. You can see the PR for the general template:
# (https://github.com/dotnet/roslyn/pull/15065)
#
# In general a "naming convention" has these three properties:
# dotnet_naming_rule.<your naming rule title>.severity = none, suggestion, warning, or error
# dotnet_naming_rule.<your naming rule title>.symbols = <your symbols title>
# dotnet_naming_rule.<your naming rule title>.style = <your style title>
#
# To create a "symbol" for your naming convention, you can specify (any or all):
# dotnet_naming_rule.<your symbols title>.applicable_kinds = class,struct,interface,enum:property,method,field,event,namespace,delegate,type_parameter
# dotnet_naming_rule.<your symbols title>.applicable_accessibilities = public,internal,private,protected,protected_internal
# dotnet_naming_rule.<your symbols title>.required_modifiers = abstract,async,const,readonly,static
#
# To create a "style" for your naming convention, you can specify (any or all):
# dotnet_naming_rule.<your style title>.required_prefix = "string of your desired prefix"
# dotnet_naming_rule.<your style title>.required_suffix = "string of your desired suffix"
# dotnet_naming_rule.<your style title>.word_separator = "string of your desired word separator"
# dotnet_naming_rule.<your style title>.capitalization = pascal_case , camel_case , first_word_upper , all_upper , all_lower
# Methods, Properties, and Enums at Any Accessbility Must Be Pascal Case
dotnet_naming_symbols.method_and_property_symbols.applicable_kinds= method,property,enum
dotnet_naming_symbols.method_and_property_symbols.applicable_accessibilities = *
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
dotnet_naming_rule.methods_and_properties_must_be_pascal_case.severity = warning
dotnet_naming_rule.methods_and_properties_must_be_pascal_case.symbols = method_and_property_symbols
dotnet_naming_rule.methods_and_properties_must_be_pascal_case.style = pascal_case_style
# Non-Public Members Must Be lower-case
dotnet_naming_symbols.non_public_symbols.applicable_kinds = property,method,field,event,delegate
dotnet_naming_symbols.non_public_symbols.applicable_accessibilities = private
dotnet_naming_style.all_lower_case_style.capitalization = all_lower
dotnet_naming_rule.non_public_members_must_be_lower_case.severity = warning
dotnet_naming_rule.non_public_members_must_be_lower_case.symbols = non_public_symbols
dotnet_naming_rule.non_public_members_must_be_lower_case.style = all_lower_case_style
# Formatting Coding Conventions
# Currently undocumented. Here are the ones we think are most
# popular for now.
# 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
# Spacing settings:
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_declaration_name_and_open_parenthesis = false
# Wrapping settings:
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment