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.

Inspection Smorgasbord

Here is a sampling of some new inspections that are making appearance in ReSharper 7.

  • Since an is keyword implicitly performs a null check, ReSharper will now warn if you’re also performing the null check explicitly:

  • Plenty of API calls support overloads which take string formatting specifications, but if you use string.Format() in those overloads explicitly, ReSharper will complain about the redundant call:

  • When using 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:

Async/Await-Related Inspections

ReSharper is acutely aware of the async and 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 ref or 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!

In addition to the examples above, ReSharper comes with a wealth of inspections and fixes for Windows Runtime applications as well as JavaScript. We have also previously demonstrated some inspections specific to various ReSharper features, such as INotifyPropertyChanged support and unit testing.

We hope you find these inspections useful in your day-to-day programming practice. Good luck!

This entry was posted in ReSharper Tips&Tricks and tagged , , , . Bookmark the permalink.

2 Responses to New Code Inspections in ReSharper 7

  1. Joe White says:

    Shouldn’t the multiple-enumeration quick-fix generate “as IList” instead of “as List”? If you’re trying to save unnecessary work, then you might as well do it for T[], Collection, ObservableCollection, etc., and not just List.

  2. nesteruk says:

    @Joe: You make a fair point – I’ve created an issue to that effect, please feel free to vote and/or comment.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">