ReSharper Help

Configuring Code Inspection Settings

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

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 Code Inspection | Settings options page, use the Enable code analysis check box to toggle the design-time code inspection. While you are on this page, you can check out which options you can configure for the code inspection.
  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 where to save them, or save the modifications to a specific settings layer using the Save To drop-down list. For more information, see Managing and Sharing ReSharper Settings.

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 inspection

  1. Open the Code Inspection | Settings options page.
  2. In the left part of the Skipped elements section, use Add File and Add Folder buttons to specify files or folders to be ignored by the code inspection.
  3. In the right part of this section, use the Add button to specify masks (e.g. *.xml) that will exclude all matching files in the solution from code inspection.
  4. Click Save to apply the modifications and let ReSharper choose where to save them, or save the modifications to a specific settings layer using the Save To drop-down list. For more information, see Managing and Sharing ReSharper Settings.

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 Code Inspection | Generated Code options page, 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 where to save them, or save the modifications to a specific settings layer using the Save To drop-down list. For more information, see Managing and Sharing ReSharper Settings.

The list of items containing generated code can be also used for:

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.

To change severity level of code inspections

  1. In the Code Inspection | Inspection Severity options page, you can view all configurable code inspections and their severity levels. You can use tabs, which group inspections by languages or expandable categories, which group together similar inspections,
  2. Find and select the inspection whose severity you want to modify. To find the inspection, just start typing its name. If you want all inspections in a category to have the same severity level, select this category.
  3. Click the drop-down list to the right of the selected entry, and select the desired severity level:
    Changing inspection severity in the ReSharper Options dialog
  4. If the severity level of an inspection is changed, you will see the Reset to default icon_reset_to_default button next to it, which allows you to reset the severity to its default value.
    The same button also appears next to the category where such inspection belongs, Clicking this button next to a category will reset all inspections inside the category to their default severity levels.
  5. Click Save to apply the modifications and let ReSharper choose where to save them, or save the modifications to a specific settings layer using the Save To drop-down list. For more information, see Managing and Sharing ReSharper Settings.

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 to the left of the caret to open the action list.
  3. In the action list, choose Inspecion [name of 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 where to save them, or save the modifications to a specific settings layer using the Save To drop-down list. For more information, see Managing and Sharing ReSharper Settings.

Suppressing code inspection in specific scope

One way to disable code inspections is to change their severity level to Do not show. In this case, the inspections will be disabled everywhere.
Sometimes, you may need to suppress a specific inspection in a specific place, while continue to detect other similar 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 comments or with attributes. Comments are more convenient for arbitrary pieces of code, attributes are preferable to suppress inspections in whole methods or types.

To disable (suppress) code inspection in specific scope

  1. Set the caret to a code issue highlighted by a ReSharper's inspection.
  2. Press Alt+Enter or click on the action indicator to the left of the caret to open the action list.
  3. In the action list, choose one of the following:
    • Inspection [name of inspection] | Disable once with comment - this option inserts a single comment - ReSharper disable once [inspection alias] - which only suppresses the inspection for the first occurrence of the corresponding issue.
    • Inspection [name of inspection] | Disable once with comment | Disable in file with comment - this option inserts a single comment - ReSharper disable [inspection alias] in the beginning of the file. This comment suppresses the inspection for all corresponding issues in the file.
    • Inspection [name of inspection] | Disable once with comment | 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]. These comments suppress the inspection for all corresponding issues between them.
      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.
    • Inspection [name of inspection] | Disable once with comment | Disable for method - this option adds the following attribute to the method: [SuppressMessage("ReSharper", "[inspection alias]")]. This attribute suppresses the inspection in the method.
    • Inspection [name of inspection] | Disable once with comment | Disable for class - this option adds the following attribute to the class: [SuppressMessage("ReSharper", "[inspection alias]")]. This attribute suppresses the inspection in the whole class.
    • Inspection [name of inspection] | Disable once with comment | Disable all inspection in file - this option inserts a single comment - ReSharper disable All in the beginning of the file. This comment suppresses all inspections the file.
      If necessary, you can insert the ReSharper restore All to enable code inspections after a specific line.

To suppress all inspections in a type or a method, add the following attribute: [SuppressMessage("ReSharper", "All")].

See Also

Last modified: 3 September 2015