New Code Inspections in ReSharper 7
As with every release, ReSharper comes with a number of inspections and fixes for diverse real-life development scenarios. This post illustrates both new inspections and quick-fixes as well as improvements to already existing analyses.
Here is a sampling of some new inspections that are making appearance in ReSharper 7.
iskeyword implicitly performs a
nullcheck, ReSharper will now warn if you’re also performing the
Plenty of API calls support overloads which take
stringformatting specifications, but if you use
string.Format()in those overloads explicitly, ReSharper will complain about the redundant call:
OrderBy()-related LINQ methods, ReSharper will now complain if there is more than one such method in a call chain, and will offer to fix the situation by using a
Then-prefixed method in the second call:
Also, ReSharper now provides usage inspections in response to Contract Annotations, which are explained in a separate post.
Quick-Fixes for Possible Multiple Enumerations
In ReSharper 6, we introduced an inspection to detect possible multiple enumerations of
IEnumerable. In ReSharper 7, we have augmented this feature with quick-fixes to turn the enumeration into either a list or an array:
Both of the options replace the original declaration type with either an array or a list, calling the appropriate LINQ conversion method if necessary. Variable creation action also offers to use either
var or an enumerable type:
ReSharper is acutely aware of the
await keywords and their proper use in .NET applications. Its support begins with basic recognition of missing or redundant keywords, together with appropriate fixes. For example, performing an
await in a non-
async method offers the following fixes:
ReSharper also takes care of various problematic use cases, such as having
out parameters in an async method:
Surround Templates as Context Actions
ReSharper has for a long time offered a separate command called Surround With Template (Ctrl+E,U) to surround blocks of code with different types of braces and preprocessing instructions. However, to make the feature even more convenient, ReSharper now offers these options as context actions when a block of code is selected. The top-level menu offers curly and round braces, with additional options offered in the submenu:
… and a lot more!
We hope you find these inspections useful in your day-to-day programming practice. Good luck!
Subscribe to Blog updates
Creating Custom AI Prompts
AI has swept through the software development industry like a wildfire. So people want to learn how to best use AI in their day to day tasks. In this post we’ll take a look at how to write custom prompts for use with the JetBrains AI Assistant in ReSharper and Rider so you can make the most of AI.&n…
12 Debugging Techniques In JetBrains Rider You Should Know About
Twelve must know debugging features in JetBrains Rider every developer should know.
Interceptors – Using C# 12 in Rider and ReSharper
Welcome to our series, where we take a closer look at the C# 12 language features and how ReSharper and Rider make it easy for you to adopt them in your codebase. If you haven’t yet, download the latest .NET 8 SDK and update your project files! In this series, we are looking at: Primary …