@@ -35,6 +35,7 @@ func (w *WaitGroupWrapper) Wrap(cb func()) {
35
35
func NewReporter (templateHtml string ) * Reporter {
36
36
return & Reporter {
37
37
Metrics : make (map [string ]Metric , 0 ),
38
+ syncRW : new (sync.RWMutex ),
38
39
}
39
40
}
40
41
@@ -50,7 +51,9 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
50
51
if err != nil {
51
52
glog .Errorln (err )
52
53
}
54
+ r .syncRW .Lock ()
53
55
r .Project = PackageAbsPath (projectPath )
56
+ r .syncRW .Unlock ()
54
57
55
58
// linterFunction:unitTestF,Run all valid TEST in your golang package.And will measure
56
59
// from both coverage and time-consuming
@@ -126,9 +129,15 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
126
129
packagesTestDetail .mux .Lock ()
127
130
metricUnitTest .Summaries = packagesTestDetail .Values
128
131
packagesTestDetail .mux .Unlock ()
129
- metricUnitTest .Percentage = sumCover / float64 (countCover )
132
+ if countCover == 0 {
133
+ metricUnitTest .Percentage = 0
134
+ } else {
135
+ metricUnitTest .Percentage = sumCover / float64 (countCover )
136
+ }
130
137
138
+ r .syncRW .Lock ()
131
139
r .Metrics ["UnitTestTips" ] = metricUnitTest
140
+ r .syncRW .Unlock ()
132
141
glog .Infoln ("unit test over!" )
133
142
}
134
143
// All directory that has .go files will be add into.
@@ -181,9 +190,10 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
181
190
182
191
metricCyclo .Summaries = summaries
183
192
metricCyclo .Percentage = countPercentage (compBigThan15 + int (sumAverageCyclo / float64 (len (dirsAll ))) - 1 )
184
-
193
+ r . syncRW . Lock ()
185
194
r .Issues = r .Issues + len (summaries )
186
195
r .Metrics ["CycloTips" ] = metricCyclo
196
+ r .syncRW .Unlock ()
187
197
glog .Infoln ("comput cyclo done!" )
188
198
}
189
199
// linterfunction:simpleCodeF,all golang code hints that can be optimized
@@ -195,7 +205,6 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
195
205
Name : "Simple" ,
196
206
Description : "All golang code hints that can be optimized and give suggestions for changes." ,
197
207
Weight : 0.1 ,
198
- Summaries : make (map [string ]Summary , 0 ),
199
208
}
200
209
summaries := make (map [string ]Summary , 0 )
201
210
@@ -226,9 +235,10 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
226
235
}
227
236
metricSimple .Summaries = summaries
228
237
metricSimple .Percentage = countPercentage (len (summaries ))
229
-
238
+ r . syncRW . Lock ()
230
239
r .Issues = r .Issues + len (summaries )
231
240
r .Metrics ["SimpleTips" ] = metricSimple
241
+ r .syncRW .Unlock ()
232
242
glog .Infoln ("simple code done!" )
233
243
}
234
244
@@ -270,9 +280,10 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
270
280
}
271
281
metricCopyCode .Summaries = summaries
272
282
metricCopyCode .Percentage = countPercentage (len (summaries ))
273
-
283
+ r . syncRW . Lock ()
274
284
r .Issues = r .Issues + len (summaries )
275
285
r .Metrics ["CopyCodeTips" ] = metricCopyCode
286
+ r .syncRW .Unlock ()
276
287
glog .Infoln ("checked copy code!" )
277
288
}
278
289
// linterFunction:deadCodeF,all useless code, or never obsolete obsolete code.
@@ -283,7 +294,6 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
283
294
Name : "DeadCode" ,
284
295
Description : "All useless code, or never obsolete obsolete code." ,
285
296
Weight : 0.1 ,
286
- Summaries : make (map [string ]Summary , 0 ),
287
297
}
288
298
summaries := make (map [string ]Summary , 0 )
289
299
@@ -313,9 +323,10 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
313
323
}
314
324
metricDeadCode .Summaries = summaries
315
325
metricDeadCode .Percentage = countPercentage (len (summaries ))
316
-
326
+ r . syncRW . Lock ()
317
327
r .Issues = r .Issues + len (summaries )
318
328
r .Metrics ["DeadCodeTips" ] = metricDeadCode
329
+ r .syncRW .Unlock ()
319
330
glog .Infoln ("check dead code done." )
320
331
}
321
332
// linterFunction:spellCheckF,check the project variables, functions,
@@ -327,7 +338,6 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
327
338
Name : "SpellCheck" ,
328
339
Description : "Check the project variables, functions, etc. naming spelling is wrong." ,
329
340
Weight : 0.1 ,
330
- Summaries : make (map [string ]Summary , 0 ),
331
341
}
332
342
summaries := make (map [string ]Summary , 0 )
333
343
@@ -358,9 +368,10 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
358
368
}
359
369
metricSpellTips .Summaries = summaries
360
370
metricSpellTips .Percentage = countPercentage (len (summaries ))
361
-
371
+ r . syncRW . Lock ()
362
372
r .Issues = r .Issues + len (summaries )
363
373
r .Metrics ["SpellCheckTips" ] = metricSpellTips
374
+ r .syncRW .Unlock ()
364
375
glog .Infoln ("checked spell error" )
365
376
}
366
377
// linterFunction:dependGraphF,The project contains all the package lists.
@@ -379,7 +390,9 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
379
390
}
380
391
metricImportPackageTips .Summaries = summaries
381
392
metricImportPackageTips .Percentage = countPercentage (len (summaries ))
393
+ r .syncRW .Lock ()
382
394
r .Metrics ["ImportPackagesTips" ] = metricImportPackageTips
395
+ r .syncRW .Unlock ()
383
396
glog .Infoln ("import packages done." )
384
397
}
385
398
@@ -391,7 +404,6 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
391
404
Name : "DependGraph" ,
392
405
Description : "The dependency graph for all packages in the project helps you optimize the project architecture." ,
393
406
Weight : 0 ,
394
- Summaries : make (map [string ]Summary , 0 ),
395
407
}
396
408
summaries := make (map [string ]Summary , 0 )
397
409
@@ -402,8 +414,10 @@ func (r *Reporter) Engine(projectPath string, exceptPackages string) {
402
414
}
403
415
metricDependGraphTips .Summaries = summaries
404
416
metricDependGraphTips .Percentage = countPercentage (len (summaries ))
417
+ r .syncRW .Lock ()
405
418
r .Issues = r .Issues + len (summaries )
406
419
r .Metrics ["DependGraphTips" ] = metricDependGraphTips
420
+ r .syncRW .Unlock ()
407
421
glog .Infoln ("created depend graph" )
408
422
}
409
423
r .TimeStamp = time .Now ().Format ("2006-01-02 15:04:05" )
0 commit comments