Putting EditorConfig to Work in Visual Studio
As Microsoft’s Kasey Uhlenhuth explains, one of the benefits of EditorConfig is that broad standards can be defined solution-wide, with additional EditorConfig files uses to define project or directory specific standards. Adding these files allows for the definition of both code formatting rules and code style rules. VS2017RC currently supports these five formatting rules:
Two more popular rules,
insert_final_newline, are not yet supported. Code Style rules can also be defined, and depending on the severity (none / suggestion / warning / error) a build break when this mechanism is fully implemented (currently in VS2017RC a build will proceed). According to Microsoft EditorConfig support in Visual Studio can and will be updated after VS2017 RTM and their goal is provide full compliance with EditorConfig features through the course of these updates.
Once a developer has defined the various Code Formatting and Code Style rules that they want for an existing source tree, it will be necessary to close and reopen any open files or when an EditorConfig file changes. Uhlenhuth provides a couple of keyboard shortcuts to quickly apply new rules:
- Updating a single open file in the editor: Format Document CTRL-K, D
- Apply updates to all files in the entire project/solution: Quick Actions menu CTRL + (control plus)
Note that when an EditorConfig file is present, its rules will override those used defined in Visual Studio’s Tools |
Options menu. If you would like to have some editor conveniences when editing EditorConfig files within VS0217, Mads Kristensen has produced the open source EditorConfig Language Service plugin. Currently using Code Formatting and Style requires VS2017RC, but a NuGet package is being developed to provide this functionality to allow for integration with build systems.
Updated January 10, 2017 to incorporate information on language support and the availability of future updates.