Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2019-10-16 17:54:40 +0300
committerJacob Vosmaer <jacob@gitlab.com>2019-10-16 17:54:40 +0300
commit31c6e181db1bb1d6d50124dcb8abfae6fb7a8d6e (patch)
tree2a6e178b468fb68b7dac279f1aec6859fbd80d9f /_support
parent427e0f5aa924bc310173a19cdda5b52b94b38283 (diff)
Add go brace whitespace formatter
Diffstat (limited to '_support')
-rw-r--r--_support/Makefile.template18
-rw-r--r--_support/makegen.go7
2 files changed, 19 insertions, 6 deletions
diff --git a/_support/Makefile.template b/_support/Makefile.template
index 592c1e7f9..e2982a8f6 100644
--- a/_support/Makefile.template
+++ b/_support/Makefile.template
@@ -159,17 +159,25 @@ lint: {{ .GoLint }}
go get golang.org/x/lint/golint@959b441ac422379a43da2230f62be024250818b0
.PHONY: check-formatting
-check-formatting: {{ .GoImports }}
+check-formatting: {{ .GoImports }} {{ .BraceFmt }}
# goimports
- @cd {{ .SourceDir }} && goimports -e -l {{ join .GoFiles " " }} | awk '{ print } END { if(NR>0) { print "Formatting error, run make format"; exit(1) } }'
+ @cd {{ .SourceDir }} && goimports -e -l {{ join .GoFiles " " }} | {{ .MakeFormatCheck }}
+ # bracefmt
+ @cd {{ .SourceDir }} && {{ .BraceFmt }} {{ join .GoFiles " " }} | {{ .MakeFormatCheck }}
{{ .GoImports }}:
go get golang.org/x/tools/cmd/goimports@2538eef75904eff384a2551359968e40c207d9d2
+{{ .BraceFmt }}:
+ @cd {{ .SourceDir }} && go build -o $@ ./internal/cmd/bracefmt
+
.PHONY: format
-format: {{ .GoImports }}
- # In addition to fixing imports, goimports also formats your code in the same style as gofmt
- # so it can be used as a replacement.
+format: {{ .GoImports }} {{ .BraceFmt }}
+ # goimports pass 1
+ @cd {{ .SourceDir }} && goimports -w -l {{ join .GoFiles " " }}
+ # bracefmt
+ @cd {{ .SourceDir }} && {{ .BraceFmt }} -w {{ join .GoFiles " " }}
+ # goimports pass 2
@cd {{ .SourceDir }} && goimports -w -l {{ join .GoFiles " " }}
.PHONY: staticcheck
diff --git a/_support/makegen.go b/_support/makegen.go
index 3a076317a..6849464f4 100644
--- a/_support/makegen.go
+++ b/_support/makegen.go
@@ -72,6 +72,7 @@ func (gm *gitalyMake) BuildDir() string {
func (gm *gitalyMake) Pkg() string { return "gitlab.com/gitlab-org/gitaly" }
func (gm *gitalyMake) GoImports() string { return "bin/goimports" }
+func (gm *gitalyMake) BraceFmt() string { return filepath.Join(gm.BuildDir(), "bin/bracefmt") }
func (gm *gitalyMake) GoCovMerge() string { return "bin/gocovmerge" }
func (gm *gitalyMake) GoLint() string { return "bin/golint" }
func (gm *gitalyMake) GoVendor() string { return "bin/govendor" }
@@ -249,7 +250,7 @@ func (gm *gitalyMake) GoFiles() []string {
}
}
- if !info.IsDir() && strings.HasSuffix(path, ".go") {
+ if !info.IsDir() && strings.HasSuffix(path, ".go") && !strings.HasSuffix(path, ".pb.go") {
rel, err := filepath.Rel(root, path)
if err != nil {
return err
@@ -309,6 +310,10 @@ func (gm *gitalyMake) ProtoCSHA256() string {
return protoCDownload[runtime.GOOS+"/"+runtime.GOARCH].sha256
}
+func (gm *gitalyMake) MakeFormatCheck() string {
+ return `awk '{ print } END { if(NR>0) { print "Formatting error, run make format"; exit(1) } }'`
+}
+
var templateText = func() string {
contents, err := ioutil.ReadFile("../_support/Makefile.template")
if err != nil {