JetBrains Rider 2018.1 Help

Syntax Styles

One of the aspects of the code style is how to use interchangeable language syntax constructions. For example, two method definitions below are identical from the compiler point of view, but the choice of syntax constructions makes them look different:

[Conditional("DEBUG")] [Test] static public void Foo(String str) { foreach (Char ch in str) { System.Console.WriteLine(value: ch); } }
[Test, Conditional("DEBUG")] public static void Foo(string str) { foreach (var ch in str) Console.WriteLine(ch); }

Configuring code syntax styles

When you start using JetBrains Rider, it will refer to its default settings to make sure that interchangeable syntax constructions are used consistently throughout your codebase. However, you can configure each individual preference to your liking. There are two ways to configure code syntax styles:

  • Configure your preferences on the Editor | Code Style | [language] | Code Style page of JetBrains Rider settings (Ctrl+Alt+S). These modifications will be saved using the mechanism of layered settings so that you can apply them either on local machine for all your projects, or share them with your teammates.
  • Use JetBrains Rider custom EditorConfig code style properties to specify your preferences in EditorConfig files, which will also allow you to have consistent code styles across your team.
    Note that preferences specified in .editorconfig files will override preferences saved in JetBrains Rider settings.

Checking and fixing code syntax style with code inspections

JetBrains Rider provides a number of code inspections that check your code for compliance with your code syntax style and suggests quick-fixes where the style is violated — for example, if the order of modifiers differs from your preferences:

Sorting modifiers

If you need to review all code syntax style problems in a desired scope, up to the whole solution, you can run code inspection in this scope. When the analysis is over, group the results by issue category, and check what problems there are and where:

Code syntax style issues found in a solution

All of the code syntax style inspections are configurable and you can disable the ones that you do not like.
You can also go through the list of code syntax style inspections and configure all of them in one go. There are two ways to do so:

  • On the Code Editing | [language] | Code Style page of JetBrains Rider options, use selectors in the Notify with column and choose Do not show for inspections that you want to disable.
    On this options page, you can also change preferences for each code syntax style rule.
  • On the Editor | Inspection Severity page of JetBrains Rider settings (Ctrl+Alt+S), find code syntax style inspections in the [language] | Code Style groups and clear check boxes next to the ones you want to disable.

Applying code syntax style with code cleanup

To apply code syntax style in the desired scope, you can also use code cleanup. You can either run code cleanup with the default profile Default: Full Cleanup to apply all code syntax style rules, or create and run a custom profile with a desired subset of code syntax style rules.

Additional actions for code syntax style in C#

To apply C# code syntax styles in the current selection

  1. In the editor, select a block of code where you want to apply code syntax styles.
  2. Press Alt+Enter or click on the action indicator to the left of the caret to open the action list.
  3. Select ThemedIcon CodeStyle Screen Gray Apply code style in the action list.
Last modified: 20 August 2018