From 6a29e6e2cc3d067ee6c7795cce288cd8672f9d25 Mon Sep 17 00:00:00 2001 From: tlipoca9 <160737620+tlipoca9@users.noreply.github.com> Date: Thu, 23 May 2024 16:14:22 +0800 Subject: [PATCH] fix: use filepath.Dir instead of path.Dir (#152) --- main.go | 3 +++ reviser/file.go | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index b376175..659104e 100644 --- a/main.go +++ b/main.go @@ -275,6 +275,9 @@ func main() { log.Fatalf("Failed to find unformatted files %s: %+v\n", originPath, err) } fmt.Printf("%s\n", unformattedFiles.String()) + if *setExitStatus && unformattedFiles != nil { + os.Exit(1) + } return } err := reviser.NewSourceDir(originProjectName, originPath, *isRecursive, excludes).Fix(options...) diff --git a/reviser/file.go b/reviser/file.go index 0a993cc..d11ae69 100644 --- a/reviser/file.go +++ b/reviser/file.go @@ -11,6 +11,7 @@ import ( "io" "os" "path" + "path/filepath" "regexp" "sort" "strings" @@ -438,7 +439,7 @@ func (f *SourceFile) parseImports(file *ast.File) (map[string]*commentsMetadata, if shouldRemoveUnusedImports || shouldUseAliasForVersionSuffix { var err error - packageImports, err = astutil.LoadPackageDependencies(path.Dir(f.filePath), astutil.ParseBuildTag(file)) + packageImports, err = astutil.LoadPackageDependencies(filepath.Dir(f.filePath), astutil.ParseBuildTag(file)) if err != nil { return nil, err }