@@ -26,6 +26,8 @@ import (
26
26
"github.com/golangci/golangci-lint/pkg/result/processors"
27
27
)
28
28
29
+ const defaultFileMode = 0644
30
+
29
31
func getDefaultIssueExcludeHelp () string {
30
32
parts := []string {"Use or not use default excludes:" }
31
33
for _ , ep := range config .DefaultExcludePatterns {
@@ -381,8 +383,6 @@ func (e *Executor) setExitCodeIfIssuesFound(issues []result.Issue) {
381
383
}
382
384
}
383
385
384
- const defaultFileMode = 0644
385
-
386
386
func (e * Executor ) runAndPrint (ctx context.Context , args []string ) error {
387
387
if err := e .goenv .Discover (ctx ); err != nil {
388
388
e .log .Warnf ("Failed to discover go env: %s" , err )
@@ -408,27 +408,11 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
408
408
if len (out ) < 2 {
409
409
out = append (out , "" )
410
410
}
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
- }
415
411
416
- p , err := e .createPrinter ( out [0 ], w )
412
+ err := e .printReports ( ctx , issues , out [1 ], out [ 0 ] )
417
413
if err != nil {
418
- if file , ok := w .(io.Closer ); shouldClose && ok {
419
- file .Close ()
420
- }
421
414
return err
422
415
}
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
- }
432
416
}
433
417
434
418
e .setExitCodeIfIssuesFound (issues )
@@ -438,6 +422,34 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
438
422
return nil
439
423
}
440
424
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
+
441
453
func (e * Executor ) createWriter (path string ) (io.Writer , bool , error ) {
442
454
if path == "" || path == "stdout" {
443
455
return logutils .StdOut , false , nil
0 commit comments