-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
missing import black #44
Comments
Unfortunately with the simple resolvers in the The You have two options:
There's a Go2 proposal that would fix all this complexity here. Feel free to give it a thunbs-up! package main
import (
"github.com/dave/dst/decorator"
"github.com/dave/dst/decorator/resolver/goast"
"github.com/dave/dst/decorator/resolver/guess"
"go/token"
)
func main() {
code := `package main
import (
"github.com/opentracing/opentracing-go"
)
var a opentracing.Tracer
`
packageNames := map[string]string{"github.com/opentracing/opentracing-go" : "opentracing"}
packageNameResolver := guess.WithMap(packageNames)
decoratorResolver := goast.WithResolver(packageNameResolver)
dec := decorator.NewDecoratorWithImports(token.NewFileSet(), "main", decoratorResolver)
f, err := dec.Parse(code)
if err != nil {
panic(err)
}
res := decorator.NewRestorerWithImports("main", packageNameResolver)
if err := res.Print(f); err != nil {
panic(err)
}
} Output: package main
import (
"github.com/opentracing/opentracing-go"
)
var a opentracing.Tracer |
One more possible solution... I assumed you need package main
import (
"github.com/dave/dst/decorator"
"go/token"
)
func main() {
code := `package main
import (
"github.com/opentracing/opentracing-go"
)
var a opentracing.Tracer
`
dec := decorator.NewDecorator(token.NewFileSet())
f, err := dec.Parse(code)
if err != nil {
panic(err)
}
res := decorator.NewRestorer()
if err := res.Print(f); err != nil {
panic(err)
}
} Output: package main
import (
"github.com/opentracing/opentracing-go"
)
var a opentracing.Tracer |
thx 😁 |
get:
expect:
The text was updated successfully, but these errors were encountered: