diff --git a/cmd/editorconfig-checker/main.go b/cmd/editorconfig-checker/main.go index 72961fd7..ad4eb3ac 100644 --- a/cmd/editorconfig-checker/main.go +++ b/cmd/editorconfig-checker/main.go @@ -39,8 +39,8 @@ func init() { flag.BoolVar(&c.ShowVersion, "version", false, "print the version number") flag.BoolVar(&c.Help, "help", false, "print the help") flag.BoolVar(&c.Help, "h", false, "print the help") - flag.StringVar(&c.Format, "format", "default", "specify the output format: default, gcc") - flag.StringVar(&c.Format, "f", "default", "specify the output format: default, gcc") + flag.StringVar(&c.Format, "format", "default", "specify the output format: default, gcc, github-actions") + flag.StringVar(&c.Format, "f", "default", "specify the output format: default, gcc, github-actions") flag.BoolVar(&c.Verbose, "verbose", false, "print debugging information") flag.BoolVar(&c.Verbose, "v", false, "print debugging information") flag.BoolVar(&c.Debug, "debug", false, "print debugging information") diff --git a/pkg/error/error.go b/pkg/error/error.go index be62878b..d1e7f8a7 100644 --- a/pkg/error/error.go +++ b/pkg/error/error.go @@ -81,6 +81,11 @@ func PrintErrors(errors []ValidationErrors, config config.Config) { continue } + // for these formats the errors need to be consolidated first. + if config.Format == "default" || config.Format == "github-actions" { + fileErrors.Errors = ConsolidateErrors(fileErrors.Errors, config) + } + if config.Format == "gcc" { // gcc: A format mimicking the error format from GCC. for _, singleError := range fileErrors.Errors { @@ -90,10 +95,23 @@ func PrintErrors(errors []ValidationErrors, config config.Config) { } config.Logger.Error(fmt.Sprintf("%s:%d:%d: %s: %s", relativeFilePath, lineNo, 0, "error", singleError.Message)) } + } else if config.Format == "github-actions" { + // github-actions: A format dedicated for usage in Github Actions + for _, singleError := range fileErrors.Errors { + if singleError.LineNumber != -1 { + if singleError.ConsecuitiveCount != 0 { + config.Logger.Error(fmt.Sprintf("::error file=%s,line=%d,endLine=%d::%s", relativeFilePath, singleError.LineNumber, singleError.LineNumber+singleError.ConsecuitiveCount, singleError.Message)) + } else { + config.Logger.Error(fmt.Sprintf("::error file=%s,line=%d::%s", relativeFilePath, singleError.LineNumber, singleError.Message)) + } + } else { + config.Logger.Error(fmt.Sprintf("::error file=%s::%s", relativeFilePath, singleError.Message)) + } + } } else { // default: A human readable text format. config.Logger.Warning(fmt.Sprintf("%s:", relativeFilePath)) - for _, singleError := range ConsolidateErrors(fileErrors.Errors, config) { + for _, singleError := range fileErrors.Errors { if singleError.LineNumber != -1 { if singleError.ConsecuitiveCount != 0 { config.Logger.Error(fmt.Sprintf("\t%d-%d: %s", singleError.LineNumber, singleError.LineNumber+singleError.ConsecuitiveCount, singleError.Message)) diff --git a/pkg/error/error_test.go b/pkg/error/error_test.go index 79e38d5a..d5b254fa 100644 --- a/pkg/error/error_test.go +++ b/pkg/error/error_test.go @@ -157,4 +157,7 @@ func TestPrintErrors(t *testing.T) { config2 := config.Config{Format: "gcc"} PrintErrors(input, config2) + + config3 := config.Config{Format: "github-actions"} + PrintErrors(input, config3) }