Skip to content

Commit d1833f6

Browse files
committed
options for risk hotspot thresholds
1 parent 56528c5 commit d1833f6

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

FineCodeCoverage/Core/ReportGenerator/ReportGeneratorUtil.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Text;
77
using System.Threading.Tasks;
88
using FineCodeCoverage.Core.Utilities;
9+
using FineCodeCoverage.Options;
910
using Fizzler.Systems.HtmlAgilityPack;
1011
using HtmlAgilityPack;
1112
using Newtonsoft.Json;
@@ -38,7 +39,8 @@ internal partial class ReportGeneratorUtil: IReportGeneratorUtil
3839
private readonly IToolFolder toolFolder;
3940
private readonly IToolZipProvider toolZipProvider;
4041
private readonly IFileUtil fileUtil;
41-
private const string zipPrefix = "reportGenerator";
42+
private readonly IAppOptionsProvider appOptionsProvider;
43+
private const string zipPrefix = "reportGenerator";
4244
private const string zipDirectoryName = "reportGenerator";
4345

4446
public string ReportGeneratorExePath { get; private set; }
@@ -50,10 +52,12 @@ public ReportGeneratorUtil(
5052
ILogger logger,
5153
IToolFolder toolFolder,
5254
IToolZipProvider toolZipProvider,
53-
IFileUtil fileUtil
55+
IFileUtil fileUtil,
56+
IAppOptionsProvider appOptionsProvider
5457
)
5558
{
5659
this.fileUtil = fileUtil;
60+
this.appOptionsProvider = appOptionsProvider;
5761
this.assemblyUtil = assemblyUtil;
5862
this.processUtil = processUtil;
5963
this.logger = logger;
@@ -87,6 +91,15 @@ async Task<bool> run(string outputReportType, string inputReports)
8791
{
8892
reportTypeSettings.Add($@"""-reports:{inputReports}""");
8993
reportTypeSettings.Add($@"""-reporttypes:Cobertura""");
94+
var options = appOptionsProvider.Get();
95+
var cyclomaticThreshold = options.ThresholdForCyclomaticComplexity;
96+
var crapScoreThreshold = options.ThresholdForCrapScore;
97+
var nPathThreshold = options.ThresholdForNPathComplexity;
98+
99+
reportTypeSettings.Add($@"""-riskHotspotsAnalysisThresholds:metricThresholdForCyclomaticComplexity={cyclomaticThreshold}""");
100+
reportTypeSettings.Add($@"""-riskHotspotsAnalysisThresholds:metricThresholdForCrapScore={crapScoreThreshold}""");
101+
reportTypeSettings.Add($@"""-riskHotspotsAnalysisThresholds:metricThresholdForNPathComplexity={nPathThreshold}""");
102+
90103
}
91104
else if (outputReportType.Equals("HtmlInline_AzurePipelines", StringComparison.OrdinalIgnoreCase))
92105
{

FineCodeCoverage/Options/AppOptions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ internal class AppOptions : DialogPage, IAppOptions
1313
private const string coverletCategory = "Coverlet";
1414
private const string openCoverCategory = "OpenCover";
1515
private const string outputCategory = "Output";
16+
private const string reportCategory = "Report";
1617

1718
public AppOptions():this(false)
1819
{
@@ -137,6 +138,16 @@ You can also ignore additional attributes by adding to this list (short name or
137138
[Category(outputCategory)]
138139
public string FCCSolutionOutputDirectoryName { get; set; }
139140

141+
[Category(reportCategory)]
142+
[Description("When cyclomatic complexity exceeds this value for a method then the method will be present in the risk hotspots tab.")]
143+
public int ThresholdForCyclomaticComplexity { get; set; } = 30
144+
[Category(reportCategory)]
145+
[Description("When npath complexity exceeds this value for a method then the method will be present in the risk hotspots tab. OpenCover only")]
146+
public int ThresholdForNPathComplexity { get; set; } = 200
147+
[Category(reportCategory)]
148+
[Description("When crap score exceeds this value for a method then the method will be present in the risk hotspots tab. OpenCover only")]
149+
public int ThresholdForCrapScore { get; set; } = 15
150+
140151
[SuppressMessage("Usage", "VSTHRD010:Invoke single-threaded types on Main thread")]
141152
public override void SaveSettingsToStorage()
142153
{

FineCodeCoverage/Options/IAppOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ public interface IAppOptions
1818
string CoverletCollectorDirectoryPath { get; }
1919
string OpenCoverCustomPath { get; }
2020
string FCCSolutionOutputDirectoryName { get; }
21+
int ThresholdForCyclomaticComplexity { get; }
22+
int ThresholdForNPathComplexity { get; }
23+
int ThresholdForCrapScore { get; }
2124
}
2225
}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ ExcludeByFile Glob patterns specifying source files to exclude e.g. **/Migra
121121
ExcludeByAttribute Attributes to exclude from code coverage (multiple values)
122122
IncludeTestAssembly Specifies whether to report code coverage of the test assembly
123123
124+
ThresholdForCyclomaticComplexity When [cyclomatic complexity](https://en.wikipedia.org/wiki/Cyclomatic_complexity) exceeds this value for a method then the method will be present in the risk hotspots tab.
125+
ThresholdForNPathComplexity When [npath complexity](https://en.wikipedia.org/wiki/Cyclomatic_complexity) exceeds this value for a method then the method will be present in the risk hotspots tab. OpenCover only.
126+
ThresholdForCrapScore When [crap score](https://testing.googleblog.com/2011/02/this-code-is-crap.html) exceeds this value for a method then the method will be present in the risk hotspots tab. OpenCover only.
127+
124128
RunSettingsOnly Specify false for global and project options to be used for coverlet data collector configuration elements when not specified in runsettings
125129
CoverletCollectorDirectoryPath Specify path to directory containing coverlet collector files if you need functionality that the FCC version does not provide.
126130
@@ -138,6 +142,8 @@ You can ignore a method or an entire class from code coverage by creating and ap
138142
You can also ignore additional attributes by adding to the 'ExcludeByAttributes' list (short name or full name supported) e.g. :
139143
[GeneratedCode] => Present in System.CodeDom.Compiler namespace
140144
[MyCustomExcludeFromCodeCoverage] => Any custom attribute that you may define
145+
146+
141147
```
142148

143149
#### Filter Expressions

0 commit comments

Comments
 (0)