goose: clean up comments into full sentences
Capitalize and end with period where missing. Reviewed-by: Chris Lewis <cflewis@google.com>
This commit is contained in:
@@ -78,7 +78,7 @@ func solve(mc *providerSetCache, out types.Type, given []types.Type, sets []symr
|
|||||||
}
|
}
|
||||||
for _, in := range trail[:len(trail)-1] {
|
for _, in := range trail[:len(trail)-1] {
|
||||||
if types.Identical(typ, in.Type) {
|
if types.Identical(typ, in.Type) {
|
||||||
// TODO(light): describe cycle
|
// TODO(light): Describe cycle.
|
||||||
return fmt.Errorf("cycle for %s", types.TypeString(typ, nil))
|
return fmt.Errorf("cycle for %s", types.TypeString(typ, nil))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ func solve(mc *providerSetCache, out types.Type, given []types.Type, sets []symr
|
|||||||
if len(trail) == 1 {
|
if len(trail) == 1 {
|
||||||
return fmt.Errorf("no provider found for %s (output of injector)", types.TypeString(typ, nil))
|
return fmt.Errorf("no provider found for %s (output of injector)", types.TypeString(typ, nil))
|
||||||
}
|
}
|
||||||
// TODO(light): give name of provider
|
// TODO(light): Give name of provider.
|
||||||
return fmt.Errorf("no provider found for %s (required by provider of %s)", types.TypeString(typ, nil), types.TypeString(trail[len(trail)-2].Type, nil))
|
return fmt.Errorf("no provider found for %s (required by provider of %s)", types.TypeString(typ, nil), types.TypeString(trail[len(trail)-2].Type, nil))
|
||||||
}
|
}
|
||||||
if !types.Identical(p.Out, typ) {
|
if !types.Identical(p.Out, typ) {
|
||||||
@@ -100,7 +100,7 @@ func solve(mc *providerSetCache, out types.Type, given []types.Type, sets []symr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, a := range p.Args {
|
for _, a := range p.Args {
|
||||||
// TODO(light): this will discard grown trail arrays.
|
// TODO(light): This will discard grown trail arrays.
|
||||||
if err := visit(append(trail, a)); err != nil {
|
if err := visit(append(trail, a)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -198,7 +198,7 @@ func buildProviderMap(mc *providerSetCache, sets []symref) (*typeutil.Map, error
|
|||||||
if prev := pm.At(b.Iface); prev != nil {
|
if prev := pm.At(b.Iface); prev != nil {
|
||||||
pos := mc.fset.Position(b.Pos)
|
pos := mc.fset.Position(b.Pos)
|
||||||
typ := types.TypeString(b.Iface, nil)
|
typ := types.TypeString(b.Iface, nil)
|
||||||
// TODO(light): error message for conflicting with another interface binding will point at provider instead of binding.
|
// TODO(light): Error message for conflicting with another interface binding will point at provider instead of binding.
|
||||||
prevPos := mc.fset.Position(prev.(*Provider).Pos)
|
prevPos := mc.fset.Position(prev.(*Provider).Pos)
|
||||||
if b.from.importPath == "" {
|
if b.from.importPath == "" {
|
||||||
// Provider set is imported directly by injector.
|
// Provider set is imported directly by injector.
|
||||||
|
|||||||
@@ -90,8 +90,7 @@ func Generate(bctx *build.Context, wd string, pkg string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newLoaderConfig(bctx *build.Context, wd string, inject bool) *loader.Config {
|
func newLoaderConfig(bctx *build.Context, wd string, inject bool) *loader.Config {
|
||||||
// TODO(light): allow errors
|
// TODO(light): Stop errors from printing to stderr.
|
||||||
// TODO(light): stop errors from printing to stderr
|
|
||||||
conf := &loader.Config{
|
conf := &loader.Config{
|
||||||
Build: bctx,
|
Build: bctx,
|
||||||
ParserMode: parser.ParseComments,
|
ParserMode: parser.ParseComments,
|
||||||
@@ -218,7 +217,7 @@ func (g *gen) inject(mc *providerSetCache, name string, sig *types.Signature, se
|
|||||||
}
|
}
|
||||||
outTypeString := types.TypeString(outType, g.qualifyPkg)
|
outTypeString := types.TypeString(outType, g.qualifyPkg)
|
||||||
zv := zeroValue(outType, g.qualifyPkg)
|
zv := zeroValue(outType, g.qualifyPkg)
|
||||||
// Set up local variables
|
// Set up local variables.
|
||||||
paramNames := make([]string, params.Len())
|
paramNames := make([]string, params.Len())
|
||||||
localNames := make([]string, len(calls))
|
localNames := make([]string, len(calls))
|
||||||
cleanupNames := make([]string, len(calls))
|
cleanupNames := make([]string, len(calls))
|
||||||
@@ -333,7 +332,7 @@ func (g *gen) inject(mc *providerSetCache, name string, sig *types.Signature, se
|
|||||||
if returnsCleanup {
|
if returnsCleanup {
|
||||||
g.p(", nil")
|
g.p(", nil")
|
||||||
}
|
}
|
||||||
// TODO(light): give information about failing provider
|
// TODO(light): Give information about failing provider.
|
||||||
g.p(", err\n")
|
g.p(", err\n")
|
||||||
g.p("\t}\n")
|
g.p("\t}\n")
|
||||||
}
|
}
|
||||||
@@ -376,7 +375,7 @@ func (g *gen) qualifyImport(path string) string {
|
|||||||
if path == g.currPackage {
|
if path == g.currPackage {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
// TODO(light): this is depending on details of the current loader.
|
// TODO(light): This is depending on details of the current loader.
|
||||||
const vendorPart = "vendor/"
|
const vendorPart = "vendor/"
|
||||||
unvendored := path
|
unvendored := path
|
||||||
if i := strings.LastIndex(path, vendorPart); i != -1 && (i == 0 || path[i-1] == '/') {
|
if i := strings.LastIndex(path, vendorPart); i != -1 && (i == 0 || path[i-1] == '/') {
|
||||||
@@ -385,7 +384,7 @@ func (g *gen) qualifyImport(path string) string {
|
|||||||
if name := g.imports[unvendored]; name != "" {
|
if name := g.imports[unvendored]; name != "" {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
// TODO(light): use parts of import path to disambiguate.
|
// TODO(light): Use parts of import path to disambiguate.
|
||||||
name := disambiguate(g.prog.Package(path).Pkg.Name(), func(n string) bool {
|
name := disambiguate(g.prog.Package(path).Pkg.Name(), func(n string) bool {
|
||||||
// Don't let an import take the "err" name. That's annoying.
|
// Don't let an import take the "err" name. That's annoying.
|
||||||
return n == "err" || g.nameInFileScope(n)
|
return n == "err" || g.nameInFileScope(n)
|
||||||
@@ -447,7 +446,7 @@ func typeVariableName(t types.Type) string {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
// TODO(light): include package name when appropriate
|
// TODO(light): Include package name when appropriate.
|
||||||
return unexport(tn.Obj().Name())
|
return unexport(tn.Obj().Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func TestGoose(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
const testRoot = "testdata"
|
const testRoot = "testdata"
|
||||||
testdataEnts, err := ioutil.ReadDir(testRoot) // ReadDir sorts by name
|
testdataEnts, err := ioutil.ReadDir(testRoot) // ReadDir sorts by name.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -473,7 +473,7 @@ func runGo(bctx *build.Context, args ...string) error {
|
|||||||
} else {
|
} else {
|
||||||
c.Env = append(c.Env, "CGO_ENABLED=0")
|
c.Env = append(c.Env, "CGO_ENABLED=0")
|
||||||
}
|
}
|
||||||
// TODO(someday): set -compiler flag if needed.
|
// TODO(someday): Set -compiler flag if needed.
|
||||||
out, err := c.CombinedOutput()
|
out, err := c.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if len(out) > 0 {
|
if len(out) > 0 {
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ func processDeclDirectives(fctx findContext, sets map[string]*ProviderSet, scope
|
|||||||
}
|
}
|
||||||
var providerSetName string
|
var providerSetName string
|
||||||
if args := p.args(); len(args) == 1 {
|
if args := p.args(); len(args) == 1 {
|
||||||
// TODO(light): validate identifier
|
// TODO(light): Validate identifier.
|
||||||
providerSetName = args[0]
|
providerSetName = args[0]
|
||||||
} else if len(args) > 1 {
|
} else if len(args) > 1 {
|
||||||
return fmt.Errorf("%v: goose:provide takes at most one argument", fctx.fset.Position(p.pos))
|
return fmt.Errorf("%v: goose:provide takes at most one argument", fctx.fset.Position(p.pos))
|
||||||
@@ -360,7 +360,7 @@ func processDeclDirectives(fctx findContext, sets map[string]*ProviderSet, scope
|
|||||||
return fmt.Errorf("%v: only functions and structs can be marked as providers", fctx.fset.Position(p.pos))
|
return fmt.Errorf("%v: only functions and structs can be marked as providers", fctx.fset.Position(p.pos))
|
||||||
}
|
}
|
||||||
if len(decl.Specs) != 1 {
|
if len(decl.Specs) != 1 {
|
||||||
// TODO(light): tighten directive extraction to associate with particular specs.
|
// TODO(light): Tighten directive extraction to associate with particular specs.
|
||||||
return fmt.Errorf("%v: only functions and structs can be marked as providers", fctx.fset.Position(p.pos))
|
return fmt.Errorf("%v: only functions and structs can be marked as providers", fctx.fset.Position(p.pos))
|
||||||
}
|
}
|
||||||
typeName := fctx.typeInfo.ObjectOf(decl.Specs[0].(*ast.TypeSpec).Name).(*types.TypeName)
|
typeName := fctx.typeInfo.ObjectOf(decl.Specs[0].(*ast.TypeSpec).Name).(*types.TypeName)
|
||||||
@@ -533,7 +533,7 @@ type symref struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseSymbolRef(r *importResolver, ref string, s *types.Scope, pkg string, pos token.Pos) (symref, error) {
|
func parseSymbolRef(r *importResolver, ref string, s *types.Scope, pkg string, pos token.Pos) (symref, error) {
|
||||||
// TODO(light): verify that provider set name is an identifier before returning
|
// TODO(light): Verify that provider set name is an identifier before returning.
|
||||||
|
|
||||||
i := strings.LastIndexByte(ref, '.')
|
i := strings.LastIndexByte(ref, '.')
|
||||||
if i == -1 {
|
if i == -1 {
|
||||||
@@ -698,12 +698,12 @@ func extractDirectives(d []directive, cg *ast.CommentGroup) []directive {
|
|||||||
d = append(d, directive{
|
d = append(d, directive{
|
||||||
kind: line[:i],
|
kind: line[:i],
|
||||||
line: strings.TrimSpace(line[i+1:]),
|
line: strings.TrimSpace(line[i+1:]),
|
||||||
pos: cg.Pos(), // TODO(light): more precise position
|
pos: cg.Pos(), // TODO(light): More precise position.
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
d = append(d, directive{
|
d = append(d, directive{
|
||||||
kind: line,
|
kind: line,
|
||||||
pos: cg.Pos(), // TODO(light): more precise position
|
pos: cg.Pos(), // TODO(light): More precise position.
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -749,7 +749,7 @@ func (d directive) args() []string {
|
|||||||
for i, r := range d.line {
|
for i, r := range d.line {
|
||||||
switch state {
|
switch state {
|
||||||
case 0:
|
case 0:
|
||||||
// Argument boundary
|
// Argument boundary.
|
||||||
switch {
|
switch {
|
||||||
case r == '"':
|
case r == '"':
|
||||||
start = i
|
start = i
|
||||||
@@ -759,7 +759,7 @@ func (d directive) args() []string {
|
|||||||
state = 1
|
state = 1
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
// In token
|
// In token.
|
||||||
switch {
|
switch {
|
||||||
case unicode.IsSpace(r):
|
case unicode.IsSpace(r):
|
||||||
args = append(args, d.line[start:i])
|
args = append(args, d.line[start:i])
|
||||||
@@ -769,7 +769,7 @@ func (d directive) args() []string {
|
|||||||
state = 2
|
state = 2
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
// In quotes
|
// In quotes.
|
||||||
switch {
|
switch {
|
||||||
case r == '"':
|
case r == '"':
|
||||||
state = 1
|
state = 1
|
||||||
@@ -791,7 +791,7 @@ func (d directive) args() []string {
|
|||||||
|
|
||||||
// isInjectFile reports whether a given file is an injection template.
|
// isInjectFile reports whether a given file is an injection template.
|
||||||
func isInjectFile(f *ast.File) bool {
|
func isInjectFile(f *ast.File) bool {
|
||||||
// TODO(light): better determination
|
// TODO(light): Better determination.
|
||||||
for _, cg := range f.Comments {
|
for _, cg := range f.Comments {
|
||||||
text := cg.Text()
|
text := cg.Text()
|
||||||
if strings.HasPrefix(text, "+build") && strings.Contains(text, "gooseinject") {
|
if strings.HasPrefix(text, "+build") && strings.Contains(text, "gooseinject") {
|
||||||
|
|||||||
Reference in New Issue
Block a user