aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2025-04-23 07:42:06 +0200
committerTaras Madan <tarasmadan@google.com>2025-04-25 07:57:20 +0000
commit06fa70440a4f5144d2f8ea32f9eebfa80724961d (patch)
treea04252f9d9e8cf6df9c990e896a3ecf99751f3c7
parente3715315e5d4f79101d4cd782877608675dff0df (diff)
pkg/cover: always hide empty dirs
The last filtering step is the empty dirs removal.
-rw-r--r--pkg/cover/heatmap.go18
-rw-r--r--pkg/cover/heatmap_test.go12
2 files changed, 24 insertions, 6 deletions
diff --git a/pkg/cover/heatmap.go b/pkg/cover/heatmap.go
index 419a9a500..e6458c36b 100644
--- a/pkg/cover/heatmap.go
+++ b/pkg/cover/heatmap.go
@@ -259,17 +259,23 @@ func DoSubsystemsHeatMapStyleBodyJS(
}
func FormatResult(thm *templateHeatmap, format Format) {
- thm.Filter(func(row *templateHeatmapRow) bool {
- if row.IsDir && len(row.Items) > 0 {
- return true
- }
- return slices.Max(row.Covered)-row.Covered[len(row.Covered)-1] >= int64(format.FilterMinCoveredLinesDrop)
- })
+ // Remove file coverage lines with drop less than a threshold.
+ if format.FilterMinCoveredLinesDrop > 0 {
+ thm.Filter(func(row *templateHeatmapRow) bool {
+ return row.IsDir ||
+ slices.Max(row.Covered)-row.Covered[len(row.Covered)-1] >= int64(format.FilterMinCoveredLinesDrop)
+ })
+ }
+ // Remove file coverage lines with zero coverage during the analysis period.
if format.DropCoveredLines0 {
thm.Filter(func(row *templateHeatmapRow) bool {
return slices.Max(row.Covered) > 0
})
}
+ // Drop empty dir elements.
+ thm.Filter(func(row *templateHeatmapRow) bool {
+ return !row.IsDir || len(row.Items) > 0
+ })
// The files are sorted lexicographically by default.
if format.OrderByCoveredLinesDrop {
thm.Sort(func(row1 *templateHeatmapRow, row2 *templateHeatmapRow) int {
diff --git a/pkg/cover/heatmap_test.go b/pkg/cover/heatmap_test.go
index 1c094f1dd..e4b490f23 100644
--- a/pkg/cover/heatmap_test.go
+++ b/pkg/cover/heatmap_test.go
@@ -179,6 +179,11 @@ func TestFormatResult(t *testing.T) {
Covered: []int64{0, 0},
Depth: 1,
},
+ {
+ Name: "file2",
+ Covered: []int64{1, 0},
+ Depth: 1,
+ },
},
Name: "dir",
Covered: []int64{1, 0},
@@ -193,6 +198,13 @@ func TestFormatResult(t *testing.T) {
Root: &templateHeatmapRow{
Items: []*templateHeatmapRow{
{
+ Items: []*templateHeatmapRow{
+ {
+ Name: "file2",
+ Covered: []int64{1, 0},
+ Depth: 1,
+ },
+ },
Name: "dir",
Covered: []int64{1, 0},
IsDir: true,