Set up coding conventions with .editorconfig
Microsoft recommend to use an .editorconfig file to define and share coding convention rules between a team. Editorconfigs is a standardized way to define coding styling conventions. It can be used for different programming languages and is supported by all popular IDEs like Visual Studio, Eclipse and much more.
Installation
- Add a .editorconfig file to the solution folder
- Copy the recommened default options from .editorconfig example and insert it into the .editorconfig file
- Rebuild solution
That’s it! Compiler Roslyn and Intellisense supports .editorconfig natively.
Customize rules
Styling rules are defined in the .editorconfig file. A rule consists of a rule name (e.g. dotnet_style_qualification_for_field), a rule value (e.g. true) and a severity level (e.g. warning). The rule value should always be set to true.
- Change the rules of the section “this. preferences” as follows:
# this. preferences
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_event = true:warning
- Rebuild the solution
- Fix the warning with quick actions