Skip to content

Commit 0fc7365

Browse files
thaJeztahphilhofer
authored andcommitted
gofmt for current versions of go and remove stray whitespace
gofmt the code for current versions of go: - adds updated build-tag comments as used by current versions, but keeping the old format lines to remain compatible with old go versions. - format some godoc comments to fix rendeing on pkg.go.dev - uses the (now preferred) `0o` notation for octal values. also remove stray whitespace to make more linters happy. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent f75b7bc commit 0fc7365

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+204
-212
lines changed

_generated/def.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ type ArrayConstants struct {
243243
ConstantUint32 [ConstantUint32]string
244244
ConstantUint64 [ConstantUint64]string
245245
ConstantHex [0x16]string
246-
ConstantOctal [07]string
246+
ConstantOctal [0o7]string
247247
}
248248

249249
// Ensure non-msg struct tags work:

_generated/gen_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package _generated
22

33
import (
44
"bytes"
5-
"github.com/tinylib/msgp/msgp"
65
"reflect"
76
"testing"
87
"time"
8+
9+
"github.com/tinylib/msgp/msgp"
910
)
1011

1112
// benchmark encoding a small, "fast" type.
@@ -76,12 +77,11 @@ func (a *TestType) Equal(b *TestType) bool {
7677
}
7778

7879
// This covers the following cases:
79-
// - Recursive types
80-
// - Non-builtin identifiers (and recursive types)
81-
// - time.Time
82-
// - map[string]string
83-
// - anonymous structs
84-
//
80+
// - Recursive types
81+
// - Non-builtin identifiers (and recursive types)
82+
// - time.Time
83+
// - map[string]string
84+
// - anonymous structs
8585
func Test1EncodeDecode(t *testing.T) {
8686
f := 32.00
8787
tt := &TestType{

_generated/omitempty_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func mustEncodeToJSON(o msgp.Encodable) string {
2929
}
3030

3131
func TestOmitEmpty0(t *testing.T) {
32-
3332
var s string
3433

3534
var oe0a OmitEmpty0
@@ -92,12 +91,10 @@ func TestOmitEmpty0(t *testing.T) {
9291
if oe0c.AInt64 != oe0d.AInt64 {
9392
t.Fail()
9493
}
95-
9694
}
9795

9896
// TestOmitEmptyHalfFull tests mixed omitempty and not
9997
func TestOmitEmptyHalfFull(t *testing.T) {
100-
10198
var s string
10299

103100
var oeA OmitEmptyHalfFull
@@ -124,7 +121,6 @@ func TestOmitEmptyHalfFull(t *testing.T) {
124121

125122
// TestOmitEmptyLotsOFields tests the case of > 64 fields (triggers the bitmask needing to be an array instead of a single value)
126123
func TestOmitEmptyLotsOFields(t *testing.T) {
127-
128124
var s string
129125

130126
var oeLotsA OmitEmptyLotsOFields
@@ -147,11 +143,9 @@ func TestOmitEmptyLotsOFields(t *testing.T) {
147143
if s != `{"field64":"val64"}` {
148144
t.Errorf("wrong result: %s", s)
149145
}
150-
151146
}
152147

153148
func BenchmarkOmitEmpty10AllEmpty(b *testing.B) {
154-
155149
en := msgp.NewWriter(ioutil.Discard)
156150
var s OmitEmpty10
157151

@@ -163,11 +157,9 @@ func BenchmarkOmitEmpty10AllEmpty(b *testing.B) {
163157
b.Fatal(err)
164158
}
165159
}
166-
167160
}
168161

169162
func BenchmarkOmitEmpty10AllFull(b *testing.B) {
170-
171163
en := msgp.NewWriter(ioutil.Discard)
172164
var s OmitEmpty10
173165
s.Field00 = "this is the value of field00"
@@ -189,11 +181,9 @@ func BenchmarkOmitEmpty10AllFull(b *testing.B) {
189181
b.Fatal(err)
190182
}
191183
}
192-
193184
}
194185

195186
func BenchmarkNotOmitEmpty10AllEmpty(b *testing.B) {
196-
197187
en := msgp.NewWriter(ioutil.Discard)
198188
var s NotOmitEmpty10
199189

@@ -208,7 +198,6 @@ func BenchmarkNotOmitEmpty10AllEmpty(b *testing.B) {
208198
}
209199

210200
func BenchmarkNotOmitEmpty10AllFull(b *testing.B) {
211-
212201
en := msgp.NewWriter(ioutil.Discard)
213202
var s NotOmitEmpty10
214203
s.Field00 = "this is the value of field00"

gen/elem.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ var primitives = map[string]Primitive{
128128
// that satisfy all of the
129129
// interfaces.
130130
var builtins = map[string]struct{}{
131-
"msgp.Raw": struct{}{},
132-
"msgp.Number": struct{}{},
131+
"msgp.Raw": {},
132+
"msgp.Number": {},
133133
}
134134

135135
// common data/methods for every Elem
@@ -644,7 +644,6 @@ func (s *BaseElem) Resolved() bool {
644644

645645
// ZeroExpr returns the zero/empty expression or empty string if not supported.
646646
func (s *BaseElem) ZeroExpr() string {
647-
648647
switch s.Value {
649648
case Bytes:
650649
return "nil"
@@ -754,7 +753,6 @@ func writeStructFields(s []StructField, name string) {
754753
// ArrayHeader implementation in this library using uint32. On the Go side, we
755754
// can declare array lengths as any constant integer width, which breaks when
756755
// attempting a direct comparison to an array header's uint32.
757-
//
758756
func coerceArraySize(asz string) string {
759757
return fmt.Sprintf("uint32(%s)", asz)
760758
}

gen/encode.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ func (e *encodeGen) appendraw(bts []byte) {
119119
}
120120

121121
func (e *encodeGen) structmap(s *Struct) {
122-
123122
oeIdentPrefix := randIdent()
124123

125124
var data []byte

gen/marshal.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ func (m *marshalGen) tuple(s *Struct) {
114114
}
115115

116116
func (m *marshalGen) mapstruct(s *Struct) {
117-
118117
oeIdentPrefix := randIdent()
119118

120119
var data []byte

gen/spec.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,12 @@ func (p *printer) declare(name string, typ string) {
318318

319319
// does:
320320
//
321-
// if m == nil {
322-
// m = make(type, size)
323-
// } else if len(m) > 0 {
324-
// for key := range m { delete(m, key) }
325-
// }
321+
// if m == nil {
322+
// m = make(type, size)
323+
// } else if len(m) > 0 {
326324
//
325+
// for key := range m { delete(m, key) }
326+
// }
327327
func (p *printer) resizeMap(size string, m *Map) {
328328
vn := m.Varname()
329329
if !p.ok() {
@@ -368,10 +368,9 @@ func (p *printer) closeblock() { p.print("\n}") }
368368

369369
// does:
370370
//
371-
// for idx := range iter {
372-
// {{generate inner}}
373-
// }
374-
//
371+
// for idx := range iter {
372+
// {{generate inner}}
373+
// }
375374
func (p *printer) rangeBlock(ctx *Context, idx string, iter string, t traversal, inner Elem) {
376375
ctx.PushVar(idx)
377376
p.printf("\n for %s := range %s {", idx, iter)
@@ -444,7 +443,6 @@ func (b *bmask) typeDecl() string {
444443

445444
// typeName returns the type, e.g. "uint8" or "[2]uint64"
446445
func (b *bmask) typeName() string {
447-
448446
if b.bitlen <= 8 {
449447
return "uint8"
450448
}
@@ -464,7 +462,6 @@ func (b *bmask) typeName() string {
464462
// readExpr returns the expression to read from a position in the bitmask.
465463
// Compare ==0 for false or !=0 for true.
466464
func (b *bmask) readExpr(bitoffset int) string {
467-
468465
if bitoffset < 0 || bitoffset >= b.bitlen {
469466
panic(fmt.Errorf("bitoffset %d out of range for bitlen %d", bitoffset, b.bitlen))
470467
}
@@ -481,12 +478,10 @@ func (b *bmask) readExpr(bitoffset int) string {
481478
buf.WriteByte(')')
482479

483480
return buf.String()
484-
485481
}
486482

487483
// setStmt returns the statement to set the specified bit in the bitmask.
488484
func (b *bmask) setStmt(bitoffset int) string {
489-
490485
var buf bytes.Buffer
491486
buf.Grow(len(b.varname) + 16)
492487
buf.WriteString(b.varname)
@@ -496,5 +491,4 @@ func (b *bmask) setStmt(bitoffset int) string {
496491
fmt.Fprintf(&buf, " |= 0x%X", (uint64(1) << (uint64(bitoffset) % 64)))
497492

498493
return buf.String()
499-
500494
}

gen/testgen.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,4 @@ func BenchmarkDecode{{.TypeName}}(b *testing.B) {
178178
}
179179
180180
`))
181-
182181
}

gen/unmarshal.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ func (u *unmarshalGen) gStruct(s *Struct) {
7474
}
7575

7676
func (u *unmarshalGen) tuple(s *Struct) {
77-
7877
// open block
7978
sz := randIdent()
8079
u.p.declare(sz, u32)

issue185_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const debugTemp = false
2525
//
2626
// structs are currently processed alphabetically by msgp. this test relies on
2727
// that property.
28-
//
2928
func TestIssue185Idents(t *testing.T) {
3029
var identCases = []struct {
3130
tpl *template.Template
@@ -225,7 +224,7 @@ func extractVars(file string) (extractedVars, error) {
225224
}
226225

227226
func goGenerateTpl(cwd, tfile string, tpl *template.Template, tplData interface{}) error {
228-
outf, err := os.OpenFile(tfile, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0600)
227+
outf, err := os.OpenFile(tfile, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o600)
229228
if err != nil {
230229
return err
231230
}

0 commit comments

Comments
 (0)