Skip to content

Commit

Permalink
This fixes set-exit-status when using ./...
Browse files Browse the repository at this point in the history
  • Loading branch information
micaelmalta authored and n-oden committed Jul 23, 2024
1 parent b3a2701 commit 09b1838
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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...)
Expand Down
8 changes: 8 additions & 0 deletions reviser/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 09b1838

Please sign in to comment.