.NET Tools
Essential productivity kit for .NET and game developers
Aligning code in columns with ReSharper and Rider
In our previous post, we looked at how we can use different code styles for different blocks of code in ReSharper 2017.3 EAP and Rider 2017.3 EAP. In this post, we will look at some other improvements to the code formatting engine, such as aligning code in columns and a sneak preview of other changes coming in ReSharper 2017.3.
This post is part of a series around changes in the ReSharper and Rider code formatter:
- Code formatting engine updates in ReSharper and Rider
- Different code styles for different blocks of code
- Aligning code in columns
- Configuring code formatting from code selection
Aligning code in columns
Another very popular group of code formatter feature requests was around aligning code. There were requests to align equal operands, to implement outdenting and make code using the ternary operator look nicer, and several other requests to make code more readable.
Some developers like to have properties in a class aligned in columns, e.g. the { get; set; }
starting in the same column. Others like to align assignments in columns. ReSharper 2017.3 EAP now supports all of those flavors! Let’s reformat this entire file into columns, using the Reformat Code action (Ctrl+Alt+Enter):
We can configure these options in ReSharper’s settings under Code Editing | C# | Formatting Style | Tabs, Indents, Alignment, then Align Similar Code in Columns.
Code formatting rules not only apply when we write code. When generating code, ReSharper uses these settings as well. For example, when we generate a constructor (Alt+Insert) ReSharper will use the column settings we configured:
What else is coming?
Another request we received and is quite popular is to insert a blank line before or after a { }
block. This feature will light up in the next EAP build (tip: you can use the JetBrains Toolbox App to auto-update to the latest EAP).
In our next and last post of this series, we’ll look at an existing ReSharper feature that helps make sense of the overwhelming amount of code formatter options.
Download ReSharper 2017.3 EAP or Rider 2017.3 EAP that keeps up with ReSharper’s formatter changes. We’d love to hear your feedback!