@@ -79,10 +79,10 @@ type Metrics struct {
79
79
type Analyzer struct {
80
80
ignoreNosec bool
81
81
ruleset RuleSet
82
- context Context
82
+ context * Context
83
83
logger * log.Logger
84
- Issues []Issue `json:"issues"`
85
- Stats Metrics `json:"metrics"`
84
+ Issues []* Issue `json:"issues"`
85
+ Stats * Metrics `json:"metrics"`
86
86
}
87
87
88
88
// NewAnalyzer builds a new anaylzer.
@@ -93,17 +93,10 @@ func NewAnalyzer(conf map[string]interface{}, logger *log.Logger) Analyzer {
93
93
a := Analyzer {
94
94
ignoreNosec : conf ["ignoreNosec" ].(bool ),
95
95
ruleset : make (RuleSet ),
96
- Issues : make ([]Issue , 0 ),
97
- context : Context {
98
- token .NewFileSet (),
99
- nil ,
100
- nil ,
101
- nil ,
102
- nil ,
103
- nil ,
104
- nil ,
105
- },
106
- logger : logger ,
96
+ context : & Context {nil , nil , nil , nil , nil , nil , nil },
97
+ logger : logger ,
98
+ Issues : make ([]* Issue , 0 , 16 ),
99
+ Stats : & Metrics {0 , 0 , 0 , 0 },
107
100
}
108
101
109
102
// TODO(tkelsey): use the inc/exc lists
@@ -113,6 +106,7 @@ func NewAnalyzer(conf map[string]interface{}, logger *log.Logger) Analyzer {
113
106
114
107
func (gas * Analyzer ) process (filename string , source interface {}) error {
115
108
mode := parser .ParseComments
109
+ gas .context .FileSet = token .NewFileSet ()
116
110
root , err := parser .ParseFile (gas .context .FileSet , filename , source , mode )
117
111
if err == nil {
118
112
gas .context .Comments = ast .NewCommentMap (gas .context .FileSet , root , root .Comments )
@@ -221,14 +215,14 @@ func (gas *Analyzer) Visit(n ast.Node) ast.Visitor {
221
215
222
216
if val , ok := gas .ruleset [reflect .TypeOf (n )]; ok {
223
217
for _ , rule := range val {
224
- ret , err := rule .Match (n , & gas .context )
218
+ ret , err := rule .Match (n , gas .context )
225
219
if err != nil {
226
- file , line := GetLocation (n , & gas .context )
220
+ file , line := GetLocation (n , gas .context )
227
221
file = path .Base (file )
228
222
gas .logger .Printf ("Rule error: %v => %s (%s:%d)\n " , reflect .TypeOf (rule ), err , file , line )
229
223
}
230
224
if ret != nil {
231
- gas .Issues = append (gas .Issues , * ret )
225
+ gas .Issues = append (gas .Issues , ret )
232
226
gas .Stats .NumFound ++
233
227
}
234
228
}
0 commit comments