ReSharper 2018.1 Help

Using EditorConfig

ReSharper supports code formatting styles, code syntax styles, and code inspection severity levels defined in the EditorConfig format.

You can start with watching this 2-minute overview video where Matt Ellis shows how ReSharper helps you to maintain the entire configuration of formatting rules using EditorConfig.

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 code styles defined in files named .editorconfig 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 root=true. File masks specified in .editorconfig files, e.g. *Test.cs are also taken into account.

ReSharper understands standard EditorConfig properties, most frequently used .NET-coding-convention EditorConfig properties, and provides a set of custom EditorConfig properties, which allow for much more granular configuration of formatting, syntax, and code inspection rules — in fact, each code style preference that you can configure in the ReSharper options dialog has ist own EditorConfig property. This means that you can maintain the entire configuration of code style and inspection rules in EditorConfig files. Below is an example of EditorConfig properties supported by ReSharper:

root = true [*] # Most of the standard properties are supported indent_size=2 max_line_length=100 # Most frequently used .NET-coding-convention properties are supported csharp_space_between_parentheses=expressions, type_casts, control_flow_statements csharp_style_var_for_built_in_types=true # ReSharper custom properties for code formatting styles resharper_csharp_brace_style=next_line resharper_csharp_blank_lines_around_invocable=2 # ReSharper custom properties for code syntax styles csharp_default_private_modifier=explicit braces_for_ifelse=not_required# ReSharper custom properties for code inspections resharper_possible_null_reference_exception_highlighting=error resharper_replace_with_string_is_null_or_empty_highlighting=do not show

EditorConfig in your solution

By default, EditorConfig properties are enabled for code formatting styles and code syntax styles, and disabled for code inspection severity levels; they will override preferences defined in ReSharper and Visual Studio options. If you want ReSharper to ignore EditorConfig styles for code formatting and code syntax, clear the corresponding checkbox on the Code Editing | General Formatter Style page of ReSharper options.

To configure code inspections from EditorConfig, you have to select the Read settings from editorconfig... checkbox on the Code Inspection | Settings page of ReSharper options.

When EditorConfig support is enabled and there are .editorconfig files that affect the current file, ReSharper will help you understand which EditorConfig styles are applied and where these settings come from:

  • On ReSharper code style and formatting options pages, you will see a yellow warning if at least one preference on the page is overridden by EditorConfig styles for the current file, each overridden preference will also be highlighted with yellow. For example:
    Code formatting options overridden by EditorConfig styles
  • In the File Formatting Info window, you can see and study all .editorconfig files that affect the current file:
    ReSharper. File Formatting Info window

Disabling ReSharper formatter with EditorConfig

In C#, C++, JavaScript, TypeScript, HTML, and Protobuf you can disable the ReSharper formatter using EditorConfig masks that have disable_formatter=true.

Standard EditorConfig properties support note

ReSharper will apply the following standard EditorConfig properties:

  • indent_size
  • indent_style
  • tab_width
  • max_line_length
  • insert_final_newline

Note that among ReSharper's custom EditorConfig properties, there are properties that will override the standard properties for specific languages. For example, you can have different intent sizes in C# and JavaScript by overriding the indent_size property with csharp_indent_size and js_indent_size properties.

.NET-coding-convention properties support note

As of version 2018.1, ReSharper supports most frequently used EditorConfig properties for the .NET coding conventions:

  • The following properties for the formatting conventions:
    • csharp_new_line_before_open_brace
    • csharp_new_line_before_else
    • csharp_new_line_before_catch
    • csharp_new_line_before_finally
    • csharp_new_line_before_members_in_object_initializers
    • csharp_indent_switch_labels
    • csharp_space_after_cast
    • csharp_space_after_keywords_in_control_flow_statements
    • csharp_space_between_method_declaration_parameter_list_parentheses
    • csharp_space_between_method_call_parameter_list_parentheses
    • csharp_space_between_parentheses
    • csharp_preserve_single_line_blocks
  • The following properties for the language conventions:
    • dotnet_style_qualification_for_field
    • dotnet_style_qualification_for_property
    • dotnet_style_qualification_for_method
    • dotnet_style_qualification_for_event
    • dotnet_style_predefined_type_for_locals_parameters_members
    • dotnet_style_predefined_type_for_member_access
    • dotnet_style_require_accessibility_modifiers
    • csharp_preferred_modifier_order
    • csharp_style_var_for_built_in_types
    • csharp_style_var_when_type_is_apparent
    • csharp_style_var_elsewhere
    • csharp_style_expression_bodied_constructors
    • csharp_style_expression_bodied_methods
    • csharp_style_expression_bodied_properties
    • csharp_style_expression_bodied_accessors
    • csharp_prefer_braces

This feature is supported in the following languages and technologies:

Language: C# Language: VB.NET Language: C++ Language: HTML Language: ASP.NET Language: Razor Language: JavaScript Language: TypeScript Language: CSS Language: XML Language: XAML Language: Resx Language: Build Scripts Language: Protobuf Language: JSON
Feature is available Feature is available Feature is available Feature is available Feature is available Feature is available Feature is available Feature is available Feature is available Feature is available Feature is available Feature is available Feature is available Feature is available Feature is available

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.

Last modified: 20 August 2018

See Also