From e680875ea14d949554f2b6826a651157eebcef81 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Wed, 2 Oct 2019 14:05:14 +0200 Subject: [PATCH] Replace the deprecated load mode with more specific flags are recommended in the packages docs (#400) Signed-off-by: Cosmin Cojocar --- analyzer.go | 12 +++++++++++- testutils/pkg.go | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/analyzer.go b/analyzer.go index 226380a..20f08d5 100644 --- a/analyzer.go +++ b/analyzer.go @@ -33,6 +33,16 @@ import ( "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. // It is passed through to all rule functions as they are called. Rules may use // 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) } return &packages.Config{ - Mode: packages.LoadSyntax, + Mode: LoadMode, BuildFlags: flags, Tests: gosec.tests, } diff --git a/testutils/pkg.go b/testutils/pkg.go index fcc7c4f..65bca97 100644 --- a/testutils/pkg.go +++ b/testutils/pkg.go @@ -80,7 +80,7 @@ func (p *TestPackage) Build() error { } conf := &packages.Config{ - Mode: packages.LoadSyntax, + Mode: gosec.LoadMode, Tests: false, } pkgs, err := packages.Load(conf, packageFiles...)