@@ -28,6 +28,7 @@ import (
2828 "strings"
2929
3030 gas "github.com/GoASTScanner/gas/core"
31+ "github.com/GoASTScanner/gas/output"
3132 "golang.org/x/tools/go/loader"
3233)
3334
@@ -151,7 +152,7 @@ func usage() {
151152}
152153
153154// 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 ) {
155156
156157 basePackage , err := build .Default .ImportDir (packageDirectory , build .ImportComment )
157158 if err != nil {
@@ -178,7 +179,12 @@ func analyzePackage(packageDirectory string, config map[string]interface{}, logg
178179 analyzer .ProcessPackage (builtPackage , pkg , file )
179180 }
180181 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
181186 }
187+
182188 return issues , nil
183189}
184190
@@ -223,6 +229,8 @@ func main() {
223229
224230 config := buildConfig (incRules , excRules )
225231 issues := make ([]* gas.Issue , 0 )
232+ metrics := & gas.Metrics {}
233+
226234 for _ , arg := range flag .Args () {
227235 if arg == "./..." {
228236 baseDirectory , err := os .Getwd ()
@@ -238,7 +246,7 @@ func main() {
238246 log .Printf ("Skipping %s\n " , path )
239247 return filepath .SkipDir
240248 }
241- newIssues , err := analyzePackage (path , config , logger )
249+ newIssues , err := analyzePackage (path , metrics , config , logger )
242250 if err != nil {
243251 log .Println (err )
244252 } else {
@@ -248,7 +256,7 @@ func main() {
248256 return nil
249257 })
250258 } else {
251- newIssues , err := analyzePackage (arg , config , logger )
259+ newIssues , err := analyzePackage (arg , metrics , config , logger )
252260 if err != nil {
253261 log .Fatal (err )
254262 }
@@ -262,25 +270,17 @@ func main() {
262270 os .Exit (0 )
263271 }
264272
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 )
269278 }
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+ }
284284
285285 // Do we have an issue? If so exit 1
286286 if issuesFound {
0 commit comments