Use EditorConfig
JetBrains Rider supports code formatting styles, code syntax styles, C# naming styles, and code inspection severity levels defined in the EditorConfig format.
What is EditorConfig and how does JetBrains 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, JetBrains Rider 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, for example *Test.cs
are also taken into account.
JetBrains Rider 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 JetBrains Rider settings dialog has its 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 JetBrains Rider:
EditorConfig in your solution
By default, EditorConfig properties are enabled; they will override preferences defined in JetBrains Rider settings. If you want JetBrains Rider to ignore EditorConfig styles for code formatting and code syntax, clear the corresponding checkbox on the
page of JetBrains Rider settings.To configure code inspections and naming styles from EditorConfig, you have to select the Read settings from editorconfig, project settings and rule sets checkbox on the page of JetBrains Rider settings.
When EditorConfig support is enabled and there are .editorconfig files that affect the current file, JetBrains Rider will help you understand which EditorConfig styles are applied and where these settings come from:
On JetBrains Rider 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:
Export code style settings to EditorConfig
If you are going to share code style settings via EditorConfig, you may want to export the styles already configured in JetBrains Rider to the .editorconfig file.
Press Ctrl+Alt+S or choose
(Windows and Linux) or (macOS) from the menu, then choose on the left.In the EditorConfig" section, click Export. This will open the Export to .editorconfig dialog.
By default, JetBrains Rider writes the settings to a new .editorconfig file in the root directory of the current solution. If one or more .editorconfig files exist, JetBrains Rider will use the closest file in the directory hierarchy to save the settings. If necessary, you can change the destination file using the path selector at the top of the dialog.
In the Section (file mask) field, you can specify a wildcard pattern to use for the section with generated properties. Note that if you choose to export standard EditorConfig" properties, they will be placed in other sections according to language conventions.
If there is an existing .editorconfig file in the specified location, there could be conflicts between values of properties that exist there and the ones that JetBrains Rider is about to save. Such properties will be shown in red and if you proceed with saving, the conflicts will be resolved in favor of the newly generated ones.
Click Export. JetBrains Rider will create or update the .editorconfig file in the specified location.
You can also save formatting styles to EditorConfig after contextual configuration of formatting rules.
Disable JetBrains Rider formatter with EditorConfig
In C#, C++, JavaScript, TypeScript, HTML, and Protobuf you can disable the JetBrains Rider formatter using EditorConfig masks that have disable_formatter=true
.
Standard EditorConfig properties support note
JetBrains Rider will apply the following standard EditorConfig properties:
indent_size
indent_style
tab_width
max_line_length
insert_final_newline
.NET-coding-convention properties support note
As of version 2021.1, JetBrains Rider supports most frequently used EditorConfig properties for the .NET coding conventions:
csharp_indent_braces
csharp_indent_switch_labels
csharp_new_line_before_catch
csharp_new_line_before_else
csharp_new_line_before_finally
csharp_new_line_before_members_in_object_initializers
csharp_new_line_before_open_brace
csharp_new_line_between_query_expression_clauses
csharp_preferred_modifier_order
csharp_preserve_single_line_blocks
csharp_space_after_cast
csharp_space_after_colon_in_inheritance_clause
csharp_space_after_comma
csharp_space_after_dot
csharp_space_after_keywords_in_control_flow_statements
csharp_space_after_semicolon_in_for_statement
csharp_space_around_binary_operators
csharp_space_before_colon_in_inheritance_clause
csharp_space_before_comma
csharp_space_before_dot
csharp_space_before_open_square_brackets
csharp_space_before_semicolon_in_for_statement
csharp_space_between_empty_square_brackets
csharp_space_between_method_call_empty_parameter_list_parentheses
csharp_space_between_method_call_name_and_opening_parenthesis
csharp_space_between_method_call_parameter_list_parentheses
csharp_space_between_method_declaration_empty_parameter_list_parentheses
csharp_space_between_method_declaration_name_and_open_parenthesis
csharp_space_between_method_declaration_parameter_list_parentheses
csharp_space_between_parentheses
csharp_space_between_square_brackets
csharp_style_var_elsewhere
csharp_style_var_for_built_in_types
csharp_style_var_when_type_is_apparent
csharp_using_directive_placement
dotnet_style_parentheses_in_arithmetic_binary_operators
dotnet_style_parentheses_in_other_binary_operators
dotnet_style_parentheses_in_relational_binary_operators
dotnet_style_predefined_type_for_locals_parameters_members
dotnet_style_predefined_type_for_member_access
dotnet_style_qualification_for_event
dotnet_style_qualification_for_field
dotnet_style_qualification_for_method
dotnet_style_qualification_for_property
dotnet_style_require_accessibility_modifiers
file_header_template
csharp_prefer_braces
csharp_style_expression_bodied_methods
csharp_style_expression_bodied_constructors
csharp_style_expression_bodied_properties
csharp_style_expression_bodied_accessors
dotnet_separate_import_directive_groups
dotnet_sort_system_directives_first
dotnet_diagnostic.*
— supported for all compiler warnings.dotnet_naming_rule.*
,dotnet_naming_style.*
,dotnet_naming_symbols.*
— will work if the specified kinds of symbols can be matched by kinds of symbols available in JetBrains Rider naming settings.