DEV Community


Posted on

You're using an EditorConfig right?

For the most part I code in two different language. C# and go. While I like them both for different reasons the one thing I miss from go is the auto formatting. I know arguments exist for both sides but I find a code base that follows the same rules throughout to be much easier to read. When it happens automatically then I don't have to worry about it and I can focus on coding.

Without an auto-formatter keeping everyone on the same page isn't easy. Maybe you think a one line if statement should have brackets (it should). If someone creates a pull request without brackets then it's going to have to be changed.

If only there was some way we could manage this... OH WAIT! EditorConfig!

Using an EditorConfig file is so easy! Once setup, Visual Studio will make suggestions right in the file with those squiggles we all love so much. It won't stop the compiler but I don't know a programmer that can ignore those red lines. Also, you can make it as strict as you want. There's a ton of flexibility.

Get it going

There a couple simple ways to set it up. The fastest is just copying someone else's. It's a great starting point, if you can live with their choices. Like this one from Roslyn. But, it's a little strict too on the variable names for my taste.

The Intellicode plugin from Microsoft will automatically create one right from your code. It tries to determine your style. From there you can tweak what it got wrong or what you want to change going forward.

Adding EditorConfig from Intellicode

However, if your code base is all over the place then that's not the best option.


Anyway, if you want to adjust the file it's quite easy. The documentation is really good, as long as you land on the right page.

Like I said you can make it as strict as you want. The file allows you to configure how it shows up in Visual Studio. You can set it to show as a warning, error, or suggestion. Pretty handy for those rules that should never be broken. It's also very granular and it seems like there's a setting for everything!

I want to remind you that it won't stop an especially stubborn person from compiling. But I think it's enough for most, that are acting on good faith. I've found it especially handy at reminding people of our formatting.

I hope you can see how useful this tool is at keeping a code base formatted. It's really easy to setup and Visual Studio will use it automatically. Making it a no brainer!

Top comments (1)

rhymes profile image

EditorConfig is great! And being editor-agnostic scales very well :)