Skip to content

Commit 2db694a

Browse files
committed
exit with the code 5 if no go files to analyze
1 parent a2b9012 commit 2db694a

File tree

11 files changed

+628
-3
lines changed

11 files changed

+628
-3
lines changed

Gopkg.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/commands/run.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/golangci/golangci-lint/pkg/logutils"
1919
"github.com/golangci/golangci-lint/pkg/printers"
2020
"github.com/golangci/golangci-lint/pkg/result"
21+
"github.com/pkg/errors"
2122
"github.com/spf13/cobra"
2223
"github.com/spf13/pflag"
2324
)
@@ -249,7 +250,7 @@ func (e *Executor) runAnalysis(ctx context.Context, args []string) (<-chan resul
249250

250251
lintCtx, err := lint.LoadContext(linters, e.cfg, e.log.Child("load"))
251252
if err != nil {
252-
return nil, err
253+
return nil, errors.Wrap(err, "context loading failed")
253254
}
254255

255256
runner, err := lint.NewRunner(lintCtx.ASTCache, e.cfg, e.log.Child("runner"))
@@ -284,7 +285,7 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
284285

285286
issues, err := e.runAnalysis(ctx, args)
286287
if err != nil {
287-
return err
288+
return err // XXX: don't loose type
288289
}
289290

290291
p, err := e.createPrinter()
@@ -345,7 +346,11 @@ func (e *Executor) executeRun(cmd *cobra.Command, args []string) {
345346
if err := e.runAndPrint(ctx, args); err != nil {
346347
e.log.Errorf("Running error: %s", err)
347348
if e.exitCode == exitcodes.Success {
348-
e.exitCode = exitcodes.Failure
349+
if exitErr, ok := errors.Cause(err).(*exitcodes.ExitError); ok {
350+
e.exitCode = exitErr.Code
351+
} else {
352+
e.exitCode = exitcodes.Failure
353+
}
349354
}
350355
}
351356

pkg/exitcodes/exitcodes.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,21 @@ const (
66
WarningInTest = 2
77
Failure = 3
88
Timeout = 4
9+
NoGoFiles = 5
10+
)
11+
12+
type ExitError struct {
13+
Message string
14+
Code int
15+
}
16+
17+
func (e ExitError) Error() string {
18+
return e.Message
19+
}
20+
21+
var (
22+
ErrNoGoFiles = &ExitError{
23+
Message: "no go files to analyze",
24+
Code: NoGoFiles,
25+
}
926
)

pkg/lint/load.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111
"time"
1212

13+
"github.com/golangci/golangci-lint/pkg/exitcodes"
1314
"github.com/golangci/golangci-lint/pkg/fsutils"
1415
"github.com/golangci/golangci-lint/pkg/goutils"
1516
"github.com/golangci/golangci-lint/pkg/logutils"
@@ -303,6 +304,10 @@ func LoadContext(linters []linter.Config, cfg *config.Config, log logutils.Log)
303304
return nil, err
304305
}
305306

307+
if len(pkgProg.Packages()) == 0 {
308+
return nil, exitcodes.ErrNoGoFiles
309+
}
310+
306311
prog, loaderConfig, err := loadWholeAppIfNeeded(linters, cfg, pkgProg, log)
307312
if err != nil {
308313
return nil, err

vendor/github.com/pkg/errors/.gitignore

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/pkg/errors/.travis.yml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/pkg/errors/LICENSE

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/pkg/errors/README.md

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/pkg/errors/appveyor.yml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)