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

Make ptimports work on Windows #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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