From 64a351a9cc6dd2d3b59d8c84b554dd2e35a946f5 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 1 Jun 2017 18:08:39 +0200 Subject: [PATCH 1/2] Prevent panic in case there are no files to check. --- lint.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lint.go b/lint.go index 5b85d8e8..9de6e258 100644 --- a/lint.go +++ b/lint.go @@ -279,6 +279,9 @@ func (p *pkg) typeCheck() error { anyFile = f astFiles = append(astFiles, f.f) } + if anyFile == nil { + return nil + } pkg, err := config.Check(anyFile.f.Name.Name, p.fset, astFiles, info) // Remember the typechecking info, even if config.Check failed, // since we will get partial information. From 37dcb65c2314b68bb8acc4522f6b159c61634b6e Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 1 Jun 2017 18:46:09 +0200 Subject: [PATCH 2/2] Abort early --- lint.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lint.go b/lint.go index 9de6e258..fb47da00 100644 --- a/lint.go +++ b/lint.go @@ -82,9 +82,6 @@ func (l *Linter) Lint(filename string, src []byte) ([]Problem, error) { // LintFiles lints a set of files of a single package. // The argument is a map of filename to source. func (l *Linter) LintFiles(files map[string][]byte) ([]Problem, error) { - if len(files) == 0 { - return nil, nil - } pkg := &pkg{ fset: token.NewFileSet(), files: make(map[string]*file), @@ -111,6 +108,9 @@ func (l *Linter) LintFiles(files map[string][]byte) ([]Problem, error) { filename: filename, } } + if len(pkg.files) == 0 { + return nil, nil + } return pkg.lint(), nil } @@ -279,9 +279,6 @@ func (p *pkg) typeCheck() error { anyFile = f astFiles = append(astFiles, f.f) } - if anyFile == nil { - return nil - } pkg, err := config.Check(anyFile.f.Name.Name, p.fset, astFiles, info) // Remember the typechecking info, even if config.Check failed, // since we will get partial information.