mirror of
https://github.com/securego/gosec.git
synced 2024-12-25 03:55:54 +00:00
Fixing config
It should have been in the context object, not the analyzer
This commit is contained in:
parent
84f0162a80
commit
da55fd1326
1 changed files with 5 additions and 4 deletions
|
@ -33,6 +33,8 @@ type Context struct {
|
|||
Comments ast.CommentMap
|
||||
Info *types.Info
|
||||
Pkg *types.Package
|
||||
Root *ast.File
|
||||
Config map[string]interface{}
|
||||
}
|
||||
|
||||
type Rule interface {
|
||||
|
@ -55,7 +57,6 @@ type Analyzer struct {
|
|||
logger *log.Logger
|
||||
Issues []Issue `json:"issues"`
|
||||
Stats Metrics `json:"metrics"`
|
||||
Config map[string]interface{}
|
||||
}
|
||||
|
||||
func NewAnalyzer(ignoreNosec bool, conf *string, logger *log.Logger) Analyzer {
|
||||
|
@ -66,14 +67,13 @@ func NewAnalyzer(ignoreNosec bool, conf *string, logger *log.Logger) Analyzer {
|
|||
ignoreNosec: ignoreNosec,
|
||||
ruleset: make(RuleSet),
|
||||
Issues: make([]Issue, 0),
|
||||
context: Context{token.NewFileSet(), nil, nil, nil},
|
||||
context: Context{token.NewFileSet(), nil, nil, nil, nil, nil},
|
||||
logger: logger,
|
||||
Config: nil,
|
||||
}
|
||||
|
||||
if conf != nil && *conf != "" { // if we have a config
|
||||
if data, err := ioutil.ReadFile(*conf); err == nil {
|
||||
if err := json.Unmarshal(data, &(a.Config)); err != nil {
|
||||
if err := json.Unmarshal(data, &(a.context.Config)); err != nil {
|
||||
logger.Fatal("Could not parse JSON config: ", *conf, ": ", err)
|
||||
}
|
||||
} else {
|
||||
|
@ -89,6 +89,7 @@ func (gas *Analyzer) process(filename string, source interface{}) error {
|
|||
root, err := parser.ParseFile(gas.context.FileSet, filename, source, mode)
|
||||
if err == nil {
|
||||
gas.context.Comments = ast.NewCommentMap(gas.context.FileSet, root, root.Comments)
|
||||
gas.context.Root = root
|
||||
|
||||
// here we get type info
|
||||
gas.context.Info = &types.Info{
|
||||
|
|
Loading…
Reference in a new issue