Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
fix fullIdent options, give = more space
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest Micklei authored and Ernest Micklei committed Feb 6, 2017
1 parent e3f28dc commit 469ccd6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion aligned.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var (
alignedEquals = leftAligned(" = ")
alignedShortEquals = leftAligned("=")
alignedSpace = leftAligned(" ")
alignedComma = leftAligned(",")
alignedComma = leftAligned(", ")
alignedEmpty = leftAligned("")
)

Expand Down
11 changes: 2 additions & 9 deletions formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,7 @@ func (f *Formatter) VisitEnum(e *Enum) {
func (f *Formatter) VisitEnumField(e *EnumField) {}

// VisitImport formats a Import.
func (f *Formatter) VisitImport(i *Import) {
f.begin("import")
kind := ""
if len(i.Kind) > 0 {
kind = fmt.Sprintf(" %s ", i.Kind)
}
fmt.Fprintf(f.w, "import %s%q;\n", kind, i.Filename)
}
func (f *Formatter) VisitImport(i *Import) {}

// VisitMessage formats a Message.
func (f *Formatter) VisitMessage(m *Message) {
Expand All @@ -84,7 +77,7 @@ func (f *Formatter) VisitOption(o *Option) {}
// VisitPackage formats a Package.
func (f *Formatter) VisitPackage(p *Package) {
f.begin("package")
fmt.Fprintf(f.w, "package %s;\n", p.Name)
fmt.Fprintf(f.w, "package %s;\n\n", p.Name)
}

// VisitService formats a Service.
Expand Down
4 changes: 2 additions & 2 deletions formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func TestPrintListOfColumns(t *testing.T) {
b := new(bytes.Buffer)
f := NewFormatter(b, " ")
f.printListOfColumns(list, "enum")
formatted := `A = 1 [a =1234];
ABC = 12 [ab=1234];
formatted := `A = 1 [a = 1234];
ABC = 12 [ab = 1234];
`
if got, want := b.String(), formatted; got != want {
t.Errorf("got [%v] want [%v]", got, want)
Expand Down
4 changes: 2 additions & 2 deletions import.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func (i *Import) columns() (cols []aligned) {
if len(i.Kind) > 0 {
cols = append(cols, leftAligned(i.Kind))
} else {
cols = append(cols, alignedSpace)
cols = append(cols, alignedEmpty)
}
cols = append(cols, alignedSpace, notAligned(fmt.Sprintf("%q", i.Filename)))
cols = append(cols, alignedEmpty, notAligned(fmt.Sprintf("%q", i.Filename)))
return
}

Expand Down
9 changes: 7 additions & 2 deletions option.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package proto

import "fmt"
import "strings"

// Option is a protoc compiler option
type Option struct {
Expand Down Expand Up @@ -31,10 +32,14 @@ func (o *Option) columns() (cols []aligned) {
// keyValuePair returns key = value or "value"
func (o *Option) keyValuePair(embedded bool) (cols []aligned) {
equals := alignedEquals
name := o.Name
if strings.Contains(name, ".") {
name = fmt.Sprintf("(%s)", name)
}
if embedded {
equals = alignedShortEquals
return append(cols, notAligned(name), equals, rightAligned(o.Constant.String()))
}
return append(cols, leftAligned(o.Name), equals, rightAligned(o.Constant.String()))
return append(cols, rightAligned(name), equals, rightAligned(o.Constant.String()))
}

// parse reads an Option body
Expand Down

0 comments on commit 469ccd6

Please sign in to comment.