Use Custom Patterns in ReSharper Code Quality Analysis in TFS build

I use ReSharper 2017.2.2 on the development machine together with Visual Studio 2017.5.

I'm using TFS 2017 Update 3.

On the TFS server, Visual Studio 2017.4 and ReSharper CLT 2017.2.2 are installed.

I'm using TFS build.

My goal is to do code analysis when building a solution.

enter image description hereI use the Resharper Code Quality Analysis task. I can configure it using the sln.DotSettings file which is at the root of the solution.

Standard code checks ReSharper successfully work. I can also change the warning level as shown here https://marketplace.visualstudio.com/items?itemName=alanwales.resharper-code-analysis enter image description here

For this I use ReSharper -> Options | Code Inspection -> Custom patternsenter image description here

This rule works well in Visual Studio. When I save this rule to sln.DotSettings, the following lines are added:

 <s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=4E6B3830DEEA6148909C23CD21C96E28/@KeyIndexDefined">True</s:Boolean>
 <s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=4E6B3830DEEA6148909C23CD21C96E28/LanguageName/@EntryValue">JAVA_SCRIPT</s:String>
 <s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=4E6B3830DEEA6148909C23CD21C96E28/MatchCatchClauseWithoutExceptionFilter/@EntryValue">False</s:Boolean>
 <s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=4E6B3830DEEA6148909C23CD21C96E28/SearchPattern/@EntryValue">debugger</s:String>
 <s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=4E6B3830DEEA6148909C23CD21C96E28/Severity/@EntryValue">ERROR</s:String></wpf:ResourceDictionary>

I in the JS code specially added lines with debugger. But I do not get a warning on my custom patterns.

Does Resharper Code Quality Analysis support in TFS use Custom patterns?

UPDATE 1: I checked the launch of the code analysis via the console with the command: InspectCode.exe -o="C:\temp\Results.xml" --no-swea "C:\BuildAgent\Thompson\_work\23\s\***.sln"

In the Results.xml file, I found the required line:

<Issue TypeId="StructuralSearch" Severity="ERROR" File="***.WebResources\WebResources\new_\js\forms\***.js" Offset="406-415" Line="13" Message="debugger" />

UPDATE 2: I looked at the script code RunResharperCodeAnalysisTool.ps1. In this file there are the following lines:

...
$severityLevels = @{"Hint" = 0; "Suggestion" = 1; "Warning" = 2; "Error" = 3}
...
foreach($issue in $issuesElements) {
    $severity = @($issuesTypesElements | Where-Object {$_.Attributes["Id"].Value -eq $issue.Attributes["TypeId"].Value})[0].Attributes["Severity"].Value

    $severityLevel = $severityLevels[$severity]

    if($severityLevel -ge $severityLevels[$failBuildLevelSelector]) {
        $item = New-Object -TypeName PSObject -Property @{
            'Severity' = $severity
            'Message' = $issue.Attributes["Message"].Value
            'File' = $issue.Attributes["File"].Value
            'Line' = $issue.Attributes["Line"].Value
        }

        $filteredElements.Add($item)
    }
}

The Results.xml file has the following lines:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generated by JetBrains Inspect Code 2017.2.2 -->
<Report ToolsVersion="109.0.20171006.123742">
  <Information>
    <Solution>..\..\BuildAgent\Thompson\_work\23\s\***\***.sln</Solution>
    <InspectionScope>
      <Element>Solution</Element>
    </InspectionScope>
  </Information>
  <IssueTypes>   
    <IssueType Id="StructuralSearch" Category="Structural Search Highlightings" CategoryId="StructuralSearch" Description="Structural Search Pattern" Severity="INVALID_SEVERITY" />    
    <IssueType Id="WebConfigErrors" Category="WebConfig Errors" CategoryId="WebConfigErrors" Description="" Severity="ERROR" />
  </IssueTypes>
  <Issues>
    <Project Name="***">
      <Issue TypeId="WebConfigErrors" File="***.WebResources\Web.config" Offset="531-650" Line="17" Message="Invalid module qualification: Failed to resolve assembly Microsoft.CodeDom.Providers.DotNetCompilerPlatform" />
      <Issue TypeId="WebConfigErrors" File="***.WebResources\Web.config" Offset="916-1035" Line="20" Message="Invalid module qualification: Failed to resolve assembly Microsoft.CodeDom.Providers.DotNetCompilerPlatform" />
      <Issue TypeId="StructuralSearch" Severity="ERROR" File="***.WebResources\WebResources\new_\js\forms\***.js" Offset="406-415" Line="13" Message="debugger" />
    </Project>
  </Issues>
</Report>

My Custom Patterns has Severity="INVALID_SEVERITY" which is not on the $severityLevels list.

4 comments
Official comment

Hello!

 

Thank you for contacting us and sorry for delayed reply.

JetBrains doesn't develop or maintain ReSharper Code Qulaity Analysis. Please contact plugin developer - https://marketplace.visualstudio.com/items?itemName=alanwales.resharper-code-analysis

Thank you.

Hi, I have faced with the exactly same issue trying to run the analysis in TeamCity and even locally using the latest ReSharper CLI.

Is it expected that the Custom Patterns inspections always come with INVALID_SEVERITY? Currently it prevents me from seeing the inspection results as errors on TeamCity Code Inspections tab in build results - although I do see them in the list of total issues...

Are you guys panning on changing this behavior for Custom Patterns any time soon?

 
0

Hello Alexander!

 

Thank you for the feedback.

I've filed corresponding issue - https://youtrack.jetbrains.com/issue/RSRP-472609.

Please feel free to comment or vote for it.

Thank you.

1

Alexander, yes, it's by design and not planned to be changed in near future.
Details are described here https://youtrack.jetbrains.com/issue/RSRP-471400#focus=streamItem-27-3057309-0-0

0

Please sign in to leave a comment.