Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/gosqlx/cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func formatRun(cmd *cobra.Command, args []string) error {
os.Exit(1)
}

// Exit with error code if any files failed to format
if result.FailedFiles > 0 {
return fmt.Errorf("%d file(s) failed to format", result.FailedFiles)
}

return nil
}

Expand Down
11 changes: 9 additions & 2 deletions cmd/gosqlx/cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,14 @@ func lintRun(cmd *cobra.Command, args []string) error {
}
}

// Exit with error code if there were violations
// Exit with error code if there were violations or file errors
errorCount := 0
warningCount := 0
fileErrorCount := 0
for _, fileResult := range result.Files {
if fileResult.Error != nil {
fileErrorCount++
}
for _, violation := range fileResult.Violations {
switch violation.Severity {
case linter.SeverityError:
Expand All @@ -181,7 +185,10 @@ func lintRun(cmd *cobra.Command, args []string) error {
}
}

// Exit with error if there are errors, or warnings with fail-on-warn flag
// Exit with error if there are file errors, lint errors, or warnings with fail-on-warn flag
if fileErrorCount > 0 {
return fmt.Errorf("%d file(s) had errors", fileErrorCount)
}
if errorCount > 0 || (lintFailOnWarn && warningCount > 0) {
os.Exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/gosqlx/cmd/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func TestLintCmd_NonExistentFile(t *testing.T) {
args := []string{"/nonexistent/file.sql"}
err := lintRun(cmd, args)

if err != nil {
t.Errorf("Command should not return error for file read failure: %v", err)
if err == nil {
t.Errorf("Command should return error for file read failure")
}

output := outBuf.String()
Expand Down
Loading