@@ -76,28 +76,28 @@ var openMetricsSummaryRecordFormat = "scc_%s{language=\"%s\"} %d\n"
76
76
var openMetricsFileRecordFormat = "scc_%s{language=\" %s\" ,file=\" %s\" } %d\n "
77
77
78
78
func sortSummaryFiles (summary * LanguageSummary ) {
79
- switch {
80
- case SortBy == "name" || SortBy == "names" || SortBy == "language" || SortBy == "languages" || SortBy == "lang" :
79
+ switch SortBy {
80
+ case "name" , "names" , "language" , "languages" , "lang" , "langs " :
81
81
slices .SortFunc (summary .Files , func (a , b * FileJob ) int {
82
82
return strings .Compare (a .Location , b .Location )
83
83
})
84
- case SortBy == "line" || SortBy == "lines" :
84
+ case "line" , "lines" :
85
85
slices .SortFunc (summary .Files , func (a , b * FileJob ) int {
86
86
return cmp .Compare (b .Lines , a .Lines )
87
87
})
88
- case SortBy == "blank" || SortBy == "blanks" :
88
+ case "blank" , "blanks" :
89
89
slices .SortFunc (summary .Files , func (a , b * FileJob ) int {
90
90
return cmp .Compare (b .Blank , a .Blank )
91
91
})
92
- case SortBy == "code" || SortBy == "codes" :
92
+ case "code" , "codes" :
93
93
slices .SortFunc (summary .Files , func (a , b * FileJob ) int {
94
94
return cmp .Compare (b .Code , a .Code )
95
95
})
96
- case SortBy == "comment" || SortBy == "comments" :
96
+ case "comment" , "comments" :
97
97
slices .SortFunc (summary .Files , func (a , b * FileJob ) int {
98
98
return cmp .Compare (b .Comment , a .Comment )
99
99
})
100
- case SortBy == "complexity" || SortBy == "complexitys" || SortBy == "comp" :
100
+ case "complexity" , "complexitys" , "comp" :
101
101
slices .SortFunc (summary .Files , func (a , b * FileJob ) int {
102
102
return cmp .Compare (b .Complexity , a .Complexity )
103
103
})
@@ -341,46 +341,46 @@ func toCSVSummary(input chan *FileJob) string {
341
341
func getRecordsSortFunc () func (a , b []string ) int {
342
342
// Cater for the common case of adding plural even for those options that don't make sense
343
343
// as it's quite common for those who English is not a first language to make a simple mistake
344
- switch {
345
- case SortBy == "name" || SortBy == "names" :
344
+ switch SortBy {
345
+ case "name" , "names" :
346
346
return func (a , b []string ) int {
347
347
return strings .Compare (a [2 ], b [2 ])
348
348
}
349
- case SortBy == "language" || SortBy == "languages " :
349
+ case "language" , "languages" , "lang" , "langs " :
350
350
return func (a , b []string ) int {
351
351
return strings .Compare (a [0 ], b [0 ])
352
352
}
353
- case SortBy == "line" || SortBy == "lines" :
353
+ case "line" , "lines" :
354
354
return func (a , b []string ) int {
355
355
i1 , _ := strconv .ParseInt (a [3 ], 10 , 64 )
356
356
i2 , _ := strconv .ParseInt (b [3 ], 10 , 64 )
357
357
return cmp .Compare (i2 , i1 )
358
358
}
359
- case SortBy == "blank" || SortBy == "blanks" :
359
+ case "blank" , "blanks" :
360
360
return func (a , b []string ) int {
361
361
i1 , _ := strconv .ParseInt (a [6 ], 10 , 64 )
362
362
i2 , _ := strconv .ParseInt (b [6 ], 10 , 64 )
363
363
return cmp .Compare (i2 , i1 )
364
364
}
365
- case SortBy == "code" || SortBy == "codes" :
365
+ case "code" , "codes" :
366
366
return func (a , b []string ) int {
367
367
i1 , _ := strconv .ParseInt (a [4 ], 10 , 64 )
368
368
i2 , _ := strconv .ParseInt (b [4 ], 10 , 64 )
369
369
return cmp .Compare (i2 , i1 )
370
370
}
371
- case SortBy == "comment" || SortBy == "comments" :
371
+ case "comment" , "comments" :
372
372
return func (a , b []string ) int {
373
373
i1 , _ := strconv .ParseInt (a [5 ], 10 , 64 )
374
374
i2 , _ := strconv .ParseInt (b [5 ], 10 , 64 )
375
375
return cmp .Compare (i2 , i1 )
376
376
}
377
- case SortBy == "complexity" || SortBy == "complexitys" :
377
+ case "complexity" , "complexitys" :
378
378
return func (a , b []string ) int {
379
379
i1 , _ := strconv .ParseInt (a [7 ], 10 , 64 )
380
380
i2 , _ := strconv .ParseInt (b [7 ], 10 , 64 )
381
381
return cmp .Compare (i2 , i1 )
382
382
}
383
- case SortBy == "byte" || SortBy == "bytes" :
383
+ case "byte" , "bytes" :
384
384
return func (a , b []string ) int {
385
385
i1 , _ := strconv .ParseInt (a [8 ], 10 , 64 )
386
386
i2 , _ := strconv .ParseInt (b [8 ], 10 , 64 )
@@ -919,38 +919,7 @@ func fileSummarizeLong(input chan *FileJob) string {
919
919
language = append (language , summary )
920
920
}
921
921
922
- // Cater for the common case of adding plural even for those options that don't make sense
923
- // as it's quite common for those who English is not a first language to make a simple mistake
924
- switch {
925
- case SortBy == "name" || SortBy == "names" || SortBy == "language" || SortBy == "langs" :
926
- slices .SortFunc (language , func (a , b LanguageSummary ) int {
927
- return strings .Compare (a .Name , b .Name )
928
- })
929
- case SortBy == "line" || SortBy == "lines" :
930
- slices .SortFunc (language , func (a , b LanguageSummary ) int {
931
- return cmp .Compare (b .Lines , a .Lines )
932
- })
933
- case SortBy == "blank" || SortBy == "blanks" :
934
- slices .SortFunc (language , func (a , b LanguageSummary ) int {
935
- return cmp .Compare (b .Blank , a .Blank )
936
- })
937
- case SortBy == "code" || SortBy == "codes" :
938
- slices .SortFunc (language , func (a , b LanguageSummary ) int {
939
- return cmp .Compare (b .Code , a .Code )
940
- })
941
- case SortBy == "comment" || SortBy == "comments" :
942
- slices .SortFunc (language , func (a , b LanguageSummary ) int {
943
- return cmp .Compare (b .Comment , a .Comment )
944
- })
945
- case SortBy == "complexity" || SortBy == "complexitys" :
946
- slices .SortFunc (language , func (a , b LanguageSummary ) int {
947
- return cmp .Compare (b .Complexity , a .Complexity )
948
- })
949
- default :
950
- slices .SortFunc (language , func (a , b LanguageSummary ) int {
951
- return cmp .Compare (b .Count , a .Count )
952
- })
953
- }
922
+ language = sortLanguageSummary (language )
954
923
955
924
startTime := makeTimestampMilli ()
956
925
for _ , summary := range language {
@@ -1263,14 +1232,7 @@ func maxIn(i []int) int {
1263
1232
return 0
1264
1233
}
1265
1234
1266
- m := i [0 ]
1267
- for _ , x := range i {
1268
- if x > m {
1269
- m = x
1270
- }
1271
- }
1272
-
1273
- return m
1235
+ return slices .Max (i )
1274
1236
}
1275
1237
1276
1238
func meanIn (i []int ) int {
@@ -1382,16 +1344,10 @@ func isLeapYear(year int) bool {
1382
1344
leapFlag := false
1383
1345
if year % 4 == 0 {
1384
1346
if year % 100 == 0 {
1385
- if year % 400 == 0 {
1386
- leapFlag = true
1387
- } else {
1388
- leapFlag = false
1389
- }
1347
+ leapFlag = year % 400 == 0
1390
1348
} else {
1391
1349
leapFlag = true
1392
1350
}
1393
- } else {
1394
- leapFlag = false
1395
1351
}
1396
1352
return leapFlag
1397
1353
}
@@ -1456,40 +1412,40 @@ func sortLanguageSummary(language []LanguageSummary) []LanguageSummary {
1456
1412
// as it's quite common for those who English is not a first language to make a simple mistake
1457
1413
// NB in any non name cases if the values are the same we sort by name to ensure
1458
1414
// deterministic output
1459
- switch {
1460
- case SortBy == "name" || SortBy == "names" || SortBy == "language" || SortBy == "languages " :
1415
+ switch SortBy {
1416
+ case "name" , "names" , "language" , "languages" , "lang" , "langs " :
1461
1417
slices .SortFunc (language , func (a , b LanguageSummary ) int {
1462
1418
return strings .Compare (a .Name , b .Name )
1463
1419
})
1464
- case SortBy == "line" || SortBy == "lines" :
1420
+ case "line" , "lines" :
1465
1421
slices .SortFunc (language , func (a , b LanguageSummary ) int {
1466
1422
if order := cmp .Compare (b .Lines , a .Lines ); order != 0 {
1467
1423
return order
1468
1424
}
1469
1425
return strings .Compare (a .Name , b .Name )
1470
1426
})
1471
- case SortBy == "blank" || SortBy == "blanks" :
1427
+ case "blank" , "blanks" :
1472
1428
slices .SortFunc (language , func (a , b LanguageSummary ) int {
1473
1429
if order := cmp .Compare (b .Blank , a .Blank ); order != 0 {
1474
1430
return order
1475
1431
}
1476
1432
return strings .Compare (a .Name , b .Name )
1477
1433
})
1478
- case SortBy == "code" || SortBy == "codes" :
1434
+ case "code" , "codes" :
1479
1435
slices .SortFunc (language , func (a , b LanguageSummary ) int {
1480
1436
if order := cmp .Compare (b .Code , a .Code ); order != 0 {
1481
1437
return order
1482
1438
}
1483
1439
return strings .Compare (a .Name , b .Name )
1484
1440
})
1485
- case SortBy == "comment" || SortBy == "comments" :
1441
+ case "comment" , "comments" :
1486
1442
slices .SortFunc (language , func (a , b LanguageSummary ) int {
1487
1443
if order := cmp .Compare (b .Comment , a .Comment ); order != 0 {
1488
1444
return order
1489
1445
}
1490
1446
return strings .Compare (a .Name , b .Name )
1491
1447
})
1492
- case SortBy == "complexity" || SortBy == "complexitys" :
1448
+ case "complexity" , "complexitys" :
1493
1449
slices .SortFunc (language , func (a , b LanguageSummary ) int {
1494
1450
if order := cmp .Compare (b .Complexity , a .Complexity ); order != 0 {
1495
1451
return order
0 commit comments