Using EditorConfig to Maintain a Consistent Coding Style

Have you ever tried to work on someone else’s code and realized that they have completely different code formatting than you are used to? Maybe they use tabs, 2 spaces, or 4 spaces for indentation. Maybe they use underscore prefixed private member variables such as private string _name;

Wouldn’t it be nice if when you pulled down the project from source control, it also brought all of the code formatting styles with it? That’s what EditorConfig is meant for.

Not long ago I added an .editorconfig file to RogueSharp. I recently mapped all of the ReSharper settings to the config as both Visual Studio and ReSharper come bundled with native support for EditorConfig.

Download

First you’ll need to download the file. I created a public Github Gist which is available here:

Add to Solution

  • Copy the downloaded file to the root of your solution where the .sln file lives.
  • Make sure that the name is .editorconfig
  • Create a new Solution Items folder in Visual Studio if it doesn’t already exist
  • Add .editorconfig to the Solution Items folder

EditorConfig Solution Item

Modify Settings

Although the .editorconfig will work as is, you’ll likely want to make some modifications to it, to match your coding style.

Common Settings

  • tabs vs spaces
  • indent size
  • trim trailing whitespace

EditorConfig Common Settings

You’ll likely want to change the indent size at a minimum. At TechSmith where I am currently employed we use 3 spaces, but 2 or 4 is more typical.

.NET Language Conventions

.NET Language Conventions

Microsoft Documentation For .NET Language Conventions

.NET Formatting Conventions

.NET Formatting Conventions

Microsoft Documentation For .NET Formatting Conventions

.NET Naming Conventions

.NET Formatting Conventions

Microsoft Documentation For .NET Naming Conventions

ReSharper Settings

ReSharper Settings

JetBrains Documentation For ReSharper EditorConfig Settings

Note: I organized the ReSharper settings according to how they appear in the menus. There should be a 1-1 relationship between each .editorconfig setting and it’s corresponding ReSharper menu entry.

ReSharper Menus

About Faron

Faron Bracy is a husband, father, and TechSmith employee. He maintains the open source library RogueSharp as a hobby project. Other hobbies include painting fantasy miniatures, playing board games, and playing retro video games with his family.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.