github.com/Capventis/moq@v0.2.6-0.20220316100624-05dd47497214/pkg/moq/formatter.go (about)

     1  package moq
     2  
     3  import (
     4  	"fmt"
     5  	"go/format"
     6  
     7  	"golang.org/x/tools/imports"
     8  )
     9  
    10  func goimports(src []byte) ([]byte, error) {
    11  	formatted, err := imports.Process("filename", src, &imports.Options{
    12  		TabWidth:  8,
    13  		TabIndent: true,
    14  		Comments:  true,
    15  		Fragment:  true,
    16  	})
    17  	if err != nil {
    18  		return nil, fmt.Errorf("goimports: %s", err)
    19  	}
    20  
    21  	return formatted, nil
    22  }
    23  
    24  func gofmt(src []byte) ([]byte, error) {
    25  	formatted, err := format.Source(src)
    26  	if err != nil {
    27  		return nil, fmt.Errorf("go/format: %s", err)
    28  	}
    29  
    30  	return formatted, nil
    31  }