Do you keep your code consistent using .editorconfig?

Updated by Brady Stroud [SSW] 1 year ago. See history

123

It's important that the code in a project is kept consistent. This is hard to do when you have developers working in different environments.

Using a .editorconfig file is the best way to manage this. See the EditorConfig file specification

Most IDEs will automatically find and use a .editorconfig file to format code.

See Keep your code clean, automatically!.

✅ Figure: ![Good example - Project using a ".editorconfig" file](/uploads/rules/consistent-code-style/vs2022-add-editorconfig.png)

❌ Figure: ![Bad example - Project using StyleCop (old)](/uploads/rules/consistent-code-style/vs-2022-stylecop.png)

Creating .editorconfig files

In VS 2022

  1. Open the Add New Item dialog (Ctrl+Shift+A)
  2. Search for "EditorConfig"
  3. Select a config file depending on your project
Image

Figure: Creating .editorconfig in VS 2022

Manually

  1. Create a new file called .editorconfig at the root of your project
  2. Add styling rules based on your needs

Ensuring compliance

To ensure your team is following this standard, you can add it to your Definition of Done.

Additionally, you can have a PR check that enforces .editorconfig rules, but its always better to do this locally.

Learn more on:

acknowledgements
related rules