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 9db37ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Check warning on line 280 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L278-L280

Added lines #L278 - L280 were not covered by tests
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
}

Check warning on line 126 in reviser/dir.go

View check run for this annotation

Codecov / codecov/patch

reviser/dir.go#L125-L126

Added lines #L125 - L126 were not covered by tests

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 ""
}

Check warning on line 185 in reviser/dir.go

View check run for this annotation

Codecov / codecov/patch

reviser/dir.go#L184-L185

Added lines #L184 - L185 were not covered by tests

var builder strings.Builder
for i, file := range c.list {
builder.WriteString(file)
Expand Down

0 comments on commit 9db37ec

Please sign in to comment.