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 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 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:
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.
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.
For more detailed configuration, you can expand Show additional options and choose the following options:
Export settings that have default values
By default, JetBrains Rider only saves properties for settings that you have changed. So only these settings will apply and override other settings when the resulting .editorconfig is read by ReSharper or Rider. All other settings will take values specified in the IDE.
If you enable this option, JetBrains Rider will save all settings in their current state, regardless whether they were changed or not. This way you will get a stricter .editorconfig that will override all code style and formatting settings when read by ReSharper or Rider.
Remove existing properties with ambiguous values
Some EditorConfig properties could correspond to multiple JetBrains Rider-specific properties, which allow for a more precise configuration. So there could be situations when a more general property agrees with some related JetBrains Rider-specific properties and contradicts to others, which makes this more general property ambiguous.
As more detailed properties have higher priority, such a situation is not a problem and there is no need to remove properties with ambiguous values.
The only case when you may want to remove properties with ambiguous values is when the project EditorConfig styles are going to be read only by ReSharper and Rider, and you want to remove redundancies from the .editorconfig file.
Export standard .editorconfig properties — whether to save standard .editorconfig properties These properties will also apply if the generated EditorConfig is read by other editors and IDEs.
Export cross-editor language-specific properties — whether to save .NET-coding-convention properties. These properties will also apply if the generated EditorConfig is read by other editors and IDEs.
Export JetBrains Rider/ReSharper-specific inspection severities — whether to save severity levels for JetBrains Rider's configurable code inspections.
BasedOnStyle — sets the corresponding option to define which which style is used for all options by default.
Hide options that coincide with the chosen base style
Options that have the same value as defined in the base style that is selected in BasedOnStyle will not be exported.
Export CPP settings — whether to export Clang-Format options that affect C++ code.
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.
Disable JetBrains Rider formatter with EditorConfig
Standard EditorConfig properties support note
JetBrains Rider will apply the following standard EditorConfig properties:
.NET-coding-convention properties support note
As of version 2019.3, JetBrains Rider supports most frequently used EditorConfig properties for the .NET coding conventions:
The following properties for the formatting conventions:
The following properties for the language conventions: