Using EditorConfig
What is EditorConfig and how does Rider 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, Rider will apply formatting 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
.
Rider 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 Rider 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 Rider:
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 Rider options. If you want Rider to ignore EditorConfig styles, clear the corresponding check box on the page of Rider settings (Ctrl+Alt+S).
Standard EditorConfig properties support note
Rider will apply the following standard EditorConfig properties:
Note that among Rider's custom EditorConfig properties, there are properties that will override any of 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.
Roslyn EditorConfig properties support note
As of version 2017.1 Rider supports Roslyn EditorConfig properties with the exception of the following ones:
csharp_indent_block_contents
csharp_indent_case_contents
csharp_indent_labels
csharp_new_line_before_members_in_anonymous_types
csharp_space_around_declaration_statements
csharp_preserve_single_line_statements