Every person has their standards when codding. Most of the time, the problem with that is having different standards for code. Especially in a team or even in a company, everyone should follow the same standardization. That can be tricky because you can miss some rules or assume your code follows the wrong rule. To make this clear, most of the IDE has an EditorConfig. The EditorConfig is a file where you make all the rules for your code. Like if the indentation is with tab or spaces, how many, etc…
What is EditorConfig?
EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs. The EditorConfig project consists of a file format for defining coding styles and a collection of text editor plugins that enable editors to read the file format and adhere to defined styles. EditorConfig files are easily readable, and they work nicely with version control systems.
What is EditorConfig solving?
Whenever we work in a team, we set up some ground rules to work efficiently; those ground rules are coding standards in the programming world.
Coding standards may include:
- Universal File configuration: indentation style, line width, line ending, indentation size.
- Programming languages-based configuration: block style, comment style, method naming, class naming.
Create your EditorConfig in VisualStudio 2022
Go to Tools -> Options -> Text Editor -> C#
Visual Studio gives you an example of how your code will show in real-time. Also, you can configure the severity of each rule. One feature cool is the Naming. You can say the style you want(Pascal Case, Camel Case) and specify different elements how they will appear. Like the Interface will begin with the letter "I".
After making all the changes needed for your standards, click on Generate .editorconfig file from settings
Sharing the EditorConfig
To share settings across solutions and projects, you need to create/put the .editorconfig file in a top-level directory/solutions folder.
Some links will help you:
.NET code style rule options — .NET | Microsoft Docs
What's new in .NET Productivity with Visual Studio 2022 — Visual Studio Blog (microsoft.com)