Skip to content

Commit

Permalink
fix: set-exit-status on recursivePath (#171)
Browse files Browse the repository at this point in the history
* This fixes set-exit-status when using `./...`

#93

* conflict resolve

* conflict resolve

---------

Co-authored-by: Micael Malta <[email protected]>
  • Loading branch information
incu6us and micaelmalta authored Feb 19, 2025
1 parent f034195 commit 6fc0151
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,22 @@ func main() {
if err != nil {
log.Fatalf("Failed to find unformatted files %s: %+v\n", originPath, err)
}
fmt.Printf("%s\n", unformattedFiles.String())
continue

if unformattedFiles != nil {
fmt.Printf("%s\n", unformattedFiles.String())
if *setExitStatus {
os.Exit(1)
}
}

return
}

err := reviser.NewSourceDir(originProjectName, originPath, *isRecursive, excludes).Fix(options...)
if err != nil {
log.Fatalf("Failed to fix directory %s: %+v\n", originPath, err)
}

continue
}

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 6fc0151

Please sign in to comment.