fix linter warnings.

このコミットが含まれているのは:
Ben Lubar 2019-10-19 17:43:21 -05:00
コミット 3ff5423014
この署名に対応する既知のキーがデータベースに存在しません
GPGキーID: 92939677AB59EDA4
19個のファイルの変更57行の追加83行の削除

ファイルの表示

@ -195,7 +195,7 @@ func (m Method) Definition() jen.Code {
if len(m.function.comment) > 0 {
comment = jen.Commentf(insertNewlines(m.function.comment)).Line()
}
funcDef := jen.Empty()
var funcDef *jen.Statement
switch m.member {
case pointerMember:
funcDef = jen.Func().Params(

ファイルの表示

@ -69,8 +69,8 @@ func (s *Struct) Definition() jen.Code {
for _, m := range s.methods {
ms = append(ms, m.Name())
}
sort.Sort(sort.StringSlice(fs))
sort.Sort(sort.StringSlice(ms))
sort.Strings(fs)
sort.Strings(ms)
// Add the functions and methods in order.
for _, c := range fs {
def = def.Line().Line().Add(s.constructors[c].Definition())

ファイルの表示

@ -59,8 +59,8 @@ func (t *Typedef) Definition() jen.Code {
for _, m := range t.methods {
ms = append(ms, m.Name())
}
sort.Sort(sort.StringSlice(fs))
sort.Sort(sort.StringSlice(ms))
sort.Strings(fs)
sort.Strings(ms)
// Add the functions and methods in order
for _, c := range fs {
def = def.Line().Line().Add(t.constructors[c].Definition())

ファイルの表示

@ -14,7 +14,6 @@ import (
const (
interfacePkg = "vocab"
resolverPkg = "resolver"
typePropertyName = "type"
)
@ -43,11 +42,11 @@ type vocabulary struct {
// newVocabulary creates a vocabulary with maps already made.
func newVocabulary() vocabulary {
return vocabulary{
Values: make(map[string]*gen.Kind, 0),
FProps: make(map[string]*gen.FunctionalPropertyGenerator, 0),
NFProps: make(map[string]*gen.NonFunctionalPropertyGenerator, 0),
Types: make(map[string]*gen.TypeGenerator, 0),
References: make(map[string]*vocabulary, 0),
Values: make(map[string]*gen.Kind),
FProps: make(map[string]*gen.FunctionalPropertyGenerator),
NFProps: make(map[string]*gen.NonFunctionalPropertyGenerator),
Types: make(map[string]*gen.TypeGenerator),
References: make(map[string]*vocabulary),
}
}
@ -274,7 +273,7 @@ func (c *Converter) Convert(p *rdf.ParsedVocabulary) (f []*File, e error) {
// all vocabularies and results in a flattened converted map.
func (c *Converter) convertReferenceVocabularyRecursively(skip map[string]bool, p *rdf.ParsedVocabulary, refs map[string]*vocabulary) (v map[string]*vocabulary, e error) {
v = make(map[string]*vocabulary)
for k, _ := range p.References {
for k := range p.References {
if skip[k] {
continue
}

ファイルの表示

@ -140,7 +140,7 @@ func (p *FunctionalPropertyGenerator) multiTypeClearNonLanguageMapMembers() []je
// funcs produces the methods needed for the functional property.
func (p *FunctionalPropertyGenerator) funcs() []*codegen.Method {
kindIndexFns := make([]jen.Code, 0, len(p.kinds)+1)
for i, _ := range p.kinds {
for i := range p.kinds {
kindIndexFns = append(kindIndexFns, jen.If(
jen.Id(codegen.This()).Dot(p.isMethodName(i)).Call(),
).Block(

ファイルの表示

@ -4,7 +4,6 @@ import (
"fmt"
"github.com/dave/jennifer/jen"
"github.com/go-fed/activity/astool/codegen"
"sync"
)
const (
@ -52,9 +51,6 @@ type ManagerGenerator struct {
tgManagedMethods map[*TypeGenerator]*managedMethods
fpManagedMethods map[*FunctionalPropertyGenerator]*managedMethods
nfpManagedMethods map[*NonFunctionalPropertyGenerator]*managedMethods
// Cached during manager code generation.
cacheOnce sync.Once
cachedStruct *codegen.Struct
}
// managedMethods caches the specific methods and interfaces mapped to specific

ファイルの表示

@ -105,7 +105,7 @@ func (p *NonFunctionalPropertyGenerator) Definitions() (*codegen.Struct, *codege
// iteratorInterfaceName gets the interface name for the iterator.
func (p *NonFunctionalPropertyGenerator) iteratorInterfaceName() string {
return fmt.Sprintf("%s", strings.Title(p.iteratorTypeName().CamelName))
return strings.Title(p.iteratorTypeName().CamelName)
}
// elementTypeGenerator produces a FunctionalPropertyGenerator for the iterator

ファイルの表示

@ -447,7 +447,7 @@ func genInit(pkg Package,
)
callInitsSlice = append(callInitsSlice, key)
}
sort.Sort(sort.StringSlice(callInitsSlice))
sort.Strings(callInitsSlice)
callInits := make([]jen.Code, 0, len(callInitsSlice))
for _, c := range callInitsSlice {
callInits = append(callInits, callInitsMap[c])
@ -464,7 +464,7 @@ func genInit(pkg Package,
)
callInitsSlice = append(callInitsSlice, key)
}
sort.Sort(sort.StringSlice(callInitsSlice))
sort.Strings(callInitsSlice)
for _, c := range callInitsSlice {
callInits = append(callInits, callInitsMap[c])
}

ファイルの表示

@ -290,13 +290,13 @@ func (p *PropertyGenerator) iteratorTypeName() Identifier {
// InterfaceName returns the interface name of the property type.
func (p *PropertyGenerator) InterfaceName() string {
return fmt.Sprintf("%s", p.StructName())
return p.StructName()
}
// parentTypeInterfaceName is useful for iterators that need the base property
// type's interface name.
func (p *PropertyGenerator) parentTypeInterfaceName() string {
return fmt.Sprintf("%s", strings.TrimSuffix(p.StructName(), "Iterator"))
return strings.TrimSuffix(p.StructName(), "Iterator")
}
// PropertyName returns the name of this property, as defined in

ファイルの表示

@ -24,7 +24,6 @@ const (
errorUnhandled = "ErrUnhandledType"
errorPredicateUnmatched = "ErrPredicateUnmatched"
errorCannotTypeAssert = "errCannotTypeAssertType"
errorCannotTypeAssertPredicate = "errCannotTypeAssertPredicate"
isUnFnName = "IsUnmatchedErr"
toAliasMapFnName = "toAliasMap"
)
@ -32,21 +31,20 @@ const (
// ResolverGenerator generates the code required for the TypeResolver and the
// PredicateTypeResolver.
type ResolverGenerator struct {
pkg Package
types []*TypeGenerator
manGen *ManagerGenerator
cacheOnce sync.Once
cachedJSON *codegen.Struct
cachedTypePredicate *codegen.Struct
cachedType *codegen.Struct
cachedErrNoMatch jen.Code
cachedErrUnhandled jen.Code
cachedErrPredicateUnmatched jen.Code
cachedErrCannotTypeAssert jen.Code
cachedErrCannotTypeAssertPredicate jen.Code
cachedFns []*codegen.Function
cachedASInterface *codegen.Interface
cachedResolverInterface *codegen.Interface
pkg Package
types []*TypeGenerator
manGen *ManagerGenerator
cacheOnce sync.Once
cachedJSON *codegen.Struct
cachedTypePredicate *codegen.Struct
cachedType *codegen.Struct
cachedErrNoMatch jen.Code
cachedErrUnhandled jen.Code
cachedErrPredicateUnmatched jen.Code
cachedErrCannotTypeAssert jen.Code
cachedFns []*codegen.Function
cachedASInterface *codegen.Interface
cachedResolverInterface *codegen.Interface
}
// Creates a new ResolverGenerator for generating all the methods, functions,
@ -138,7 +136,6 @@ func (r *ResolverGenerator) Definition() (jsonRes, typeRes, typePredRes *codegen
r.cachedErrUnhandled = r.errorUnhandled()
r.cachedErrPredicateUnmatched = r.errorPredicateUnmatched()
r.cachedErrCannotTypeAssert = r.errorCannotTypeAssert()
r.cachedErrCannotTypeAssertPredicate = r.errorCannotTypeAssertPredicate()
r.cachedFns = r.fns()
r.cachedASInterface = r.asInterface()
r.cachedResolverInterface = r.resolverInterface()
@ -148,7 +145,6 @@ func (r *ResolverGenerator) Definition() (jsonRes, typeRes, typePredRes *codegen
r.cachedErrUnhandled,
r.cachedErrPredicateUnmatched,
r.cachedErrCannotTypeAssert,
r.cachedErrCannotTypeAssertPredicate,
}, r.cachedFns, []*codegen.Interface{
r.cachedASInterface,
r.cachedResolverInterface,
@ -184,16 +180,6 @@ func (r *ResolverGenerator) errorCannotTypeAssert() jen.Code {
).Line().Var().Id(errorCannotTypeAssert).Error().Op("=").Qual("errors", "New").Call(jen.Lit("activity stream type cannot be asserted to its interface"))
}
// errorCannotTypeAssertPredicate returns the declaration for the
// errCannotTypeAssert global value.
func (r *ResolverGenerator) errorCannotTypeAssertPredicate() jen.Code {
return jen.Commentf(
"%s indicates that a predicate cannot be type-casted to an "+
"expected function signature.",
errorCannotTypeAssertPredicate,
).Line().Var().Id(errorCannotTypeAssertPredicate).Error().Op("=").Qual("errors", "New").Call(jen.Lit("predicate cannot be type asserted to a known function type"))
}
// errorPredicateUnmatched returns the declaration for the ErrPredicateUnmatched
// global value.
func (r *ResolverGenerator) errorPredicateUnmatched() jen.Code {
@ -307,10 +293,7 @@ func (r *ResolverGenerator) jsonResolverMethods() (m []*codegen.Method) {
jen.If(
jen.Op("!").Id("ok"),
).Block(
jen.List(
jen.Id(vocabId),
jen.Id("_"),
).Op("=").Id("aliasMap").Index(
jen.Id(vocabId).Op("=").Id("aliasMap").Index(
jen.Lit(vocabHttp.String()),
),
),

ファイルの表示

@ -304,7 +304,7 @@ func (t *TypeGenerator) StructName() string {
// InterfaceName returns the interface name for this type.
func (t *TypeGenerator) InterfaceName() string {
return fmt.Sprintf("%s", t.StructName())
return t.StructName()
}
// Extends returns the generators of types that this ActivityStreams type
@ -450,11 +450,11 @@ func (t *TypeGenerator) allProperties() []Property {
}
}
for ext := range extends {
for k, _ := range ext.WithoutProperties() {
for k := range ext.WithoutProperties() {
delete(p, k)
}
}
for k, _ := range t.WithoutProperties() {
for k := range t.WithoutProperties() {
delete(p, k)
}
// Sort the properties into a stable order -- this is important for
@ -546,7 +546,7 @@ func (t *TypeGenerator) extendsDefinition() (*codegen.Function, *codegen.Method)
for _, name := range extends {
extendsStr = append(extendsStr, name)
}
sort.Sort(sort.StringSlice(extendsStr))
sort.Strings(extendsStr)
extensions := make([]jen.Code, 0, len(extendsStr))
for _, name := range extendsStr {
extensions = append(extensions, jen.Lit(name))
@ -595,7 +595,7 @@ func (t *TypeGenerator) getAllChildrenExtendedBy(s []string, tg *TypeGenerator)
s = append(s, e.TypeName())
s = t.getAllChildrenExtendedBy(s, e)
}
sort.Sort(sort.StringSlice(s))
sort.Strings(s)
return s
}
@ -1119,7 +1119,7 @@ func (t *TypeGenerator) constructorFn() *codegen.Function {
jen.Op("&").Qual(t.PrivatePackage().Path(), t.StructName()).Values(
jen.Dict{
jen.Id(aliasMember): jen.Lit(t.vocabAlias),
jen.Id(unknownMember): jen.Make(jen.Map(jen.String()).Interface(), jen.Lit(0)),
jen.Id(unknownMember): jen.Make(jen.Map(jen.String()).Interface()),
},
),
),
@ -1132,7 +1132,7 @@ func (t *TypeGenerator) constructorFn() *codegen.Function {
jen.Op("&").Qual(t.PrivatePackage().Path(), t.StructName()).Values(
jen.Dict{
jen.Id(aliasMember): jen.Lit(t.vocabAlias),
jen.Id(unknownMember): jen.Make(jen.Map(jen.String()).Interface(), jen.Lit(0)),
jen.Id(unknownMember): jen.Make(jen.Map(jen.String()).Interface()),
jen.Id(typeMember): jen.Id("typeProp"),
},
),

ファイルの表示

@ -12,6 +12,7 @@ import (
"github.com/go-fed/activity/astool/rdf/rfc"
"github.com/go-fed/activity/astool/rdf/schema"
"github.com/go-fed/activity/astool/rdf/xsd"
"io"
"io/ioutil"
"os"
"strings"
@ -166,9 +167,7 @@ func mustAddOntology(o rdf.Ontology) {
// into the registry, before main executes.
func init() {
flag.Usage = func() {
fmt.Fprintf(
flag.CommandLine.Output(),
helpText)
_, _ = io.WriteString(flag.CommandLine.Output(), helpText)
flag.PrintDefaults()
}
mustAddOntology(&xsd.XMLOntology{Package: "xml"})
@ -278,8 +277,7 @@ func (c *CommandLineFlags) detectPath() error {
}
c.pathAutoDetected = true
gopath = strings.Join([]string{gopath, "src", ""}, "/")
c.path.Set(strings.TrimPrefix(pwd, gopath))
return nil
return c.path.Set(strings.TrimPrefix(pwd, gopath))
}
// Validate applies custom validation logic to flags and returns an error if any

ファイルの表示

@ -59,7 +59,7 @@ func (p *ParsedVocabulary) GetReference(uri string) (*Vocabulary, error) {
return nil, err
}
if p.References == nil {
p.References = make(map[string]*Vocabulary, 0)
p.References = make(map[string]*Vocabulary)
}
if v, ok := p.References[httpSpec]; ok {
return v, nil

ファイルの表示

@ -270,12 +270,8 @@ func (l *langstring) Apply(key string, value interface{}, ctx *ParsingContext) (
jen.Id("k"),
),
),
jen.Qual("sort", "Sort").Call(
jen.Qual("sort", "StringSlice").Call(jen.Id("lk")),
),
jen.Qual("sort", "Sort").Call(
jen.Qual("sort", "StringSlice").Call(jen.Id("rk")),
),
jen.Qual("sort", "Strings").Call(jen.Id("lk")),
jen.Qual("sort", "Strings").Call(jen.Id("rk")),
jen.For(
jen.Id("i").Op(":=").Lit(0),
jen.Id("i").Op("<").Len(jen.Id("lk")).Op("&&").Id("i").Op("<").Len(jen.Id("rk")),

ファイルの表示

@ -611,6 +611,7 @@ func parseJSONLDContext(registry *RDFRegistry, input JSONLD) (nodes []RDFNode, e
s, ok := i.(string)
if !ok {
err = fmt.Errorf("single @context value is not a string")
return
}
return registry.getFor(s)
}

ファイルの表示

@ -1008,7 +1008,8 @@ func (d *duration) Apply(key string, value interface{}, ctx *rdf.ParsingContext)
),
),
jen.Id("re").Op(":=").Qual("regexp", "MustCompile").Call(
jen.Lit("P(\\d*Y)?(\\d*M)?(\\d*D)?(T(\\d*H)?(\\d*M)?(\\d*S)?)?"),
// raw string, recommended by https://github.com/dave/jennifer/issues/50
jen.Op("`P(\\d*Y)?(\\d*M)?(\\d*D)?(T(\\d*H)?(\\d*M)?(\\d*S)?)?`"),
),
jen.Id("res").Op(":=").Id("re").Dot("FindStringSubmatch").Call(jen.Id("s")),
jen.Var().Id("dur").Qual("time", "Duration"),

ファイルの表示

@ -187,7 +187,7 @@ func TestBaseActorSocialProtocol(t *testing.T) {
req := toAPRequest(toPostOutboxRequest(testCreateNoId))
delegate.EXPECT().AuthenticatePostOutbox(ctx, resp, req).Return(ctx, true, nil)
delegate.EXPECT().AddNewIds(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
activity = withNewId(activity)
withNewId(activity)
return nil
})
delegate.EXPECT().PostOutbox(
@ -217,7 +217,7 @@ func TestBaseActorSocialProtocol(t *testing.T) {
return wrappedInCreate(t), nil
})
delegate.EXPECT().AddNewIds(ctx, wrappedInCreate(toDeserializedForm(testMyNote))).DoAndReturn(func(c context.Context, activity Activity) error {
activity = withNewId(activity)
withNewId(activity)
return nil
})
delegate.EXPECT().PostOutbox(
@ -242,7 +242,7 @@ func TestBaseActorSocialProtocol(t *testing.T) {
req := toAPRequest(toPostOutboxRequest(testCreateNoId))
delegate.EXPECT().AuthenticatePostOutbox(ctx, resp, req).Return(ctx, true, nil)
delegate.EXPECT().AddNewIds(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
activity = withNewId(activity)
withNewId(activity)
return nil
})
delegate.EXPECT().PostOutbox(
@ -267,7 +267,7 @@ func TestBaseActorSocialProtocol(t *testing.T) {
req := toAPRequest(toPostOutboxRequest(testCreateNoId))
delegate.EXPECT().AuthenticatePostOutbox(ctx, resp, req).Return(ctx, true, nil)
delegate.EXPECT().AddNewIds(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
activity = withNewId(activity)
withNewId(activity)
return nil
})
delegate.EXPECT().PostOutbox(
@ -696,7 +696,7 @@ func TestBaseActor(t *testing.T) {
req := toAPRequest(toPostOutboxRequest(testCreateNoId))
delegate.EXPECT().AuthenticatePostOutbox(ctx, resp, req).Return(ctx, true, nil)
delegate.EXPECT().AddNewIds(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
activity = withNewId(activity)
withNewId(activity)
return nil
})
delegate.EXPECT().PostOutbox(
@ -723,7 +723,7 @@ func TestBaseActor(t *testing.T) {
req := toAPRequest(toPostOutboxRequest(testCreateNoId))
delegate.EXPECT().AuthenticatePostOutbox(ctx, resp, req).Return(ctx, true, nil)
delegate.EXPECT().AddNewIds(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
activity = withNewId(activity)
withNewId(activity)
return nil
})
delegate.EXPECT().PostOutbox(

ファイルの表示

@ -185,7 +185,7 @@ func (w SocialWrappedCallbacks) create(c context.Context, a vocab.ActivityStream
}
// Obtain all actor IRIs.
actors := a.GetActivityStreamsActor()
createActorIds := make(map[string]*url.URL, 0)
createActorIds := make(map[string]*url.URL)
if actors != nil {
createActorIds = make(map[string]*url.URL, actors.Len())
for iter := actors.Begin(); iter != actors.End(); iter = iter.Next() {

ファイルの表示

@ -113,7 +113,7 @@ func (h HttpSigTransport) Dereference(c context.Context, iri *url.URL) ([]byte,
if err != nil {
return nil, err
}
req.WithContext(c)
req = req.WithContext(c)
req.Header.Add(acceptHeader, acceptHeaderValue)
req.Header.Add("Accept-Charset", "utf-8")
req.Header.Add("Date", h.clock.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05")+" GMT")
@ -144,7 +144,7 @@ func (h HttpSigTransport) Deliver(c context.Context, b []byte, to *url.URL) erro
if err != nil {
return err
}
req.WithContext(c)
req = req.WithContext(c)
req.Header.Add(contentTypeHeader, contentTypeHeaderValue)
req.Header.Add("Accept-Charset", "utf-8")
req.Header.Add("Date", h.clock.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05")+" GMT")