Configure SonarLint Analyzers properties

泪湿孤枕 提交于 2020-12-10 16:05:34

问题


I've added the SonarLint C# Roslyn analyzer to a project (via the SonarAnalyzer for C# NuGet package) in Visual Studio. Is it possible to configure how the analyzer rules operate?

For example, the CodeComplexity analyser appears to have a Threshold property to which I'd like to set a different value.

I've found a couple of references to a SonarLint.xml file, but creating such a file and locating it at the solution level doesn't seem to have had any effect.

Here's the content of the SonarLint.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<AnalysisInput>
  <Rules>
    <Rule>
      <Key>S3776</Key>
      <Parameters>
        <Parameter>
          <Key>threshold</Key>
          <Value>30</Value>           
        </Parameter>
      </Parameters>
    </Rule>
  </Rules>
  <Files>
  </Files>
</AnalysisInput>

回答1:


Include the SonarLint.xml file in the project and set the Build Action file property to AdditionalFiles.

Diving in to the SonarLint source code led me to this class, which makes use of the AnalyzerOptions class. This then led me to the documentation in the Roslyn repository about Additional Files.



来源:https://stackoverflow.com/questions/42989826/configure-sonarlint-analyzers-properties

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!