@@ -26,6 +26,8 @@ import (
2626 "github.com/golangci/golangci-lint/pkg/result/processors"
2727)
2828
29+ const defaultFileMode = 0644
30+
2931func getDefaultIssueExcludeHelp () string {
3032 parts := []string {"Use or not use default excludes:" }
3133 for _ , ep := range config .DefaultExcludePatterns {
@@ -381,8 +383,6 @@ func (e *Executor) setExitCodeIfIssuesFound(issues []result.Issue) {
381383 }
382384}
383385
384- const defaultFileMode = 0644
385-
386386func (e * Executor ) runAndPrint (ctx context.Context , args []string ) error {
387387 if err := e .goenv .Discover (ctx ); err != nil {
388388 e .log .Warnf ("Failed to discover go env: %s" , err )
@@ -408,27 +408,11 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
408408 if len (out ) < 2 {
409409 out = append (out , "" )
410410 }
411- w , shouldClose , err := e .createWriter (out [1 ])
412- if err != nil {
413- return fmt .Errorf ("can't create output for %s: %w" , out [1 ], err )
414- }
415411
416- p , err := e .createPrinter ( out [0 ], w )
412+ err := e .printReports ( ctx , issues , out [1 ], out [ 0 ] )
417413 if err != nil {
418- if file , ok := w .(io.Closer ); shouldClose && ok {
419- file .Close ()
420- }
421414 return err
422415 }
423- if err = p .Print (ctx , issues ); err != nil {
424- if file , ok := w .(io.Closer ); shouldClose && ok {
425- file .Close ()
426- }
427- return fmt .Errorf ("can't print %d issues: %s" , len (issues ), err )
428- }
429- if file , ok := w .(io.Closer ); shouldClose && ok {
430- file .Close ()
431- }
432416 }
433417
434418 e .setExitCodeIfIssuesFound (issues )
@@ -438,6 +422,34 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
438422 return nil
439423}
440424
425+ func (e * Executor ) printReports (ctx context.Context , issues []result.Issue , path , format string ) error {
426+ w , shouldClose , err := e .createWriter (path )
427+ if err != nil {
428+ return fmt .Errorf ("can't create output for %s: %w" , path , err )
429+ }
430+
431+ p , err := e .createPrinter (format , w )
432+ if err != nil {
433+ if file , ok := w .(io.Closer ); shouldClose && ok {
434+ _ = file .Close ()
435+ }
436+ return err
437+ }
438+
439+ if err = p .Print (ctx , issues ); err != nil {
440+ if file , ok := w .(io.Closer ); shouldClose && ok {
441+ _ = file .Close ()
442+ }
443+ return fmt .Errorf ("can't print %d issues: %s" , len (issues ), err )
444+ }
445+
446+ if file , ok := w .(io.Closer ); shouldClose && ok {
447+ _ = file .Close ()
448+ }
449+
450+ return nil
451+ }
452+
441453func (e * Executor ) createWriter (path string ) (io.Writer , bool , error ) {
442454 if path == "" || path == "stdout" {
443455 return logutils .StdOut , false , nil
0 commit comments