Code style settings from Roslyn conventions in EditorConfig
In our previous post, we looked at how we can specify ReSharper’s inspection severities inside our EditorConfig file. In this post, we will see how ReSharper and Rider integrate with Roslyn conventions.
In this series:
- Maintaining consistent code style with formatting inspections
- Configuring inspection severities with EditorConfig
- Code style settings from Roslyn conventions in EditorConfig
- StyleCop code style settings and inspections
Integration of Roslyn conventions
When we are in collaboration with folks that don’t have ReSharper or Rider installed, it makes sense to use Roslyn conventions in our EditorConfig file as well. Since ReSharper 2017.1 we supported reading most of the Roslyn formatting conventions and adjust the effective ReSharper settings accordingly. In ReSharper 2018.1 EAP and Rider 2018.1, we extend our support by the following Roslyn language conventions including their severity:
Note: we will add support for Roslyn naming conventions in a future version of ReSharper.
Before adding any of these conventions to our EditorConfig files, we need to enable the related option under Options | Code Editing | General Formatter Style:
As an example, we could specify to prefer built-in type names instead of
var and notify with a warning if the convention was violated:
csharp_style_var_for_built_in_types = false : warning
This setting will automatically be applied to the effective ReSharper settings. For better understanding, the overridden settings are highlighted in yellow:
Another great way to find out about our effective settings, is to browse ReSharper | Windows | File Formatting Info:
Tip: we can open any ReSharper tool window by hitting Alt+Enter and typing its name.
Our help section provides more information about using EditorConfig files.
Stay tuned for the next part of this series, in which we will see how ReSharper and Rider integrate with StyleCop configurations.