More formatting updates in ReSharper and Rider 2018.1.2
Our latest release of ReSharper 2018.1.2 includes improvements in formatting that we have not yet showcased in previous blog posts. We have already written a series about maintaining consistent code style with formatting inspections earlier. Now let’s look at some of the other formatting features that have been improved in ReSharper 2018.1.2 and Rider 2018.1.2!
Commenting code is a practice that has been around for as long as people have been programming. While comments may seem to be a minor issue in a language, an awkward comment format in a language is a nuisance and can be a source of nasty errors.
In ReSharper 2017, we introduced a new feature that will comment the second line when you break a long comment into two. This will make things easier for everyone by allowing to quickly break comments into multiple lines so they are visible in Visual Studio’s code editor.
Here is an example of this feature at work:
There is also a new comment formatting option in ReSharper 2018.1. The new option will allow ReSharper to format and indent comments so they are more readable with our code. The update will format the comment after removing all whitespace at the beginning of the line. Some developers may not want their comments formatted in this manner. If you don’t want to have ReSharper format comments in this fashion, have the “Don’t indent comments started at first column” option under Code Editing | C# | Formatting Style | Tabs, Indents, Alignment selected.
An example of how this new formatting feature works is shown below.
New settings for method signature line breaks
There are also a few new line break options that will allow you to have your personal preferences when writing C# code and method signatures.
The first we will look at is the “Keep existing arrangement of parenthesis in declaration” under ReSharper’s options Code Editing | C# | Formatting Style | Line Breaks and Wrapping under the section Arrangement of Method Signatures. Note the preview pane shows an example of a method’s signature using the setting selection as shown below.
We can also wrap method signatures before the parenthesis in the declaration as seen in the Options dialog’s example visualizer.
New settings for LINQ expressions line breaks
There are also two new settings for when we are writing LINQ expressions in C#. The first is found under Code Editing | C# | Formatting Style | Line Breaks and Wrapping under the section Arrangement of LINQ Expressions. The “Prefer wrap before multiline LINQ expressions” option will move the cursor to a new line after the assignment character as seen in the preview below.
The second new option for writing LINQ expressions with ReSharper 2018.1 is Place “into” on new line in LINQ expressions located in Code Editing | C# | Formatting Style | Line Breaks and Wrapping under the section Arrangement of LINQ Expressions. This will move the into statement for LINQ expressions to a new line when you are writing your code as seen below in the preview.
The updates to the code formatting engine provide greater customization options to fit the code style you and your team prefer. Remember these can be shared with team members as well through the use of settings layers.
We’d love to hear your feedback on these updated features! Give ReSharper 2018.1 a try!
Subscribe to Blog updates
Thanks, we've got you!