Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitarPetrov committed Sep 6, 2020
1 parent 1b71478 commit b5bb922
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ func (ac *ApplyCmd) Run() error {
if err != nil {
return err
}
return ac.importsGroomer.RemoveUnusedImportFromDirectory(path, map[string]string{"fmt":"", "runtime":"rt", "rand":""})
return ac.importsGroomer.RemoveUnusedImportFromDirectory(path, map[string]string{"fmt":"", "runtime":"rt", "rand":""}) // TODO: flag for import aliases
})
}
2 changes: 1 addition & 1 deletion cmd/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ func (rc *RevertCmd) Run() error {
if err != nil {
return err
}
return rc.importsGroomer.RemoveUnusedImportFromDirectory(path, map[string]string{"fmt":"", "runtime":"rt", "rand":""})
return rc.importsGroomer.RemoveUnusedImportFromDirectory(path, map[string]string{"fmt":"", "runtime":"rt", "crypto/rand":""}) // TODO: flag for import aliases
})
}
4 changes: 2 additions & 2 deletions tracing/deinstrument_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestDeinstrumentFile(t *testing.T) {
}

var buff2 bytes.Buffer
if err := NewImportsGroomer().RemoveUnusedImportFromFile(fset, file, &buff2, map[string]string{"fmt":"", "runtime":"rt", "rand":""}); err != nil {
if err := NewImportsGroomer().RemoveUnusedImportFromFile(fset, file, &buff2, map[string]string{"fmt":"", "runtime":"rt", "crypto/rand":""}); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -87,7 +87,7 @@ func TestDeinstrumentDirectory(t *testing.T) {
t.Fatal(err)
}

if err := NewImportsGroomer().RemoveUnusedImportFromDirectory("test", map[string]string{"fmt":"", "runtime":"rt", "rand":""}); err != nil {
if err := NewImportsGroomer().RemoveUnusedImportFromDirectory("test", map[string]string{"fmt":"", "runtime":"rt", "crypto/rand":""}); err != nil {
t.Fatal(err)
}

Expand Down
2 changes: 1 addition & 1 deletion tracing/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (ci *codeInstrumenter) InstrumentPackage(fset *token.FileSet, pkg *ast.Pack
func (ci *codeInstrumenter) InstrumentFile(fset *token.FileSet, file *ast.File, out io.Writer) error {
astutil.AddImport(fset, file, "fmt")
astutil.AddNamedImport(fset, file, "rt", "runtime")
astutil.AddImport(fset, file, "rand")
astutil.AddImport(fset, file, "crypto/rand")

// Needed because ast does not support floating comments and deletes them.
// In order to preserve all comments we just pre-parse it to dst which treats them as first class citizens.
Expand Down
12 changes: 6 additions & 6 deletions tracing/instrument_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func main() {
const resultCodeWithoutImports = `package a
import (
"crypto/rand"
"fmt"
"rand"
rt "runtime"
)
Expand Down Expand Up @@ -79,8 +79,8 @@ func main() {
const editedResultCodeWithoutImports = `package a
import (
"crypto/rand"
"fmt"
"rand"
rt "runtime"
)
Expand Down Expand Up @@ -149,8 +149,8 @@ func main() {
const resultCodeWithFmtImport = `package a
import (
"crypto/rand"
"fmt"
"rand"
rt "runtime"
)
Expand Down Expand Up @@ -222,8 +222,8 @@ func main() {
const resultCodeWithMultipleImports = `package a
import (
"crypto/rand"
"fmt"
"rand"
rt "runtime"
"strconv"
)
Expand Down Expand Up @@ -295,8 +295,8 @@ func main() {
const resultCodeWithImportsWithoutFmt = `package a
import (
"crypto/rand"
"fmt"
"rand"
rt "runtime"
"strconv"
)
Expand Down Expand Up @@ -356,8 +356,8 @@ type test struct {
const resultCodeWithoutFunction = `package a
import (
"crypto/rand"
"fmt"
"rand"
rt "runtime"
)
Expand Down
36 changes: 18 additions & 18 deletions tracing/tracingfakes/fake_imports_groomer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tracing/unused_imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestRemoveUnusedImportsFromFile(t *testing.T) {
t.Fatal(err)
}
var buff bytes.Buffer
if err := NewImportsGroomer().RemoveUnusedImportFromFile(fset, file, &buff, map[string]string{"fmt":"", "runtime":"rt", "rand":""}); err != nil {
if err := NewImportsGroomer().RemoveUnusedImportFromFile(fset, file, &buff, map[string]string{"fmt":"", "runtime":"rt", "crypto/rand":""}); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -63,7 +63,7 @@ func TestRemoveUnusedImportsFromDirectory(t *testing.T) {
i++
}

if err := NewImportsGroomer().RemoveUnusedImportFromDirectory("test", map[string]string{"fmt":"", "runtime":"rt", "rand":""}); err != nil {
if err := NewImportsGroomer().RemoveUnusedImportFromDirectory("test", map[string]string{"fmt":"", "runtime":"rt", "crypto/rand":""}); err != nil {
t.Fatal(err)
}

Expand Down

0 comments on commit b5bb922

Please sign in to comment.