From 8d4b1bbe627e20cc87acf40961748ff9143c88e3 Mon Sep 17 00:00:00 2001 From: Tony Hallett Date: Sat, 13 Jan 2024 17:18:37 +0000 Subject: [PATCH 1/3] unqualified when grouping by namespace --- .../ReportGenerator/ReportGeneratorUtil.cs | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs b/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs index 9a06e628..0fccb84d 100644 --- a/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs +++ b/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs @@ -885,7 +885,37 @@ function getCellValue(row, index){{ return code; } - private string HackGroupingToAllowAll(int groupingLevel) + private string ObserveAndHideNamespaceWhenGroupingByNamespace() + { + var code = $@" +var targetNode = document; + +var config = {{ attributes: false, childList: true, subtree: true }}; + +var callback = function(mutationsList, observer) {{ + var groupingInput = document.querySelector(""coverage-info .customizebox input""); + if(!groupingInput || groupingInput.value == 0){{ + return; + }} + + var rows = document.querySelectorAll(""coverage-info table tbody tr[class-row]""); + for(var i=0;i Date: Sat, 13 Jan 2024 19:28:50 +0000 Subject: [PATCH 2/3] add options --- .../Core/ReportGenerator/ReportGeneratorUtil.cs | 3 ++- SharedProject/Options/AppOptionsPage.cs | 6 +++++- SharedProject/Options/AppOptionsProvider.cs | 1 + SharedProject/Options/IAppOptions.cs | 10 ++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs b/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs index 0fccb84d..f30a4654 100644 --- a/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs +++ b/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs @@ -845,6 +845,7 @@ function getCellValue(row, index){{ var config = {{ attributes: false, childList: true, subtree: true }}; var callback = function(mutationsList, observer) {{ + console.log(""mutation observer hide fully covered""); var rows = document.querySelectorAll(""coverage-info table tbody tr""); for(var i=0;i Date: Sun, 14 Jan 2024 15:54:07 +0000 Subject: [PATCH 3/3] completed --- .../AppOptionsProvider_Tests.cs | 1 + ...ttingsTemplateReplacementsFactory_Tests.cs | 1 + README.md | 3 +- .../ReportGenerator/ReportGeneratorUtil.cs | 115 +++++++++++++----- SharedProject/Options/AppOptionsPage.cs | 2 +- SharedProject/Options/AppOptionsProvider.cs | 2 +- SharedProject/Options/IAppOptions.cs | 4 +- 7 files changed, 91 insertions(+), 37 deletions(-) diff --git a/FineCodeCoverageTests/AppOptionsProvider_Tests.cs b/FineCodeCoverageTests/AppOptionsProvider_Tests.cs index d005303e..0b3cd308 100644 --- a/FineCodeCoverageTests/AppOptionsProvider_Tests.cs +++ b/FineCodeCoverageTests/AppOptionsProvider_Tests.cs @@ -317,6 +317,7 @@ internal void Should_Use_Deseralized_String_From_Store_For_AppOption_Property(Fu { nameof(IAppOptions.ShowToolWindowToolbar),true}, {nameof(IAppOptions.ExcludeAssemblies),new string[]{ "Exclude"} }, {nameof(IAppOptions.IncludeAssemblies),new string[]{ "Include"} }, + {nameof(IAppOptions.NamespaceQualification),NamespaceQualification.AlwaysUnqualified } }; var mockJsonConvertService = autoMocker.GetMock(); mockJsonConvertService.Setup( diff --git a/FineCodeCoverageTests/MsCodeCoverage/RunSettingsTemplateReplacementsFactory_Tests.cs b/FineCodeCoverageTests/MsCodeCoverage/RunSettingsTemplateReplacementsFactory_Tests.cs index 1e6fc222..ebcb405b 100644 --- a/FineCodeCoverageTests/MsCodeCoverage/RunSettingsTemplateReplacementsFactory_Tests.cs +++ b/FineCodeCoverageTests/MsCodeCoverage/RunSettingsTemplateReplacementsFactory_Tests.cs @@ -701,5 +701,6 @@ internal class TestCoverageProjectOptions : IAppOptions public string[] ExcludeAssemblies { get; set; } public string[] IncludeAssemblies { get; set; } public bool DisabledNoCoverage { get; set; } + public NamespaceQualification NamespaceQualification { get; set; } } } diff --git a/README.md b/README.md index 0550f386..ee4d2df8 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,8 @@ If you are using option 1) then project and global options will only be used whe |ToolsDirectory|Folder to which copy tools subfolder. Must alredy exist. Requires restart of VS.| |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. | |StickyCoverageTable|Set to true for coverage table to have a sticky thead.| -|NamespacedClasses|Set to false to show classes in report in short form. Affects grouping.| +|NamespacedClasses|Set to false to show types in report in short form. Affects grouping.| +|NamespaceQualification|Control qualification of types in report when NamespacedClasses is true.
FullyQualified - always fully qualify.
AlwaysUnqualified - always unqualified.
UnqualifiedByNamespace - unqualified when grouping by namespace.
QualifiedByNamespaceLevel - omits the first grouping level identifier parts. Reduces space whilst maintaining uniqueness.| |HideFullyCovered|Set to true to hide classes, namespaces and assemblies that are fully covered.| |Hide0Coverage|Set to true to hide classes, namespaces and assemblies that have 0% coverage.| |Hide0Coverable|Set to false to show classes, namespaces and assemblies that are not coverable.| diff --git a/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs b/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs index f30a4654..3fc5e98d 100644 --- a/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs +++ b/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs @@ -170,7 +170,7 @@ async Task run(string outputReportType, string inputReports) reportTypeSettings.Add($@"""-reports:{inputReports}"""); reportTypeSettings.Add($@"""-plugins:{typeof(FccLightReportBuilder).Assembly.Location}"""); reportTypeSettings.Add($@"""-reporttypes:{FccLightReportBuilder.REPORT_TYPE}"""); - var (cyclomaticThreshold, crapScoreThreshold, nPathThreshold) = HotspotThresholds(); + var (cyclomaticThreshold, crapScoreThreshold, nPathThreshold) = HotspotThresholds(appOptionsProvider.Get()); reportTypeSettings.Add($@"""riskHotspotsAnalysisThresholds:metricThresholdForCyclomaticComplexity={cyclomaticThreshold}"""); reportTypeSettings.Add($@"""riskHotspotsAnalysisThresholds:metricThresholdForCrapScore={crapScoreThreshold}"""); @@ -337,9 +337,9 @@ Alternative is lighten / darken the background color style.InnerHtml = changedCss; } - private string GetStickyTableHead() + private string GetStickyTableHead(IAppOptions appOptions) { - if (!appOptionsProvider.Get().StickyCoverageTable) + if (!appOptions.StickyCoverageTable) { return ""; } @@ -829,9 +829,40 @@ private string HideGroupingCss() "; } - private string ObserveAndHideFullyCovered() + private string CoverageInfoObserver() + { + var code = @" +var coverageInfoObserver = (function(){ + var mutationObserver; + var callbacks = []; + function observe(){ + mutationObserver.observe( + document.querySelector(""coverage-info""), + { attributes: false, childList: true, subtree: true } + ) + } + function cb(record,obs){ + mutationObserver.disconnect(); + for(var i=0;i groupingLevel){ + name = namespaceParts.slice(groupingLevel).join(""."") + ""."" + type; +}"; + break; + default: + throw new Exception($"Unknown GroupingNamespaceQualification '{appOptions.NamespaceQualification}'"); + } + var alwaysUnqualified = appOptions.NamespaceQualification == NamespaceQualification.AlwaysUnqualified; var code = $@" -var targetNode = document; - var config = {{ attributes: false, childList: true, subtree: true }}; -var callback = function(mutationsList, observer) {{ +var changeQualification = function() {{ var groupingInput = document.querySelector(""coverage-info .customizebox input""); - if(!groupingInput || groupingInput.value == 0){{ + if(!groupingInput || groupingInput.value <= 0 && !{alwaysUnqualified.ToString().ToLower()}){{ return; }} - console.log(""mutation observer namespace""); + + var groupingLevel = groupingInput.value; var rows = document.querySelectorAll(""coverage-info table tbody tr[class-row]""); for(var i=0;i { - var (cyclomaticThreshold, crapScoreThreshold, nPathThreshold) = HotspotThresholds(); + var (cyclomaticThreshold, crapScoreThreshold, nPathThreshold) = HotspotThresholds(appOptions); var noRiskHotspotsHeader = "No risk hotspots that exceed options :"; var noRiskHotspotsCyclomaticMsg = $"Cyclomatic complexity : {cyclomaticThreshold}"; var noRiskHotspotsNpathMsg =$"NPath complexity : {nPathThreshold}"; @@ -1154,10 +1205,11 @@ public string ProcessUnifiedHtml(string htmlForProcessing, string reportOutputFo htmlSb.Replace("", $@"