Skip to content

Commit

Permalink
[all] Fix some lint complaints.
Browse files Browse the repository at this point in the history
  • Loading branch information
DHowett committed Mar 21, 2017
1 parent c0bafb4 commit b6f6787
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 27 deletions.
8 changes: 3 additions & 5 deletions bplist.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ func (p *bplistGenerator) writePlistValue(pval cfValue) {
case *cfDictionary:
p.writeDictionaryTag(pval)
case *cfArray:
p.writeArrayTag([]cfValue(pval.values))
p.writeArrayTag(pval.values)
case cfString:
p.writeStringTag(string(pval))
case *cfNumber:
p.writeIntTag(uint64(pval.value))
p.writeIntTag(pval.value)
case *cfReal:
if pval.wide {
p.writeRealTag(pval.value, 64)
Expand Down Expand Up @@ -155,7 +155,6 @@ func minimumSizeForInt(n uint64) int {
default:
return 8
}
panic(errors.New("illegal integer size"))
}

func (p *bplistGenerator) writeSizedInt(n uint64, nbytes int) {
Expand Down Expand Up @@ -321,7 +320,6 @@ func newBplistGenerator(w io.Writer) *bplistGenerator {
type bplistParser struct {
reader io.ReadSeeker
version int
buf []byte
objrefs map[uint64]cfValue
offtable []uint64
trailer bplistTrailer
Expand Down Expand Up @@ -466,7 +464,7 @@ func (p *bplistParser) readSizedInt(nbytes int) (uint64, uint64) {
case 8:
var val uint64
binary.Read(p.reader, binary.BigEndian, &val)
return uint64(val), 0
return val, 0
case 16:
var high, low uint64
binary.Read(p.reader, binary.BigEndian, &high)
Expand Down
12 changes: 6 additions & 6 deletions common_data_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (b *BothUnmarshaler) UnmarshalText(text []byte) error {
return errors.New("shouldn't hit this")
}

var xmlPreamble string = `<?xml version="1.0" encoding="UTF-8"?>
var xmlPreamble = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
`

Expand Down Expand Up @@ -735,7 +735,7 @@ type EverythingTestData struct {
Date time.Time `plist:"date"`
}

var plistValueTreeRawData *EverythingTestData = &EverythingTestData{
var plistValueTreeRawData = &EverythingTestData{
Intarray: []uint64{1, 8, 16, 32, 64, 2, 9, 17, 33, 65},
Floats: []float64{32.0, 64.0},
Booleans: []bool{true, false},
Expand All @@ -744,10 +744,10 @@ var plistValueTreeRawData *EverythingTestData = &EverythingTestData{
Date: time.Date(2013, 11, 27, 0, 34, 0, 0, time.UTC),
}
var plistValueTree cfValue
var plistValueTreeAsBplist []byte = []byte{98, 112, 108, 105, 115, 116, 48, 48, 214, 1, 13, 17, 21, 25, 27, 2, 14, 18, 22, 26, 28, 88, 105, 110, 116, 97, 114, 114, 97, 121, 170, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 16, 1, 16, 8, 16, 16, 16, 32, 16, 64, 16, 2, 16, 9, 16, 17, 16, 33, 16, 65, 86, 102, 108, 111, 97, 116, 115, 162, 15, 16, 34, 66, 0, 0, 0, 35, 64, 80, 0, 0, 0, 0, 0, 0, 88, 98, 111, 111, 108, 101, 97, 110, 115, 162, 19, 20, 9, 8, 87, 115, 116, 114, 105, 110, 103, 115, 162, 23, 24, 92, 72, 101, 108, 108, 111, 44, 32, 65, 83, 67, 73, 73, 105, 0, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 44, 0, 32, 78, 22, 117, 76, 84, 100, 97, 116, 97, 68, 1, 2, 3, 4, 84, 100, 97, 116, 101, 51, 65, 184, 69, 117, 120, 0, 0, 0, 8, 21, 30, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 68, 71, 76, 85, 94, 97, 98, 99, 107, 110, 123, 142, 147, 152, 157, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 166}
var plistValueTreeAsXML string = xmlPreamble + `<plist version="1.0"><dict><key>intarray</key><array><integer>1</integer><integer>8</integer><integer>16</integer><integer>32</integer><integer>64</integer><integer>2</integer><integer>9</integer><integer>17</integer><integer>33</integer><integer>65</integer></array><key>floats</key><array><real>32</real><real>64</real></array><key>booleans</key><array><true></true><false></false></array><key>strings</key><array><string>Hello, ASCII</string><string>Hello, 世界</string></array><key>data</key><data>AQIDBA==</data><key>date</key><date>2013-11-27T00:34:00Z</date></dict></plist>`
var plistValueTreeAsOpenStep string = `{booleans=(1,0,);data=<01020304>;date="2013-11-27 00:34:00 +0000";floats=(32,64,);intarray=(1,8,16,32,64,2,9,17,33,65,);strings=("Hello, ASCII","Hello, \U4e16\U754c",);}`
var plistValueTreeAsGNUStep string = `{booleans=(<*BY>,<*BN>,);data=<01020304>;date=<*D2013-11-27 00:34:00 +0000>;floats=(<*R32>,<*R64>,);intarray=(<*I1>,<*I8>,<*I16>,<*I32>,<*I64>,<*I2>,<*I9>,<*I17>,<*I33>,<*I65>,);strings=("Hello, ASCII","Hello, \U4e16\U754c",);}`
var plistValueTreeAsBplist = []byte{98, 112, 108, 105, 115, 116, 48, 48, 214, 1, 13, 17, 21, 25, 27, 2, 14, 18, 22, 26, 28, 88, 105, 110, 116, 97, 114, 114, 97, 121, 170, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 16, 1, 16, 8, 16, 16, 16, 32, 16, 64, 16, 2, 16, 9, 16, 17, 16, 33, 16, 65, 86, 102, 108, 111, 97, 116, 115, 162, 15, 16, 34, 66, 0, 0, 0, 35, 64, 80, 0, 0, 0, 0, 0, 0, 88, 98, 111, 111, 108, 101, 97, 110, 115, 162, 19, 20, 9, 8, 87, 115, 116, 114, 105, 110, 103, 115, 162, 23, 24, 92, 72, 101, 108, 108, 111, 44, 32, 65, 83, 67, 73, 73, 105, 0, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 44, 0, 32, 78, 22, 117, 76, 84, 100, 97, 116, 97, 68, 1, 2, 3, 4, 84, 100, 97, 116, 101, 51, 65, 184, 69, 117, 120, 0, 0, 0, 8, 21, 30, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 68, 71, 76, 85, 94, 97, 98, 99, 107, 110, 123, 142, 147, 152, 157, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 166}
var plistValueTreeAsXML = xmlPreamble + `<plist version="1.0"><dict><key>intarray</key><array><integer>1</integer><integer>8</integer><integer>16</integer><integer>32</integer><integer>64</integer><integer>2</integer><integer>9</integer><integer>17</integer><integer>33</integer><integer>65</integer></array><key>floats</key><array><real>32</real><real>64</real></array><key>booleans</key><array><true></true><false></false></array><key>strings</key><array><string>Hello, ASCII</string><string>Hello, 世界</string></array><key>data</key><data>AQIDBA==</data><key>date</key><date>2013-11-27T00:34:00Z</date></dict></plist>`
var plistValueTreeAsOpenStep = `{booleans=(1,0,);data=<01020304>;date="2013-11-27 00:34:00 +0000";floats=(32,64,);intarray=(1,8,16,32,64,2,9,17,33,65,);strings=("Hello, ASCII","Hello, \U4e16\U754c",);}`
var plistValueTreeAsGNUStep = `{booleans=(<*BY>,<*BN>,);data=<01020304>;date=<*D2013-11-27 00:34:00 +0000>;floats=(<*R32>,<*R64>,);intarray=(<*I1>,<*I8>,<*I16>,<*I32>,<*I64>,<*I2>,<*I9>,<*I17>,<*I33>,<*I65>,);strings=("Hello, ASCII","Hello, \U4e16\U754c",);}`

type LaxTestData struct {
I64 int64
Expand Down
2 changes: 1 addition & 1 deletion invalid_bplist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
},
*/

var InvalidBplists [][]byte = [][]byte{
var InvalidBplists = [][]byte{
// Bad magic
[]byte{
'x', 'p', 'l', 'i', 's', 't', '3', '0',
Expand Down
2 changes: 1 addition & 1 deletion invalid_text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

var InvalidTextPlists []string = []string{
var InvalidTextPlists = []string{
"(/",
"{/",
"<*I>",
Expand Down
5 changes: 2 additions & 3 deletions marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ func (p *Encoder) marshal(val reflect.Value) cfValue {
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return &cfNumber{signed: false, value: val.Uint()}
case reflect.Float32:
return &cfReal{wide: false, value: float64(val.Float())}
return &cfReal{wide: false, value: val.Float()}
case reflect.Float64:
return &cfReal{wide: true, value: float64(val.Float())}
return &cfReal{wide: true, value: val.Float()}
case reflect.Bool:
return cfBoolean(val.Bool())
case reflect.Slice, reflect.Array:
Expand Down Expand Up @@ -183,5 +183,4 @@ func (p *Encoder) marshal(val reflect.Value) cfValue {
default:
panic(&unknownTypeError{typ})
}
return nil
}
6 changes: 2 additions & 4 deletions plist_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ func (*cfNumber) typeName() string {
func (p *cfNumber) hash() interface{} {
if p.signed {
return int64(p.value)
} else {
return p.value
}
return p.value
}

type cfReal struct {
Expand All @@ -92,9 +91,8 @@ func (cfReal) typeName() string {
func (p *cfReal) hash() interface{} {
if p.wide {
return p.value
} else {
return float32(p.value)
}
return float32(p.value)
}

type cfBoolean bool
Expand Down
6 changes: 2 additions & 4 deletions text.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (p *textPlistGenerator) writePlistValue(pval cfValue) {
if pval.signed {
io.WriteString(p.writer, strconv.FormatInt(int64(pval.value), 10))
} else {
io.WriteString(p.writer, strconv.FormatUint(uint64(pval.value), 10))
io.WriteString(p.writer, strconv.FormatUint(pval.value, 10))
}
if p.format == GNUStepFormat {
p.writer.Write([]byte(`>`))
Expand All @@ -153,7 +153,7 @@ func (p *textPlistGenerator) writePlistValue(pval cfValue) {
p.writer.Write([]byte(`<*R`))
}
// GNUstep does not differentiate between 32/64-bit floats.
io.WriteString(p.writer, strconv.FormatFloat(float64(pval.value), 'g', -1, 64))
io.WriteString(p.writer, strconv.FormatFloat(pval.value, 'g', -1, 64))
if p.format == GNUStepFormat {
p.writer.Write([]byte(`>`))
}
Expand Down Expand Up @@ -517,7 +517,6 @@ func (p *textPlistParser) parseGNUStepValue(v []byte) cfValue {
return cfDate(t.In(time.UTC))
}
panic(errors.New("invalid GNUStep type " + string(typ)))
return nil
}

func (p *textPlistParser) parsePlistValue() cfValue {
Expand Down Expand Up @@ -565,7 +564,6 @@ func (p *textPlistParser) parsePlistValue() cfValue {
return p.parseUnquotedString()
}
}
return nil
}

func newTextPlistParser(r io.Reader) *textPlistParser {
Expand Down
6 changes: 3 additions & 3 deletions unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ func (p *Decoder) unmarshal(pval cfValue, val reflect.Value) {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
val.SetInt(int64(pval.value))
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
val.SetUint(uint64(pval.value))
val.SetUint(pval.value)
default:
panic(incompatibleTypeError)
}
case *cfReal:
if val.Kind() == reflect.Float32 || val.Kind() == reflect.Float64 {
// TODO: Consider warning on a downcast (storing a 64-bit value in a 32-bit reflect)
val.SetFloat(float64(pval.value))
val.SetFloat(pval.value)
} else {
panic(incompatibleTypeError)
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func (p *Decoder) valueInterface(pval cfValue) interface{} {
return pval.value
case *cfReal:
if pval.wide {
return float64(pval.value)
return pval.value
} else {
return float32(pval.value)
}
Expand Down

0 comments on commit b6f6787

Please sign in to comment.