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 committed May 27, 2024
1 parent 5f29621 commit 99288e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,14 @@ 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 {
os.Exit(1)
}
}

return
}
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 99288e4

Please sign in to comment.