Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ coverage.out
unit-test-report.json
go-covercheck
!**/go-covercheck/
*.png
19 changes: 18 additions & 1 deletion cmd/go-covercheck/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ const (
InitFlag = "init"
InitFlagUsage = "create a sample .go-covercheck.yml config file in the current directory"

HeatmapOutputFlag = "heatmap-output"
HeatmapOutputFlagShort = "o"
HeatmapOutputFlagUsage = "output file path for heatmap formats (default: coverage-heatmap.png or stdout for ASCII)"

// ConfigFilePermissions permissions.
ConfigFilePermissions = 0600
)
Expand Down Expand Up @@ -145,14 +149,16 @@ var (
config.SortOrderDesc,
)

FormatFlagUsage = fmt.Sprintf("output format [%s|%s|%s|%s|%s|%s|%s]",
FormatFlagUsage = fmt.Sprintf("output format [%s|%s|%s|%s|%s|%s|%s|%s|%s]",
config.FormatTable,
config.FormatJSON,
config.FormatYAML,
config.FormatMD,
config.FormatHTML,
config.FormatCSV,
config.FormatTSV,
config.FormatHeatmapASCII,
config.FormatHeatmapPNG,
)

SkipFlagDefault []string
Expand Down Expand Up @@ -473,6 +479,10 @@ func applyConfigOverrides(cfg *config.Config, cmd *cobra.Command, noConfigFile b
noConfigFile {
cfg.ModuleName = v
}
if v, _ := cmd.Flags().GetString(HeatmapOutputFlag); cmd.Flags().Changed(HeatmapOutputFlag) ||
noConfigFile {
cfg.HeatmapOutput = v
}

// set cfg.Total thresholds to the global values, iff no override was specified for each.
if v, _ := cmd.Flags().GetFloat64(StatementThresholdFlag); !cmd.Flags().Changed(TotalStatementThresholdFlag) &&
Expand Down Expand Up @@ -651,6 +661,13 @@ func initFlags(cmd *cobra.Command) {
false,
InitFlagUsage,
)

cmd.Flags().StringP(
HeatmapOutputFlag,
HeatmapOutputFlagShort,
"",
HeatmapOutputFlagUsage,
)
}

func shouldSkip(filename string, skip []string) bool {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/mattn/go-colorable v0.1.14
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.10.0
golang.org/x/image v0.29.0
golang.org/x/term v0.33.0
golang.org/x/tools v0.35.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
golang.org/x/exp v0.0.0-20250531010427-b6e5de432a8b h1:QoALfVG9rhQ/M7vYDScfPdWjGL9dlsVVM5VGh7aKoAA=
golang.org/x/exp v0.0.0-20250531010427-b6e5de432a8b/go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ=
golang.org/x/image v0.29.0 h1:HcdsyR4Gsuys/Axh0rDEmlBmB68rW1U9BUdB3UVHsas=
golang.org/x/image v0.29.0/go.mod h1:RVJROnf3SLK8d26OW91j4FrIHGbsJ8QnbEocVTOWQDA=
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
25 changes: 14 additions & 11 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ const (
SortOrderDesc = "desc"
SortOrderDefault = SortOrderAsc

FormatJSON = "json"
FormatYAML = "yaml"
FormatTable = "table"
FormatCSV = "csv"
FormatHTML = "html"
FormatTSV = "tsv"
FormatMD = "md"
FormatDefault = FormatTable
FormatJSON = "json"
FormatYAML = "yaml"
FormatTable = "table"
FormatCSV = "csv"
FormatHTML = "html"
FormatTSV = "tsv"
FormatMD = "md"
FormatHeatmapASCII = "heatmap-ascii"
FormatHeatmapPNG = "heatmap-png"
FormatDefault = FormatTable

thresholdOff = 0
thresholdMax = 100
Expand Down Expand Up @@ -80,6 +82,7 @@ type Config struct {
Format string `yaml:"format,omitempty"`
TerminalWidth int `yaml:"terminalWidth,omitempty"`
ModuleName string `yaml:"moduleName,omitempty"`
HeatmapOutput string `yaml:"heatmapOutput,omitempty"`
}

// Load a Config from a path or produce an error.
Expand Down Expand Up @@ -141,11 +144,11 @@ func (c *Config) Validate() error { //nolint:cyclop
}

switch c.Format {
case FormatJSON, FormatYAML, FormatTable, FormatMD, FormatCSV, FormatHTML, FormatTSV:
case FormatJSON, FormatYAML, FormatTable, FormatMD, FormatCSV, FormatHTML, FormatTSV, FormatHeatmapASCII, FormatHeatmapPNG:
break
default:
return fmt.Errorf("format must be one of %s|%s|%s|%s|%s|%s|%s",
FormatJSON, FormatYAML, FormatTable, FormatCSV, FormatHTML, FormatTSV, FormatMD)
return fmt.Errorf("format must be one of %s|%s|%s|%s|%s|%s|%s|%s|%s",
FormatJSON, FormatYAML, FormatTable, FormatCSV, FormatHTML, FormatTSV, FormatMD, FormatHeatmapASCII, FormatHeatmapPNG)
}

if c.NoSummary && c.NoTable && c.Format != FormatJSON && c.Format != FormatYAML {
Expand Down
Loading