BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Putting EditorConfig to Work in Visual Studio

| by Jeff Martin Follow 5 Followers on Jan 10, 2017. Estimated reading time: 1 minute |

One of the features included in Visual Studio 2017's first Release Candidate (RC) was support for the EditorConfig standard.  Adhering to this standard allows developers to define a coding style once and then easily reuse that style across different editors.  Another big advantage is that the styles defined in an EditorConfig file can be stored in a source control system and avoid being lost in a particular editor’s dialog boxes or configuration.  VS2017 will support the use of the EditorConfig functionality with several languages, including C#, Visual Basic, C++, JavaScript, F# and TypeScript.

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:

  1. indent_style
  2. indent_size
  3. tab_width
  4. end_of_line
  5. charset

Two more popular rules, trim_trailing_whitespace and 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.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT