@@ -28,6 +28,7 @@ import (
28
28
"strings"
29
29
30
30
gas "github.com/GoASTScanner/gas/core"
31
+ "github.com/GoASTScanner/gas/output"
31
32
"golang.org/x/tools/go/loader"
32
33
)
33
34
@@ -151,7 +152,7 @@ func usage() {
151
152
}
152
153
153
154
// TODO(gm) This needs to be refactored (potentially included in Analyzer)
154
- func analyzePackage (packageDirectory string , config map [string ]interface {}, logger * log.Logger ) ([]* gas.Issue , error ) {
155
+ func analyzePackage (packageDirectory string , metrics * gas. Metrics , config map [string ]interface {}, logger * log.Logger ) ([]* gas.Issue , error ) {
155
156
156
157
basePackage , err := build .Default .ImportDir (packageDirectory , build .ImportComment )
157
158
if err != nil {
@@ -178,7 +179,12 @@ func analyzePackage(packageDirectory string, config map[string]interface{}, logg
178
179
analyzer .ProcessPackage (builtPackage , pkg , file )
179
180
}
180
181
issues = append (issues , analyzer .Issues ... )
182
+ metrics .NumFiles += analyzer .Stats .NumFiles
183
+ metrics .NumFound += analyzer .Stats .NumFound
184
+ metrics .NumLines += analyzer .Stats .NumLines
185
+ metrics .NumNosec += analyzer .Stats .NumNosec
181
186
}
187
+
182
188
return issues , nil
183
189
}
184
190
@@ -223,6 +229,8 @@ func main() {
223
229
224
230
config := buildConfig (incRules , excRules )
225
231
issues := make ([]* gas.Issue , 0 )
232
+ metrics := & gas.Metrics {}
233
+
226
234
for _ , arg := range flag .Args () {
227
235
if arg == "./..." {
228
236
baseDirectory , err := os .Getwd ()
@@ -238,7 +246,7 @@ func main() {
238
246
log .Printf ("Skipping %s\n " , path )
239
247
return filepath .SkipDir
240
248
}
241
- newIssues , err := analyzePackage (path , config , logger )
249
+ newIssues , err := analyzePackage (path , metrics , config , logger )
242
250
if err != nil {
243
251
log .Println (err )
244
252
} else {
@@ -248,7 +256,7 @@ func main() {
248
256
return nil
249
257
})
250
258
} else {
251
- newIssues , err := analyzePackage (arg , config , logger )
259
+ newIssues , err := analyzePackage (arg , metrics , config , logger )
252
260
if err != nil {
253
261
log .Fatal (err )
254
262
}
@@ -262,25 +270,17 @@ func main() {
262
270
os .Exit (0 )
263
271
}
264
272
265
- // TODO(gm) - Report output is borken...
266
- /*
267
- for _, issue := range issues {
268
- log.Println(issue)
273
+ // Create output report
274
+ if * flagOutput != "" {
275
+ outfile , err := os .Create (* flagOutput )
276
+ if err != nil {
277
+ logger .Fatalf ("Couldn't open: %s for writing. Reason - %s" , * flagOutput , err )
269
278
}
270
-
271
- // Create output report
272
- if *flagOutput != "" {
273
- outfile, err := os.Create(*flagOutput)
274
- if err != nil {
275
- logger.Fatalf("Couldn't open: %s for writing. Reason - %s", *flagOutput, err)
276
- }
277
- defer outfile.Close()
278
- output.CreateReport(outfile, *flagFormat, &analyzer)
279
- } else {
280
- output.CreateReport(os.Stdout, *flagFormat, &analyzer)
281
- }
282
-
283
- */
279
+ defer outfile .Close ()
280
+ output .CreateReport (outfile , * flagFormat , issues , metrics )
281
+ } else {
282
+ output .CreateReport (os .Stdout , * flagFormat , issues , metrics )
283
+ }
284
284
285
285
// Do we have an issue? If so exit 1
286
286
if issuesFound {
0 commit comments