ReSharper 8.0 Web Help

This topic covers different ways of configuring Code Inspection in ReSHarper:

Tip

You can also use Code Annotations to customize the way ReSharper inspects your code.

Toggling design-time code inspection

By default, ReSharper enables design-time code inspection in all files corresponding to the supported languages. If necessary, you can disable it. Regardless of whether or not the design-time code inspection is enabled, you can always run code inspection in specific scope.

To disable or enable design-time code inspection
  1. In the ReSharper Options | Code Inspection | Settings, use the Enable code analysis check box to toggle the design-time code inspection. While you are on this page, you can check out available code inspection configuration options.
  2. If necessary, you can select the Analyze errors in whole solution check box to enable the Solution-Wide Analysis.
  3. Click Save to apply the modifications and let ReSharper choose the settings layer, or choose a particular settings layer in the Save To drop-down list. To learn more about saving ReSharper settings, see JetBrains .NET Tools Blog: Save or Save To in ReSharper Options.

Excluding items from code inspection

ReSharper allows you to configure the list of files, file masks, and folders that should be excluded from code inspection. The excluded items are ignored by both design-time code inspection and code inspection in specific scope.

To exclude files and folders from code analysis
  1. In the ReSharper | Options | Code Inspection | Inspection Severity, click Edit Items to Skip.
  2. In the left part of the Skip Files and Folders dialog box that opens, use Add File and Add Folder buttons to specify files or folders to skip.
  3. In the right part of the dialog box, use the Add button to specify masks (e.g. *.xml) that will exclude all matching files in the solution from the code inspection.
  4. Click OK to close the dialog box.
  5. Click Save to apply the modifications and let ReSharper choose the settings layer, or choose a particular settings layer in the Save To drop-down list. To learn more about saving ReSharper settings, see JetBrains .NET Tools Blog: Save or Save To in ReSharper Options.

Tip

If you want to exclude the current file from code inspection, press Ctrl+Shift+Alt+8Ctrl+Shift+Alt+8 and ReSharper will add this file to the list of excluded files.

If you open a file excluded from code inspection, you can recognize it by the hidden marker bar (or the Analysis is switched off errStripeOff icon if the marker bar is integrated into the enhanced scroll bar of Visual Studio 2013). To quickly toggle code analysis for the current file, press Ctrl+Shift+Alt+8Ctrl+Shift+Alt+8.

Partly disabling code inspection for generated code

You can also configure the list of files, folders, file masks, and regions that contain generated code. For these items, ReSharper runs only the code inspections that check code for compiler errors and warnings. Some file masks and regions, which are used by Visual Studio for generated code, e.g. *.designer.cs are included in this list by default, but you can change the default settings if necessary.

To specify files and regions with generated code
  1. In the ReSharper | Options | Code Inspection | Generated Code, use the the Add File and the Add Folder buttons to specify files or folders that contain generated code.
  2. In the lower left part of the page, use the Add button to specify masks (e.g. *.Designer.cs) for generated code files.
  3. In the lower right part of the page, use the Add button to specify names of the regions that contain generated code.
  4. Click Save to apply the modifications and let ReSharper choose the settings layer, or choose a particular settings layer in the Save To drop-down list. To learn more about saving ReSharper settings, see JetBrains .NET Tools Blog: Save or Save To in ReSharper Options.

Tip

The list of items containing generated code can be also used for excluding generated code from search results. To enable this, select the Filter results from generated files check box in the ReSharper Options | Environment | Search & Navigation.

Changing inspection severity levels

Each ReSharper code inspection has a specific severity level, which can be changed. For instance, by changing the severity level to Do not show, you can get rid of issues that seem trivial or being of no interest to you, or force ReSharper to display warnings as errors or suggestions, etc.

Note

Compiler errors and warnings that ReSharper highlights are not configurable the way that ReSharper's own inspections are. However, with some compiler warnings, you can use #pragma directives to suppress them. Look for this action in the action list upon a specific warning.

To change severity level of code inspections
  1. In the ReSharper | Options | Code Inspection | Inspection Severity, you can view all code inspections. You can tabs, which group inspections by languages, expandable sections, which group together similar inspections, or just type a part of the issue name in the search box.
  2. Select an inspection whose severity you want to modify.
  3. Click the drop-down list to the right of the selected entry, and choose one of five severity options:

    Changing inspection severity in the ReSharper Options dialog

  4. Click Save to apply the modifications and let ReSharper choose the settings layer, or choose a particular settings layer in the Save To drop-down list. To learn more about saving ReSharper settings, see JetBrains .NET Tools Blog: Save or Save To in ReSharper Options.

You can also access inspection severity options right from the editor.

To change inspection severity from the editor
  1. Set the caret to a code issue highlighted by a ReSharper's inspection.
  2. Press Alt+Enter or click on the action indicator, which appears to the left of the code issue, to open the action list.
  3. In the action list, choose Options for [name of inspection] inspection | Configure inspection severity:
  4. In the Inspection Options dialog box that appears, you can check the current severity level of the inspection and change it if necessary.
  5. Click Save to apply the modifications and let ReSharper choose the settings layer, or choose a particular settings layer in the Save To drop-down list. To learn more about saving ReSharper settings, see JetBrains .NET Tools Blog: Save or Save To in ReSharper Options.

Disabling code inspections with comments

One way to disable a code inspection is to change its severity level to Do not show. In this case, the inspection will be disabled everywhere.
Sometimes, you may need to partly disable a specific inspection, i.e. ignore some code issues while continue to detect other issues with this inspection. For example, ReSharper considers some code to be 'dead' and you can see that it is true. The inspection is helpful and you do not want to disable it. However, you may want to use this code later and do not want it to be highlighted in the editor or appear in the inspection results. To do so, ReSharper allows you to suppress inspections with special comments for a specific statement, function/method, tag or file.

To disable code inspections with comments
  1. Set the caret to a code issue highlighted by a ReSharper's inspection.
  2. Press Alt+Enter or click on the action indicator, which appears to the left of the code issue, to open the action list.
  3. In the action list, choose one of the following:
    • Options for [name of inspection] inspection | Disable once with comment - this option inserts a single comment - ReSharper disable once [inspection alias] - which only disables the inspection for the first occurrence of the corresponding code issue in the file.
    • Options for [name of inspection] inspection | Disable and restore with comment - this option inserts a pair of comments before and after the issue - ReSharper disable [inspection alias] and ReSharper restore [inspection alias] - which disables the inspection for all corresponding code issues between these comments.
      You can then move these comments to other places in the file so that several issues of this type are suppressed. For example, this can be useful to suppress the 'redundant namespace' inspection if you want to keep several unused namespace imports.

Tip

Starting from ReSharper 8.0, you can disable all inspections (except those detecting compiler errors) in a specific block of code — insert // ReSharper Disable All before and // ReSharper Restore All after the code block.