Merge pull request #33 from HewlettPackard/config_fix

Fixing config
This commit is contained in:
Tim Kelsey 2016-08-05 11:05:16 +01:00 committed by GitHub
commit 7e1d7ee0fe

View file

@ -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{