@@ -170,7 +170,7 @@ async Task run(string outputReportType, string inputReports)
170
170
reportTypeSettings.Add($@""" - reports : { inputReports } """);
171
171
reportTypeSettings.Add($@""" - plugins : { typeof ( FccLightReportBuilder ) . Assembly . Location } """);
172
172
reportTypeSettings.Add($@""" - reporttypes : { FccLightReportBuilder . REPORT_TYPE } """);
173
- var (cyclomaticThreshold, crapScoreThreshold, nPathThreshold) = HotspotThresholds();
173
+ var (cyclomaticThreshold, crapScoreThreshold, nPathThreshold) = HotspotThresholds(appOptionsProvider.Get() );
174
174
175
175
reportTypeSettings.Add($@""" riskHotspotsAnalysisThresholds: metricThresholdForCyclomaticComplexity = { cyclomaticThreshold } """);
176
176
reportTypeSettings.Add($@""" riskHotspotsAnalysisThresholds: metricThresholdForCrapScore = { crapScoreThreshold } """);
@@ -337,9 +337,9 @@ Alternative is lighten / darken the background color
337
337
style.InnerHtml = changedCss;
338
338
}
339
339
340
- private string GetStickyTableHead()
340
+ private string GetStickyTableHead(IAppOptions appOptions )
341
341
{
342
- if (!appOptionsProvider.Get() .StickyCoverageTable)
342
+ if (!appOptions .StickyCoverageTable)
343
343
{
344
344
return "";
345
345
}
@@ -829,9 +829,40 @@ private string HideGroupingCss()
829
829
";
830
830
}
831
831
832
- private string ObserveAndHideFullyCovered()
832
+ private string CoverageInfoObserver()
833
+ {
834
+ var code = @"
835
+ var coverageInfoObserver = (function(){
836
+ var mutationObserver;
837
+ var callbacks = [];
838
+ function observe(){
839
+ mutationObserver.observe(
840
+ document.querySelector(""coverage-info""),
841
+ { attributes: false, childList: true, subtree: true }
842
+ )
843
+ }
844
+ function cb(record,obs){
845
+ mutationObserver.disconnect();
846
+ for(var i=0;i<callbacks.length;i++){
847
+ callbacks[i]();
848
+ }
849
+ observe();
850
+ }
851
+ return {
852
+ observe:function(callback){
853
+ callbacks.push(callback);
854
+ if(!mutationObserver){
855
+ mutationObserver = new MutationObserver(cb);
856
+ observe();
857
+ }
858
+ }
859
+ }
860
+ })();
861
+ ";
862
+ return code;
863
+ }
864
+ private string ObserveAndHideFullyCovered(IAppOptions appOptions)
833
865
{
834
- var appOptions = appOptionsProvider.Get();
835
866
if (!(appOptions.HideFullyCovered | appOptions.Hide0Coverage | appOptions.Hide0Coverable))
836
867
{
837
868
return "";
@@ -840,12 +871,9 @@ private string ObserveAndHideFullyCovered()
840
871
function getCellValue(row, index){{
841
872
return parseInt(row.cells[index].innerText);
842
873
}}
843
- var targetNode = document;
844
874
845
- var config = {{ attributes: false, childList: true, subtree: true }};
846
875
847
- var callback = function(mutationsList, observer) {{
848
- console.log(""mutation observer hide fully covered"");
876
+ var hideCoverage = function() {{
849
877
var rows = document.querySelectorAll(""coverage-info table tbody tr"");
850
878
for(var i=0;i<rows.length;i++){{
851
879
var row = rows[i];
@@ -879,41 +907,64 @@ function getCellValue(row, index){{
879
907
880
908
}};
881
909
}};
882
-
883
- var observer = new MutationObserver(callback);
884
- observer.observe(targetNode, config);
910
+ hideCoverage();
911
+ coverageInfoObserver.observe(hideCoverage);
885
912
";
886
913
return code;
887
914
}
888
915
889
- private string ObserveAndHideNamespaceWhenGroupingByNamespace()
916
+ private string ObserveAndHideNamespaceWhenGroupingByNamespace(IAppOptions appOptions )
890
917
{
918
+
919
+ if (!appOptions.NamespacedClasses || appOptions.NamespaceQualification == NamespaceQualification.FullyQualified)
920
+ {
921
+ return "";
922
+ }
923
+ var fullyQualifiedToName = "";
924
+ switch(appOptions.NamespaceQualification)
925
+ {
926
+ case NamespaceQualification.AlwaysUnqualified:
927
+ case NamespaceQualification.UnqualifiedByNamespace:
928
+ fullyQualifiedToName = "var name = fullyQualified.substring(fullyQualified.lastIndexOf(\".\") + 1);";
929
+ break;
930
+ case NamespaceQualification.QualifiedByNamespaceLevel:
931
+ fullyQualifiedToName = @"
932
+ var parts = fullyQualified.split(""."");
933
+ var namespaceParts = parts.slice(0,parts.length-1);
934
+ var type = parts[parts.length-1];
935
+ var name = type;
936
+ if(namespaceParts.length > groupingLevel){
937
+ name = namespaceParts.slice(groupingLevel).join(""."") + ""."" + type;
938
+ }";
939
+ break;
940
+ default:
941
+ throw new Exception($"Unknown GroupingNamespaceQualification '{appOptions.NamespaceQualification}'");
942
+ }
943
+ var alwaysUnqualified = appOptions.NamespaceQualification == NamespaceQualification.AlwaysUnqualified;
891
944
var code = $@"
892
- var targetNode = document;
893
-
894
945
var config = {{ attributes: false, childList: true, subtree: true }};
895
946
896
- var callback = function(mutationsList, observer ) {{
947
+ var changeQualification = function() {{
897
948
var groupingInput = document.querySelector(""coverage-info .customizebox input"");
898
- if(!groupingInput || groupingInput.value == 0 ){{
949
+ if(!groupingInput || groupingInput.value <= 0 && !{alwaysUnqualified.ToString().ToLower()} ){{
899
950
return;
900
951
}}
901
- console.log(""mutation observer namespace"");
952
+
953
+ var groupingLevel = groupingInput.value;
902
954
var rows = document.querySelectorAll(""coverage-info table tbody tr[class-row]"");
903
955
for(var i=0;i<rows.length;i++){{
904
956
var row = rows[i];
905
957
var cell = row.cells[0];
906
958
var a = cell.querySelector(""a"");
907
959
var fullyQualified = a.innerText;
908
- var name = fullyQualified.substring(fullyQualified.lastIndexOf(""."") + 1);
960
+ {fullyQualifiedToName}
909
961
a.innerText = name;
910
962
}};
911
963
}};
912
-
913
- var observer = new MutationObserver(callback);
914
- observer.observe(targetNode, config);
964
+ changeQualification();
965
+ coverageInfoObserver.observe(changeQualification);
915
966
";
916
- return code;
967
+ return code;
917
968
}
918
969
919
970
private string HackGroupingToAllowAll(int groupingLevel)
@@ -1000,7 +1051,7 @@ public string ProcessUnifiedHtml(string htmlForProcessing, string reportOutputFo
1000
1051
ReportColours = reportColoursProvider.GetColours();
1001
1052
return assemblyUtil.RunInAssemblyResolvingContext(() =>
1002
1053
{
1003
- var (cyclomaticThreshold, crapScoreThreshold, nPathThreshold) = HotspotThresholds();
1054
+ var (cyclomaticThreshold, crapScoreThreshold, nPathThreshold) = HotspotThresholds(appOptions );
1004
1055
var noRiskHotspotsHeader = "No risk hotspots that exceed options :";
1005
1056
var noRiskHotspotsCyclomaticMsg = $"Cyclomatic complexity : {cyclomaticThreshold}";
1006
1057
var noRiskHotspotsNpathMsg =$"NPath complexity : {nPathThreshold}";
@@ -1154,10 +1205,11 @@ public string ProcessUnifiedHtml(string htmlForProcessing, string reportOutputFo
1154
1205
1155
1206
htmlSb.Replace("</body>", $@"
1156
1207
<script type=""text/javascript"">
1157
- {GetStickyTableHead()}
1208
+ {GetStickyTableHead(appOptions )}
1158
1209
{HackGroupingToAllowAll(groupingLevel)}
1159
- {ObserveAndHideFullyCovered()}
1160
- {ObserveAndHideNamespaceWhenGroupingByNamespace()}
1210
+ {CoverageInfoObserver()}
1211
+ {ObserveAndHideNamespaceWhenGroupingByNamespace(appOptions)}
1212
+ {ObserveAndHideFullyCovered(appOptions)}
1161
1213
function getRuleBySelector(cssRules,selector){{
1162
1214
for(var i=0;i<cssRules.length;i++){{
1163
1215
if(cssRules[i].selectorText == selector){{
@@ -1672,13 +1724,12 @@ private void HideRowsFromOverviewTable(HtmlDocument doc)
1672
1724
}
1673
1725
}
1674
1726
1675
- private ( int cyclomaticThreshold , int crapScoreThreshold , int nPathThreshold ) HotspotThresholds( )
1727
+ private ( int cyclomaticThreshold , int crapScoreThreshold , int nPathThreshold ) HotspotThresholds( IAppOptions appOptions )
1676
1728
{
1677
- var options = appOptionsProvider. Get ( ) ;
1678
1729
return (
1679
- options . ThresholdForCyclomaticComplexity ,
1680
- options . ThresholdForCrapScore ,
1681
- options . ThresholdForNPathComplexity
1730
+ appOptions . ThresholdForCyclomaticComplexity ,
1731
+ appOptions . ThresholdForCrapScore ,
1732
+ appOptions . ThresholdForNPathComplexity
1682
1733
) ;
1683
1734
1684
1735
}
0 commit comments