func (g *Gofmt) Run(change scm.Change, options *Options) error {
	out, _, _, err := options.Capture(change.Repo(), "gofmt", "-l", "-s", ".")
	files := []string{}
	for _, line := range strings.Split(string(out), "\n") {
		if len(line) != 0 && !change.IsIgnored(line) {
			files = append(files, line)
		}
	}
	if len(files) != 0 {
		return fmt.Errorf("these files are improperly formatted, please run: gofmt -w -s .\n%s", strings.Join(files, "\n"))
	}
	if err != nil {
		return fmt.Errorf("gofmt -l -s . failed: %s", err)
	}
	return nil
}
Run implements Check.
package checks
import (
	"bytes"
	"errors"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
	"sync"
	"time"
	"github.com/maruel/pre-commit-go/internal"
	"github.com/maruel/pre-commit-go/scm"
)
type CheckPrerequisite struct {
	HelpCommand []string `yaml:"help_command"`
	ExpectedExitCode int `yaml:"expected_exit_code"`
	URL string
}
func (c *CheckPrerequisite) IsPresent() bool {
	_, exitCode, _ := internal.Capture(cwd, nil, c.HelpCommand...)
	return exitCode == c.ExpectedExitCode
}
type Check interface {
	GetDescription() string
	GetName() string
	GetPrerequisites() []CheckPrerequisite
	Run(change scm.Change, options *Options) error
}
type Build struct {
	BuildAll  bool     `yaml:"build_all"`
	ExtraArgs []string `yaml:"extra_args"`
}
func (b *Build) GetDescription() string {
	return "(obsolete)"
}
func (b *Build) GetName() string {
	return "build"
}
func (b *Build) GetPrerequisites() []CheckPrerequisite {
	return nil
}
func (b *Build) Run(change scm.Change, options *Options) error {
	return nil
}
type Copyright struct {
	Header string
}
func (c *Copyright) GetDescription() string {
	return "enforces all .go sources have copyright"
}
func (c *Copyright) GetName() string {
	return "copyright"
}
func (c *Copyright) GetPrerequisites() []CheckPrerequisite {
	return nil
}
func (c *Copyright) Run(change scm.Change, options *Options) error {
	var badFiles []string
	prefix := []byte(c.Header)
	for _, f := range change.Changed().GoFiles() {
		if !change.IsIgnored(f) {
			if content := change.Content(f); content != nil {
				if !bytes.HasPrefix(content, prefix) {
					badFiles = append(badFiles, f)
				}
			} else {
				badFiles = append(badFiles, f)
			}
		}
	}
	if len(badFiles) != 0 {
		return fmt.Errorf("files have invalid copyright header:\n  %s", strings.Join(badFiles, "\n  "))
	}
	return nil
}
type Gofmt struct {
}
func (g *Gofmt) GetDescription() string {
	return "enforces all .go sources are formatted with 'gofmt -s'"
}
func (g *Gofmt) GetName() string {
	return "gofmt"
}
func (g *Gofmt) GetPrerequisites() []CheckPrerequisite {
	return nil
}