diff --git a/main.go b/main.go index 3be2e76..53afb19 100644 --- a/main.go +++ b/main.go @@ -285,7 +285,7 @@ func main() { return } - originPath := flag.Arg(0) + originPaths := flag.Args() if filePath != "" { deprecatedMessagesCh <- fmt.Sprintf("-%s is deprecated. Put file name(s) as last argument to the command(Example: goimports-reviser -rm-unused -set-alias -format goimports-reviser/main.go)", filePathArg) @@ -365,7 +365,12 @@ func main() { if err != nil { log.Fatalf("Failed to find unformatted files %s: %+v\n", originPath, err) } - fmt.Printf("%s\n", unformattedFiles.String()) + if unformattedFiles != nil { + fmt.Printf("%s\n", unformattedFiles.String()) + if *setExitStatus { + hasChange = true + } + } continue } err := reviser.NewSourceDir(originProjectName, originPath, *isRecursive, excludes).Fix(options...) diff --git a/reviser/dir.go b/reviser/dir.go index 69275b2..0fc2776 100644 --- a/reviser/dir.go +++ b/reviser/dir.go @@ -121,6 +121,10 @@ func (d *SourceDir) Find(options ...SourceFileOption) (*UnformattedCollection, e return nil, fmt.Errorf("failed to walk dif: %w", err) } + if len(badFormattedCollection) == 0 { + return nil, nil + } + return newUnformattedCollection(badFormattedCollection), nil } @@ -176,6 +180,10 @@ func (c *UnformattedCollection) List() []string { } func (c *UnformattedCollection) String() string { + if c == nil { + return "" + } + var builder strings.Builder for i, file := range c.list { builder.WriteString(file)