This document explains how to use .editorconfig
files to enhance code readability and maintain cleaner source code.
- Location:
\.editorconfig
- Purpose: This is the default editor config file for Visual Studio solutions (*.sln) files. It should be placed in the same directory as the solution file.
- Location:
CodeAnalysis\Suggestive\.editorconfig
- Purpose: If you plan to enable code analysis for an existing project, start by adding this
.editorconfig
file to the project. Use it until the project aligns with the default.editorconfig
requirements.
- Location:
CodeAnalysis\None\.editorconfig
- Purpose: Use this file to ignore code analysis for a specific Visual Studio project.
- No additional work is needed; the Default
.editorconfig
will take effect automatically when a new project is created.
- If possible, use the “Default” editor config promptly.
- Otherwise, evaluate whether the project should be ignored or not.
- Copy the appropriate template (either “None” or “Suggestive”) into the project.
- Test the code analyzer by building the project.
- Copy the
CodeAnalysis
folder and the.editorconfig
from this Git repository's main folder into your new repository. - Evaluate which
.editorconfig
template each project should use. Initially, consider using the “None” template to minimize effort. Over time, gradually promote the use of the “Suggestive” template for each project.
- Update the Cleanup Code Profile 1
- Include the following fixers:
- Fix all warnings and erros set in EditorConfig
- Fix analyzer warnings and erros set in EditorConfig
- Include the following fixers:
- Configure Cleanup Code on Save a. Navigate to Options > Text Editor > Code Cleanup b. Select "Profile 2" from the dropdown c. Check "Run Code Cleanup profile on Save" d. Click OK to save changes
- When working with cs files, to automatically run the Analyzer's recommendation, Press the "CTRL+K", "CTRL+E"
- This will execute the Code Cleanup using the default profile which is the "Profile 1".
In some cases, the code analyzer may report errors that require complex changes to resolve. When this happens:
- Consider adjusting the severity of the error to a warning or suggestion.
- If appropriate, change it to “None” or “Silent” severity.
- Consolidate all default .editorconfig of all teams and build a new default .editorconfig based on these versions.
- Create new suggestive
.editorconfig
based on the Default editor config when needed, just replace theerror
withsuggestion
.
Feel free to make these adjustments as needed to maintain a healthy codebase! 🚀