What’s new in ReSharper 2021.1

ReSharper 2021.1 brings updates in code analysis, support for ASP.NET route templates, rename for tuple components, and more.

Download

Free 30-day trial

Code Analysis

More patterns to merge

The Merge into pattern inspection can now deal with many more code patterns. Fuse null checks with other checks into a single pattern check:

Rewrite checks from conditional?.Access expressions to nested pattern matching:

Reduce if statement nesting by merging the checks together:

Finally, you can merge patterns inside a simple var (a,b) deconstruction pattern by expanding them to full forms:

More C# 9.0 Support

We’ve added more support for C# 9.0 records. The Extract interface and Extract superclass refactorings now work with record declarations, as do File Layout and the features that have to do with XML documentation.

We’ve come up with a set of new inspections and actions. Redundant explicit property declaration for properties in record declarations can be of help while migrating your code to use records with positional parameters and implicit property declarations. A corresponding quick-fix, Remove explicit property, is included.

If you decide to turn a record into a class, the To class action will take care of the positional parameters and primary constructor. There’s a To record action that works the opposite way as well.

Whenever you need to rewrite positional parameters and a primary constructor to ordinary properties, constructor, and an explicit Deconstruct() method, consider using the To explicit constructor context action.

There’s also something to keep things neat: the Redundant 'record' type declaration body inspection and the corresponding quick-fix will replace the empty record type declaration body with a semicolon.

Find usages now searches for the usages of a record’s primary constructor and for the usages of an implicit Deconstruct() method.

Inline temporary variable

We’re happy to introduce a new inspection, Inline temporary variable. Sometimes you find yourself using the same value over and over under different names in your program. Can such code be made more transparent? Sure, and ReSharper is here to help.

It can even help you find bugs if the temporary variable was supposed to be initialized to some other value or mutated later in code.

Other goodies

Logical not patterns can help you make your type checks much easier to read. ReSharper offers dropping the !() syntax in favour of a not pattern.

ReSharper now suggests using the range operator instead of Slice and Substring, if doing so simplifies the code.

The Namespace does not correspond to file location inspection is now suppressed in files with top-level code.

There’s another new inspection that checks whether an auto-property can be replaced with a computed property, along with a quick-fix to make the replacement.

For C# 10.0 support, we’ve taken some first steps and taught ReSharper to work with the Constant interpolation strings feature.

Stay tuned for a dedicated blog post with all of the details on Code Analysis in 2021.1!

ASP.NET Core Route Templates

Route templates are widely used in MVC applications to configure how HTTP requests are matched to the application’s executable endpoints. In 2021.1 we’re introducing support for route templates: ReSharper now provides structural navigation, inspections, and quick-fixes. Let’s see some examples.

The most basic inspections check route template syntax errors: accidentally placing a catch-all parameter route in the middle of the template, declaring the catch-all parameter as optional, adding a default value for the optional parameter, and so on.

Route parameters are the source of interesting cases. What if you declare a parameter with the same name in the controller and in the action? ReSharper will warn you about it.

On the other hand, parameters can be missing. In this case, ReSharper will suggest you add them, either from the controller’s attribute or from the action. If there’s a type constraint, it will be used to infer the type of the parameter.

Speaking of constraints, they’re a good place for code analysis. ReSharper checks whether the applied constraint itself is correct, and whether a parameter actually satisfies the constraint.

ReSharper also tries to analyze whether the parameter type can be more strict – based on the constraint – and may suggest changing the type. If you’ve used the different type for the parameter on purpose, then just dismiss the suggestion.

ReSharper is aware of custom constraints as well. If in some cases they aren’t recognized, annotate your constraint class with the [RouteParameterConstraint] attribute provided by JetBrains.Annotations.

As for other features from our standard pack, there’s code completion, structural navigation, and rearranging the code.

Renaming the route parameters doesn’t need to be manual anymore: the Rename refactoring is here for you.

All of the above works for attribute-based routing for now. We’re eager to hear your feedback on this new piece.

For more details about ASP.NET Core route templates, please see this blog post.

Rename in Tuples

Named tuples have been with us since C# 7, but renaming the components remained a manual operation. We’ve put an end to it – you can call the refactoring now.

Navigation

You now have a new navigation action – Navigate to Windows Explorer. You’ll find it in the Navigate | Navigate to menu or by pressing Ctrl+Shift+A and typing its name. This can be useful if you are doing something with the file itself, like copying it or copying the path inside the repository, or if you prefer to view the file’s VCS history using Git extensions for Windows Explorer.

Performance

While we’re still dismantling ReSharper for ‘out of process’ mode and putting it back together, we never stop fixing specific performance issues where it’s possible. Here are some highlights.

  • We’ve sped up typing in Razor files inside large solutions.
  • We’ve sped up typing in any large files where ReSharper’s analyzers are working.
  • We’ve improved the performance and responsiveness of debugger data tips.
  • We’ve optimized how ReSharper deals with shared documents, so it now consumes less memory.
  • We’ve implemented performance improvements for JavaScript and TypeScript unit testing.

Formatting and Code Styles

We’ve added a couple of new settings:

  • You can now choose whether to set a space before and within target-typed new() parentheses.
  • You can specify wrapping before the assignment operator.
  • You can outdent label statements.

For custom naming rules, we have updated the order in which they are applied: more specific ones now go first.

Finally, we’ve added a new action for Format Selection. You can now tell ReSharper to only adjust the indents for the selected code instead of performing the whole reformatting process.

We’ve also fixed a set of bugs – you can find the details in our issue tracker.

EditorConfig

EditorConfig is becoming a popular tool in the .NET community, and we’re continually improving how it works with ReSharper. Here’s what we’ve changed:

  • We’ve improved how ReSharper reads settings for naming rules from EditorConfig and writes the user-defined naming rules to EditorConfig.
  • If the naming rules are overridden in EditorConfig, ReSharper shows a notification on the naming settings page.
  • We’ve added support for the csharp_indent_case_contents_when_block option in EditorConfig.

Unit Testing

  • We’ve implemented support for VSTest adapters – a feature that allows you to discover and run tests from a third party framework. Now you aren’t limited by the frameworks we support out of the box. Enable the feature in ReSharper | Options | Tools | Unit Testing | Test Frameworks | VSTest.
  • We’ve implemented MSTest support in Universal Windows Platform projects for Visual Studio 2019.
  • Some of you have encountered the “spawned processes” issue: sometimes the test runner completes its work, but a process launched by it still lives. We’ve added a setting for the default course of action in this case. You can now choose between being asked what to do, doing nothing, and terminating the spawned process. And when you’re being asked about a process and decide what to do with it, your decision is saved to ReSharper | Options | Tools | Unit Testing | Test Runner. You can always delete it if it was wrong.
  • We’ve implemented a set of inspections for the AutoFixture library in NUnit. ReSharper now checks whether the test value type is correct, verifies that there are no redundant arguments in the [InlineAutoData] attribute, and warns you if there is no [TestFixture] or [Test] attribute on the test class or method.
  • We’ve upgraded our support for QUnit to version 2.14.0.

C++ Support

ReSharper C++ 2021.1 brings support for several new C++20 and C++17 language features: class types in non-type template parameters, C++20 class template argument deduction rules, and noexcept as a part of the function type. There are also new code completion items for coroutines available both in basic code completion and as postfix completion templates: co_await, co_yield, and co_return.

C++ Syntax Style

We've introduced a collection of syntax style settings that you can use to enforce the chosen code style for the syntax constructions. With the supporting inspections, quick-fixes, and the Apply Syntax Style and Cleanup selection context actions, you can apply the new style to the codebase with ease and keep the new code consistent.

Other Updates

  • We’ve added an action for copying GitHub links with the Copy FQN feature. When you call Copy Fully-qualified name from the main menu (ReSharper | Edit) or from the Ctrl+Shift+A, ReSharper does the copying and opens a context menu where you can choose from a variety of formats in case you need a non-default one. This menu now includes GitHub links.
  • If you use regular expressions in strings in C#, VB.NET, or JavaScript – even in Razor pages – you’ll probably appreciate the extend/shrink selection feature, which now works in injects as well.
  • We’ve added type conversion hints for tuple conversions.
  • A new Body constraint is available for methods in File Layout. It allows you to specify different rules for block-bodied and expression-bodied methods.

New Home Screen in dotTrace and dotMemory dotUltimate

We’ve completely reworked the Home screen in dotTrace and dotMemory. It’s now much easier to configure and start new profiling sessions, work with snapshots, and perform other basic operations.

Download

Free 30-day trial