Skip to content
This repository has been archived by the owner on Nov 25, 2019. It is now read-only.

Commit

Permalink
Make ptimports work on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwyatt committed Dec 18, 2017
1 parent ab6f883 commit aac17b2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.iml
*.ipr
*.iws
.vscode/
.idea/
build/
dist/
1 change: 1 addition & 0 deletions ptimports/ptimports.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func gofmtMain() {
}

for _, path := range paths {
path = filepath.FromSlash(path)
switch dir, err := os.Stat(path); {
case err != nil:
report(err)
Expand Down
5 changes: 3 additions & 2 deletions ptimports/ptimports/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package ptimports

import (
"fmt"
"path"
"path/filepath"
"strings"

Expand All @@ -31,12 +32,12 @@ func repoForFile(filename string) (string, error) {
if goPathSrcRel, err := pkgpath.NewAbsPkgPath(abs).GoPathSrcRel(); err == nil {
relative = goPathSrcRel
}
segments := strings.Split(relative, "/")
segments := strings.Split(relative, string(filepath.Separator))
if len(segments) < 3 {
return "", fmt.Errorf("expected repo to be located under at least 3 subdirectories but received relative filepath: %v", relative)
}
// append trailing / to prevent matches on repos with superstring names
return filepath.Join(segments[:3]...) + "/", nil
return path.Join(segments[:3]...) + "/", nil
}

type importGrouper interface {
Expand Down

0 comments on commit aac17b2

Please sign in to comment.