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