Starting from version 2017.1, ReSharper supports formatting styles defined in EditorConfig format.
In this topic:
- What is EditorConfig and how does ReSharper extend it?
- EditorConfig in your solution
- Standard EditorConfig properties support note
- Roslyn EditorConfig properties support note
What is EditorConfig and how does ReSharper extend it?
EditorConfig is a configuration file convention that is used to define and maintain consistent code styles between team members working on the same code as well as between different editors and IDEs that they might use. The styles are saved in INI-like files named .editorconfig, where section names are file masks and properties inside a section define code styles for files matching that masks.
As EditorConfig convention suggests, ReSharper will
apply formatting styles
defined in files named
in the directory of the current file and in all its parent directories until it reaches
the root filepath or finds an EditorConfig file with
ReSharper understands standard EditorConfig properties, most of Roslyn EditorConfig properties, and provides a set of custom EditorConfig properties, which allow for much more granular configuration of formatting rules - in fact, there are properties for each preference available in the ReSharper options dialog. This means that you can maintain the entire configuration of formatting rules in EditorConfig files. Below is an example of .editorconfig settings supported by ReSharper:
root = true [*] # Most of the standard EditorConfig properties are supported indent_size=2 max_line_length=100 # Most of Roslyn EditorConfig properties for Visual Studio 2017 are supported csharp_space_between_parentheses=expressions, type_casts, control_flow_statements csharp_new_line_within_query_expression_clauses=true # Greater flexibility in configuring code formatting styles with custom EditorConfig properties resharper_csharp_brace_style=next_line resharper_csharp_blank_lines_around_invocable=2
EditorConfig in your solution
By default, EditorConfig styles are enabled and they will override formatting preferences defined in ReSharper and Visual Studio options. If you want ReSharper to ignore EditorConfig styles, clear the corresponding check box on the page of ReSharper options.
When EditorConfig support is enabled and there are .editorconfig files that affect any of the files in the current solution, ReSharper will help you understand which EditorConfig styles are applied and where these settings come from:
- On ReSharper formatting options pages, you will see a yellow warning if at least one preference on a page is overridden by EditorConfig styles, each overridden preference will be also highlighted with yellow. For example:
- In the File Formatting Info window, you can see and study all .editorconfig files that affect the current file:
Standard EditorConfig properties support note
ReSharper will apply the following standard EditorConfig properties:
Note that among ReSharper's
custom EditorConfig properties,
there are properties that will override any of the standard properties for specific languages.
indent_size property with
Roslyn EditorConfig properties support note
As of version 2017.1 ReSharper supports Roslyn EditorConfig properties with the exception of the following ones:
This feature is supported in the following languages/technologies:
The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.