Skip to content

EditorConfig

Damian edited this page Sep 14, 2021 · 2 revisions

The following basic rules are applied to C#, C++, and SQL projects

Spacing

  • Indent using spaces, not tab
  • Indent size: 2 spaces

Naming Convention

  • Async method must have the Async suffix

Sample

# Copyright Xeno Innovations, Inc.
#
# EditorConfig (http://EditorConfig.org)
# This file provides formatting rules for the project so you can
# keep your own personal defaults for others
#
# Revision Log
# 4   2020-05-10 - C# coding standards
# 3c  2020-04-18 - Split file filters into their own sections
# 3   2017-07-31 - Basic
#
# References:
#   - https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2019
#   - https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2019
#   - https://github.com/microsoft/microsoft-ui-xaml/blob/master/.editorconfig
#

# Top-most EditorConfig file
root = true

# All generic files should use MSDOS style endings, not Unix (lf)
[*]
end_of_line = crlf

# C# Files
[*.cs]
indent_style = space
indent_size = 2
tab_width = 2
trim_trailing_whitespace = true

# C# Coding Conventions

## Switch case statements
csharp_indent_switch_labels = true
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true

## Formatting - new line options
### Require braces to be on a new line for (also known as "Allman" style)
###   accessors, methods, object_collection, control_blocks, types, properties, lambdas
csharp_new_line_before_open_brace = all
csharp_new_line_before_catch = true
csharp_new_line_before_else = 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
csharp_new_line_between_query_expression_clauses = true

## Known issue below, use `all`
## ### Require braces to be on a new line for (also known as "Allman" style)
## csharp_new_line_before_open_brace = accessors, methods, object_collection, control_blocks, types, properties, lambdas

## Generic
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false

dotnet_style_allow_multiple_blank_lines_experimental = false
dotnet_style_allow_statement_immediately_after_block_experimental = false

### Alt to LicenseHeader extension
# file_header_template = Copyright Xeno Innovations, Inc. 2021

## Naming Conventions
### Async methods must use "Async" suffix
dotnet_naming_rule.async_methods_end_in_async.symbols = any_async_methods
dotnet_naming_rule.async_methods_end_in_async.style = end_in_async
dotnet_naming_rule.async_methods_end_in_async.severity = error
dotnet_naming_symbols.any_async_methods.applicable_kinds = method
dotnet_naming_symbols.any_async_methods.applicable_accessibilities = *
dotnet_naming_symbols.any_async_methods.required_modifiers = async
dotnet_naming_style.end_in_async.capitalization = pascal_case
dotnet_naming_style.end_in_async.required_prefix =
dotnet_naming_style.end_in_async.required_suffix = Async
dotnet_naming_style.end_in_async.word_separator =

### private fields should use prefix with an underscore
dotnet_naming_rule.private_members_with_underscore.symbols  = private_fields
dotnet_naming_rule.private_members_with_underscore.style    = prefix_underscore
dotnet_naming_rule.private_members_with_underscore.severity = warning
dotnet_naming_symbols.private_fields.applicable_kinds       = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_style.prefix_underscore.capitalization = camel_case
dotnet_naming_style.prefix_underscore.required_prefix = _

### Constant fields must use PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols  = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = error
dotnet_naming_rule.constant_fields_should_be_pascal_case.style    = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds   = field
dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

### Interfaces must have an I suffix
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.severity = error
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_style.begins_with_i.capitalization = pascal_case
dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =

# StyleCop.Analyzers
## CA1031: Do not catch general exception types
dotnet_diagnostic.CA1031.severity = none

# CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.CS1591.severity = silent

[*.{c,cpp,h}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.sql]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.{xml,xaml,axml}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.json]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
Clone this wiki locally