Skip to content

Commit e680875

Browse files
authored
Replace the deprecated load mode with more specific flags are recommended in the packages docs (#400)
Signed-off-by: Cosmin Cojocar <[email protected]>
1 parent ad375d3 commit e680875

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

analyzer.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ import (
3333
"golang.org/x/tools/go/packages"
3434
)
3535

36+
// LoadMode controls the amount of details to return when loading the packages
37+
const LoadMode = packages.NeedName |
38+
packages.NeedFiles |
39+
packages.NeedCompiledGoFiles |
40+
packages.NeedImports |
41+
packages.NeedTypes |
42+
packages.NeedTypesSizes |
43+
packages.NeedTypesInfo |
44+
packages.NeedSyntax
45+
3646
// The Context is populated with data parsed from the source code as it is scanned.
3747
// It is passed through to all rule functions as they are called. Rules may use
3848
// this data in conjunction withe the encountered AST node.
@@ -140,7 +150,7 @@ func (gosec *Analyzer) pkgConfig(buildTags []string) *packages.Config {
140150
flags = append(flags, tagsFlag)
141151
}
142152
return &packages.Config{
143-
Mode: packages.LoadSyntax,
153+
Mode: LoadMode,
144154
BuildFlags: flags,
145155
Tests: gosec.tests,
146156
}

testutils/pkg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (p *TestPackage) Build() error {
8080
}
8181

8282
conf := &packages.Config{
83-
Mode: packages.LoadSyntax,
83+
Mode: gosec.LoadMode,
8484
Tests: false,
8585
}
8686
pkgs, err := packages.Load(conf, packageFiles...)

0 commit comments

Comments
 (0)