ReSharper Code Inspections Issues Import in NDepend

Exporting R# Code Inspections Issues so that NDepend can collect them

Jetbrains proposes the free InspectCode Command-Line Tool. You can download InspectCode.exe from here.

InspectCode can be used this way to output R# Code Inspections Issue in .json files with the SARIF format (Static Analysis Results Interchange Format).

>cd "Path where inspectcode.exe has been unzipped"

>inspectcode.exe "Absolute path to .sln or .csproj input file" -o="Absolute Path to .json or .sarif output file"

The double quote character " are necessary only if the path contains at least one space character.

When an NDepend project references one or several .NET solution file(s) the tool expects to collect ReSharper Code Inspection' issues in .json or .sarif files in the directory $(SolutionDir)\.sarif. Thus you can specify a .json or .sarif file this directory as inspectcode.exe output file.

If the directory $(SolutionDir)\.sarif doesn't exist inspectcode.exe can create it.

If some R# Code Inspections are activated on the solution or project analyzed by inspectcode, their issues will be also outputed in the SARIF file. If SARIF files from both Roslyn Analyzers and R# Code Inspections are imported into NDepend, any collisions are resolved with priority given to issues coming from the Roslyn Analyzers SARIF files.

The json format expected to describe issues to import is SARIF (Static Analysis Results Interchange Format). SARIF is not just about ReSharper Code Inspections. Any .NET tool exporting code issues in a SARIF file format can be used, like for example, some custom tools in your company.

The NDepend Project Properties tab: Import Roslyn and R# Code Inspections Issues

Here is a screenshot of this tab below:

The NDepend Project Properties > Roslyn Analyzers Issues Import tabThe NDepend Project Properties > Roslyn Analyzers Issues Import tab
  • A) An option let's cancel the default behavior to search for SARIF .json file in the directory $(SolutionDir)\.sarif.
  • B) A button let's create both the directory $(SolutionDir)\.sarif and the file $(SolutionDir)\Directory.Build.Props (when they don't exist) for each solution referenced by the NDepend project.
  • C) Documentation about how to import issues generated ReSharper Code Inspections and also stored in SARIF files.
  • D) It is possible to specify any other directory in which to search for SARIF .json files.

Accessing the ReSharper Code Inspections issues in NDepend

ReSharper Code Inspections issues are first-class citizens in NDepend. They are shown side by side with issues generated by CQLinq rules and Roslyn Analyzers everywhere in the product.

  • In the report rule list: (see it live here)

    NDepend-Report-ReSharper-Code-Inspections
  • In the report issues in source code: (see it live here)

    NDepend-Report-ReSharper-Code-Inspections-Issues-List
  • In the report source file list: (see it live here).

    NDepend-Report-ReSharper-Code-Inspections-Issues-In-Source-Code
  • They are counted in the report projects and source files issues sum: (see it live here)

    NDepend-Report-Projects
  • There are listed in the UI Queries and Rules Explorer:

    NDepend-UI-ReSharper-Code-Inspections
  • They can be matched by any CQLinq C# LINQ query, that queries issues. In the screenshot below we can see that when a ReSharper Code Inspection is selected in the Queries and Rules Explorer panel, a C# LINQ query is generated to query the issues of the ReSharper Code Inspections:

    NDepend-UI-ReSharper-Code-Inspections-Edit

Disabling some ReSharper Code Inspection

Some ReSharper Code Inspections can be duplicate of some NDepend or Roslyn Analyzers default rules.

To avoid having duplicated rules you can turn-off some ReSharper Code Inspections in a file named $(SolutionDir)\.editorconfig This way:

[*.cs]
resharper_unused_auto_property_accessor_global_highlighting=none

This page lists both the R# inspection name and the .editorConfig property.