Replace the deprecated load mode with more specific flags are recommended in the packages docs (#400)

Signed-off-by: Cosmin Cojocar <cosmin.cojocar@gmx.ch>
This commit is contained in:
Cosmin Cojocar 2019-10-02 14:05:14 +02:00 committed by GitHub
parent ad375d3b8f
commit e680875ea1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -33,6 +33,16 @@ import (
"golang.org/x/tools/go/packages" "golang.org/x/tools/go/packages"
) )
// LoadMode controls the amount of details to return when loading the packages
const LoadMode = packages.NeedName |
packages.NeedFiles |
packages.NeedCompiledGoFiles |
packages.NeedImports |
packages.NeedTypes |
packages.NeedTypesSizes |
packages.NeedTypesInfo |
packages.NeedSyntax
// The Context is populated with data parsed from the source code as it is scanned. // The Context is populated with data parsed from the source code as it is scanned.
// It is passed through to all rule functions as they are called. Rules may use // It is passed through to all rule functions as they are called. Rules may use
// this data in conjunction withe the encountered AST node. // this data in conjunction withe the encountered AST node.
@ -140,7 +150,7 @@ func (gosec *Analyzer) pkgConfig(buildTags []string) *packages.Config {
flags = append(flags, tagsFlag) flags = append(flags, tagsFlag)
} }
return &packages.Config{ return &packages.Config{
Mode: packages.LoadSyntax, Mode: LoadMode,
BuildFlags: flags, BuildFlags: flags,
Tests: gosec.tests, Tests: gosec.tests,
} }

View file

@ -80,7 +80,7 @@ func (p *TestPackage) Build() error {
} }
conf := &packages.Config{ conf := &packages.Config{
Mode: packages.LoadSyntax, Mode: gosec.LoadMode,
Tests: false, Tests: false,
} }
pkgs, err := packages.Load(conf, packageFiles...) pkgs, err := packages.Load(conf, packageFiles...)