Skip to content

Commit

Permalink
fix: staticcheck and govet fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Apr 27, 2022
1 parent 0c00a93 commit d3091e2
Show file tree
Hide file tree
Showing 27 changed files with 48 additions and 121 deletions.
4 changes: 2 additions & 2 deletions codecHelpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ipld/go-ipld-prime/schema"
)

func Example_Marshal() {
func Example_marshal() {
type Foobar struct {
Foo string
Bar string
Expand All @@ -28,7 +28,7 @@ func Example_Marshal() {

// TODO: Example_Unmarshal, which uses nil and infers a typesystem. However, to match Example_Unmarshal_withSchema, that appears to need more features in bindnode.

func Example_Unmarshal_withSchema() {
func Example_unmarshal_withSchema() {
typesys := schema.MustTypeSystem(
schema.SpawnStruct("Foobar",
[]schema.StructField{
Expand Down
2 changes: 1 addition & 1 deletion fluent/qp/qp.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (f floatParam) Assemble(na datamodel.NodeAssembler) {
}

func Float(f float64) Assemble {
return intParam(f).Assemble
return floatParam(f).Assemble
}

type stringParam string
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/multiformats/go-multihash v0.1.0
github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e
github.com/warpfork/go-testmark v0.3.0
golang.org/x/text v0.3.7
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 h1:46ULzRKLh1CwgRq2dC5SlBzEq
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 1 addition & 1 deletion linking/cid/cidLink.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (lp LinkPrototype) BuildLink(hashsum []byte) datamodel.Link {
p := lp.Prefix

length := p.MhLength
if p.MhType == multihash.ID {
if p.MhType == multihash.IDENTITY {
length = -1
}
if p.Version == 0 && (p.MhType != multihash.SHA2_256 ||
Expand Down
8 changes: 3 additions & 5 deletions node/bindnode/infer.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func inferGoType(typ schema.Type, status map[schema.TypeName]inferredStatus, lev

// from IPLD Schema field names like "foo" to Go field names like "Foo".
func fieldNameFromSchema(name string) string {
fieldName := strings.Title(name)
fieldName := strings.Title(name) //lint:ignore SA1019 cases.Title doesn't work for this
if !token.IsIdentifier(fieldName) {
panic(fmt.Sprintf("bindnode: inferred field name %q is not a valid Go identifier", fieldName))
}
Expand Down Expand Up @@ -418,10 +418,8 @@ func inferSchema(typ reflect.Type, level int) schema.Type {
return schemaTypeBytes
}

etyp := typ.Elem()
nullable := false
if etyp.Kind() == reflect.Ptr {
etyp = etyp.Elem()
if typ.Elem().Kind() == reflect.Ptr {
nullable = true
}
etypSchema := inferSchema(typ.Elem(), level+1)
Expand All @@ -433,7 +431,7 @@ func inferSchema(typ reflect.Type, level int) schema.Type {
defaultTypeSystem.Accumulate(typSchema)
return typSchema
}
panic(fmt.Sprintf("%s", typ.Kind()))
panic(fmt.Sprintf("%d", typ.Kind()))
}

// There are currently 27 reflect.Kind iota values,
Expand Down
4 changes: 0 additions & 4 deletions node/bindnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,6 @@ type _mapAssembler struct {
// TODO: more state checks

curKey _assembler

nextIndex int // only used by repr.go
}

func (w *_mapAssembler) AssembleKey() datamodel.NodeAssembler {
Expand Down Expand Up @@ -1000,8 +998,6 @@ type _unionAssembler struct {
// TODO: more state checks

curKey _assembler

nextIndex int // only used by repr.go
}

func (w *_unionAssembler) AssembleKey() datamodel.NodeAssembler {
Expand Down
2 changes: 1 addition & 1 deletion node/tests/schemaLinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
var store = memstore.Store{}

func encode(n datamodel.Node) (datamodel.Node, datamodel.Link) {
lp := cidlink.LinkPrototype{cid.Prefix{
lp := cidlink.LinkPrototype{Prefix: cid.Prefix{
Version: 1,
Codec: 0x0129,
MhType: 0x13,
Expand Down
35 changes: 3 additions & 32 deletions node/tests/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,9 @@ import (
// they'd probably be much less fragile and give better error messages that way.
// On the other hand, the functions for condensing two-arg returns wouldn't go away anyway.

func plz(n datamodel.Node, e error) datamodel.Node {
if e != nil {
panic(e)
}
return n
}

func plzStr(n datamodel.Node, e error) string {
if e != nil {
panic(e)
}
if s, ok := n.AsString(); ok == nil {
return s
} else {
panic(ok)
}
}

func str(n datamodel.Node) string {
if s, ok := n.AsString(); ok == nil {
return s
} else {
panic(ok)
}
}

func erp(n datamodel.Node, e error) interface{} {
if e != nil {
return e
}
return n
}
// various benchmarks assign their final result here,
// in order to defuse the possibility of their work being elided.
var sink interface{} //lint:ignore U1000 used by benchmarks

// purely to syntactically flip large inline closures so we can see the argument at the top rather than the bottom of the block.
func withNode(n datamodel.Node, cb func(n datamodel.Node)) {
Expand Down
4 changes: 0 additions & 4 deletions node/tests/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (
"github.com/ipld/go-ipld-prime/traversal/selector"
)

// various benchmarks assign their final result here,
// in order to defuse the possibility of their work being elided.
var sink interface{}

func mustNodeFromJsonString(np datamodel.NodePrototype, str string) datamodel.Node {
nb := np.NewBuilder()
must.NotError(json.Decode(nb, strings.NewReader(str)))
Expand Down
2 changes: 2 additions & 0 deletions printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ func (cfg Config) oneline(typ schema.Type, isInKey bool) bool {
return isInKey // Future: this could become customizable, with some kind of Always|OnlyInKeys|Never option enum per type.
}

/* TODO: not implemented or used
// useRepr decides if a value should be printed using its representation.
// Sometimes configuring this to be true for structs or unions with stringy representations
// will cause map printouts using them as keys to become drastically more readable
// (if with some loss of informativeness, or at least loss of explicitness).
func (cfg Config) useRepr(typ schema.Type, isInKey bool) bool {
return false
}
*/

// useCmplxKeys decides if a map should print itself using a multi-line and extra-indented style for keys.
func (cfg Config) useCmplxKeys(mapn datamodel.Node) bool {
Expand Down
4 changes: 2 additions & 2 deletions schema/gen/go/adjunctCfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (cfg *AdjunctCfg) FieldSymbolUpper(f schema.StructField) string {
if x, ok := cfg.fieldSymbolUpperOverrides[FieldTuple{f.Type().Name(), f.Name()}]; ok {
return x
}
return strings.Title(f.Name())
return strings.Title(f.Name()) //lint:ignore SA1019 cases.Title doesn't work for this
}

// Comments returns a bool for whether comments should be included in gen output or not.
Expand Down Expand Up @@ -171,7 +171,7 @@ func sizeOfSchemaType(t schema.Type) uintptr {
// and validated more aggressively up front when adjcfg is loaded.
func (cfg *AdjunctCfg) UnionMemlayout(t schema.Type) string {
if t.TypeKind() != schema.TypeKind_Union {
panic(fmt.Errorf("%s is not a union!", t.Name()))
panic(fmt.Errorf("%s is not a union", t.Name()))
}
v, ok := cfg.CfgUnionMemlayout[t.Name()]
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion schema/gen/go/genBoolReprBool.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (g boolReprBoolReprGenerator) EmitNodePrototypeType(w io.Writer) {
`, w, g.AdjCfg, g)
}
func (g boolReprBoolReprGenerator) GetNodeBuilderGenerator() NodeBuilderGenerator {
return boolReprBoolReprBuilderGenerator{g.AdjCfg, g.Type}
return boolReprBoolReprBuilderGenerator(g)
}

type boolReprBoolReprBuilderGenerator struct {
Expand Down
2 changes: 1 addition & 1 deletion schema/gen/go/genBytesReprBytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (g bytesReprBytesReprGenerator) EmitNodePrototypeType(w io.Writer) {
`, w, g.AdjCfg, g)
}
func (g bytesReprBytesReprGenerator) GetNodeBuilderGenerator() NodeBuilderGenerator {
return bytesReprBytesReprBuilderGenerator{g.AdjCfg, g.Type}
return bytesReprBytesReprBuilderGenerator(g)
}

type bytesReprBytesReprBuilderGenerator struct {
Expand Down
2 changes: 1 addition & 1 deletion schema/gen/go/genFloatReprFloat.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (g float64ReprFloatReprGenerator) EmitNodePrototypeType(w io.Writer) {
`, w, g.AdjCfg, g)
}
func (g float64ReprFloatReprGenerator) GetNodeBuilderGenerator() NodeBuilderGenerator {
return float64ReprFloatReprBuilderGenerator{g.AdjCfg, g.Type}
return float64ReprFloatReprBuilderGenerator(g)
}

type float64ReprFloatReprBuilderGenerator struct {
Expand Down
2 changes: 1 addition & 1 deletion schema/gen/go/genIntReprInt.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (g intReprIntReprGenerator) EmitNodePrototypeType(w io.Writer) {
`, w, g.AdjCfg, g)
}
func (g intReprIntReprGenerator) GetNodeBuilderGenerator() NodeBuilderGenerator {
return intReprIntReprBuilderGenerator{g.AdjCfg, g.Type}
return intReprIntReprBuilderGenerator(g)
}

type intReprIntReprBuilderGenerator struct {
Expand Down
2 changes: 1 addition & 1 deletion schema/gen/go/genLinkReprLink.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (g linkReprLinkReprGenerator) EmitNodePrototypeType(w io.Writer) {
`, w, g.AdjCfg, g)
}
func (g linkReprLinkReprGenerator) GetNodeBuilderGenerator() NodeBuilderGenerator {
return linkReprLinkReprBuilderGenerator{g.AdjCfg, g.Type}
return linkReprLinkReprBuilderGenerator(g)
}

type linkReprLinkReprBuilderGenerator struct {
Expand Down
2 changes: 1 addition & 1 deletion schema/gen/go/genStringReprString.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (g stringReprStringReprGenerator) EmitNodePrototypeType(w io.Writer) {
`, w, g.AdjCfg, g)
}
func (g stringReprStringReprGenerator) GetNodeBuilderGenerator() NodeBuilderGenerator {
return stringReprStringReprBuilderGenerator{g.AdjCfg, g.Type}
return stringReprStringReprBuilderGenerator(g)
}

type stringReprStringReprBuilderGenerator struct {
Expand Down
6 changes: 1 addition & 5 deletions schema/gen/go/genUnionReprKinded.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,7 @@ func (g unionKindedReprGenerator) EmitNodePrototypeType(w io.Writer) {
// --- NodeBuilder and NodeAssembler --->

func (g unionKindedReprGenerator) GetNodeBuilderGenerator() NodeBuilderGenerator {
return unionKindedReprBuilderGenerator{
g.AdjCfg,
g.PkgName,
g.Type,
}
return unionKindedReprBuilderGenerator(g)
}

type unionKindedReprBuilderGenerator struct {
Expand Down
2 changes: 1 addition & 1 deletion schema/gen/go/mixins/templateUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func doTemplate(tmplstr string, w io.Writer, data interface{}) {
tmpl := template.Must(template.New("").
Funcs(template.FuncMap{
"title": func(s string) string { return strings.Title(s) },
"title": func(s string) string { return strings.Title(s) }, //lint:ignore SA1019 cases.Title doesn't work for this
}).
Parse(testutil.Dedent(tmplstr)))
if err := tmpl.Execute(w, data); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion schema/gen/go/templateUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func doTemplate(tmplstr string, w io.Writer, adjCfg *AdjunctCfg, data interface{
}
},
"add": func(a, b int) int { return a + b },
"title": func(s string) string { return strings.Title(s) },
"title": func(s string) string { return strings.Title(s) }, //lint:ignore SA1019 cases.Title doesn't work for this
}).
Parse(testutil.Dedent(tmplstr)))
if err := tmpl.Execute(w, data); err != nil {
Expand Down
46 changes: 0 additions & 46 deletions schema/gen/go/testutil_test.go

This file was deleted.

6 changes: 6 additions & 0 deletions schema/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,15 @@ type UnionRepresentation_Keyed struct {
type UnionRepresentation_Kinded struct {
table map[datamodel.Kind]TypeName
}

//lint:ignore U1000 implementation TODO
type UnionRepresentation_Envelope struct {
discriminantKey string
contentKey string
table map[string]TypeName // key is user-defined freetext
}

//lint:ignore U1000 implementation TODO
type UnionRepresentation_Inline struct {
discriminantKey string
table map[string]TypeName // key is user-defined freetext
Expand Down Expand Up @@ -228,6 +232,8 @@ type StructRepresentation_Map struct {
implicits map[string]ImplicitValue
}
type StructRepresentation_Tuple struct{}

//lint:ignore U1000 implementation TODO
type StructRepresentation_StringPairs struct{ sep1, sep2 string }
type StructRepresentation_Stringjoin struct{ sep string }

Expand Down
2 changes: 1 addition & 1 deletion storage/fsstore/fsstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func CheckAndMakeBasepath(basepath string) error {
return fmt.Errorf("fsstore: failed to make staging dir: %w", err)
}
if !fi.IsDir() {
return fmt.Errorf("fsstore: staging dir path contains not a dir!")
return fmt.Errorf("fsstore: staging dir path contains not a dir")
}
default:
return fmt.Errorf("fsstore: failed to make staging dir: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions storage/sharding/sharding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func printShard(fn func(string, *[]string), key string) {
fmt.Printf("%s => %s\n", key, path.Join(v...))
}

func Example_Shard_r133() {
func Example_shard_R133() {
printShard(Shard_r133, "abcdefgh")
printShard(Shard_r133, "abcdefg")
printShard(Shard_r133, "abcdef")
Expand All @@ -29,7 +29,7 @@ func Example_Shard_r133() {

}

func Example_Shard_r122() {
func Example_shard_r122() {
printShard(Shard_r122, "abcdefgh")
printShard(Shard_r122, "abcdefg")
printShard(Shard_r122, "abcdef")
Expand All @@ -46,7 +46,7 @@ func Example_Shard_r122() {
// abc => 00/ab/abc
}

func Example_Shard_r12() {
func Example_shard_r12() {
printShard(Shard_r12, "abcde")
printShard(Shard_r12, "abcd")
printShard(Shard_r12, "abc")
Expand Down
Loading

0 comments on commit d3091e2

Please sign in to comment.