Skip to content

Commit

Permalink
refactor: use Go 1.22 new features (#492)
Browse files Browse the repository at this point in the history
Fixes #488
  • Loading branch information
apocelipes authored Jul 22, 2024
1 parent f926a2c commit c3aeee2
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 289 deletions.
152 changes: 76 additions & 76 deletions SCC-OUTPUT-REPORT.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
<tbody><tr>
<th>Go</th>
<th>30</th>
<th>9512</th>
<th>1475</th>
<th>9446</th>
<th>1459</th>
<th>459</th>
<th>7578</th>
<th>1530</th>
<th>253192</th>
<th>4036</th>
<th>7528</th>
<th>1506</th>
<th>252447</th>
<th>4013</th>
</tr><tr>
<td>processor/formatters.go</td>
<td></td>
<td>1612</td>
<td>215</td>
<td>1607</td>
<td>209</td>
<td>46</td>
<td>1351</td>
<td>1352</td>
<td>289</td>
<td>48042</td>
<td>797</td>
<td>47930</td>
<td>795</td>
</tr><tr>
<td>processor/workers_test.go</td>
<td></td>
Expand All @@ -53,13 +53,13 @@
</tr><tr>
<td>processor/workers.go</td>
<td></td>
<td>880</td>
<td>874</td>
<td>129</td>
<td>91</td>
<td>660</td>
<td>228</td>
<td>25607</td>
<td>496</td>
<td>654</td>
<td>226</td>
<td>25549</td>
<td>495</td>
</tr><tr>
<td>processor/processor.go</td>
<td></td>
Expand All @@ -68,7 +68,7 @@
<td>103</td>
<td>424</td>
<td>92</td>
<td>19261</td>
<td>19301</td>
<td>435</td>
</tr><tr>
<td>main.go</td>
Expand All @@ -78,7 +78,7 @@
<td>6</td>
<td>382</td>
<td>10</td>
<td>8850</td>
<td>8869</td>
<td>253</td>
</tr><tr>
<td>processor/detector_test.go</td>
Expand All @@ -93,12 +93,12 @@
</tr><tr>
<td>cmd/badges/main.go</td>
<td></td>
<td>341</td>
<td>58</td>
<td>342</td>
<td>59</td>
<td>14</td>
<td>269</td>
<td>47</td>
<td>7971</td>
<td>7991</td>
<td>202</td>
</tr><tr>
<td>processor/workers_tokei_test.go</td>
Expand All @@ -113,12 +113,12 @@
</tr><tr>
<td>processor/detector.go</td>
<td></td>
<td>238</td>
<td>45</td>
<td>236</td>
<td>44</td>
<td>33</td>
<td>160</td>
<td>59</td>
<td>6243</td>
<td>159</td>
<td>57</td>
<td>6245</td>
<td>151</td>
</tr><tr>
<td>processor/file_test.go</td>
Expand All @@ -128,18 +128,18 @@
<td>1</td>
<td>162</td>
<td>37</td>
<td>4595</td>
<td>4598</td>
<td>97</td>
</tr><tr>
<td>processor/structs.go</td>
<td></td>
<td>193</td>
<td>189</td>
<td>21</td>
<td>18</td>
<td>154</td>
<td>14</td>
<td>5646</td>
<td>132</td>
<td>150</td>
<td>12</td>
<td>5645</td>
<td>131</td>
</tr><tr>
<td>processor/workers_regression_test.go</td>
<td></td>
Expand Down Expand Up @@ -168,7 +168,7 @@
<td>1</td>
<td>114</td>
<td>21</td>
<td>2601</td>
<td>2586</td>
<td>66</td>
</tr><tr>
<td>cmd/badges/main_test.go</td>
Expand Down Expand Up @@ -211,15 +211,15 @@
<td>2043</td>
<td>52</td>
</tr><tr>
<td>processor/helpers_test.go</td>
<td>cmd/badges/simplecache_test.go</td>
<td></td>
<td>62</td>
<td>14</td>
<td>1</td>
<td>47</td>
<td>20</td>
<td>949</td>
<td>31</td>
<td>52</td>
<td>12</td>
<td>0</td>
<td>40</td>
<td>9</td>
<td>1041</td>
<td>30</td>
</tr><tr>
<td>processor/filereader.go</td>
<td></td>
Expand All @@ -230,16 +230,6 @@
<td>6</td>
<td>1329</td>
<td>37</td>
</tr><tr>
<td>cmd/badges/simplecache_test.go</td>
<td></td>
<td>52</td>
<td>12</td>
<td>0</td>
<td>40</td>
<td>9</td>
<td>1041</td>
<td>30</td>
</tr><tr>
<td>processor/cocomo.go</td>
<td></td>
Expand All @@ -250,16 +240,6 @@
<td>0</td>
<td>2222</td>
<td>35</td>
</tr><tr>
<td>processor/cocomo_test.go</td>
<td></td>
<td>37</td>
<td>8</td>
<td>4</td>
<td>25</td>
<td>6</td>
<td>699</td>
<td>23</td>
</tr><tr>
<td>processor/bloom.go</td>
<td></td>
Expand All @@ -268,18 +248,18 @@
<td>12</td>
<td>18</td>
<td>2</td>
<td>1050</td>
<td>1062</td>
<td>29</td>
</tr><tr>
<td>processor/helpers.go</td>
<td>processor/cocomo_test.go</td>
<td></td>
<td>32</td>
<td>6</td>
<td>37</td>
<td>8</td>
<td>4</td>
<td>22</td>
<td>2</td>
<td>544</td>
<td>21</td>
<td>25</td>
<td>6</td>
<td>699</td>
<td>23</td>
</tr><tr>
<td>processor/structs_test.go</td>
<td></td>
Expand All @@ -290,6 +270,16 @@
<td>4</td>
<td>517</td>
<td>19</td>
</tr><tr>
<td>processor/helpers_test.go</td>
<td></td>
<td>26</td>
<td>6</td>
<td>1</td>
<td>19</td>
<td>4</td>
<td>447</td>
<td>18</td>
</tr><tr>
<td>processor/processor_unix_test.go</td>
<td></td>
Expand All @@ -310,6 +300,16 @@
<td>0</td>
<td>165</td>
<td>12</td>
</tr><tr>
<td>processor/helpers.go</td>
<td></td>
<td>18</td>
<td>4</td>
<td>4</td>
<td>10</td>
<td>0</td>
<td>391</td>
<td>14</td>
</tr><tr>
<td>processor/constants.go</td>
<td></td>
Expand All @@ -324,15 +324,15 @@
<tfoot><tr>
<th>Total</th>
<th>30</th>
<th>9512</th>
<th>1475</th>
<th>9446</th>
<th>1459</th>
<th>459</th>
<th>7578</th>
<th>1530</th>
<th>253192</th>
<th>4036</th>
<th>7528</th>
<th>1506</th>
<th>252447</th>
<th>4013</th>
</tr>
<tr>
<th colspan="9">Estimated Cost to Develop (organic) $226,531<br>Estimated Schedule Effort (organic) 7.82 months<br>Estimated People Required (organic) 2.57<br></th>
<th colspan="9">Estimated Cost to Develop (organic) $224,961<br>Estimated Schedule Effort (organic) 7.80 months<br>Estimated People Required (organic) 2.56<br></th>
</tr></tfoot>
</table></body></html>
4 changes: 2 additions & 2 deletions processor/bloom.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package processor

import "math/rand"
import "math/rand/v2"

var BloomTable [256]uint64

Expand All @@ -15,7 +15,7 @@ func BloomHash(b byte) uint64 {
// characters) the values are not well distributed through the 0-255 byte
// range. math/rand gives us a way to generate a value with more well
// distributed randomness.
k := rand.New(rand.NewSource(int64(b))).Uint64()
k := rand.New(rand.NewPCG(uint64(b), uint64(b))).Uint64()

// Mask to slice out a 0-63 value
var mask64 uint64 = 0b00111111
Expand Down
20 changes: 9 additions & 11 deletions processor/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
package processor

import (
"cmp"
"errors"
"fmt"
"sort"
"slices"
"strings"
)

Expand All @@ -32,7 +33,7 @@ func DetectLanguage(name string) ([]string, string) {
// Convert from d.ts to ts and check that in case of multiple extensions
if !ok {
extension = getExtension(extension)
language, _ = ExtensionToLanguage[extension]
language = ExtensionToLanguage[extension]
}

return language, extension
Expand Down Expand Up @@ -72,11 +73,9 @@ func DetectSheBang(content string) (string, error) {
}

for k, v := range ShebangLookup {
for _, x := range v {
if slices.Contains(v, cmd) {
// detects both full path and env usage
if x == cmd {
return k, nil
}
return k, nil
}
}

Expand Down Expand Up @@ -202,12 +201,11 @@ func DetermineLanguage(filename string, fallbackLanguage string, possibleLanguag
toSort = append(toSort, languageGuess{Name: lan, Count: count})
}

sort.Slice(toSort, func(i, j int) bool {
if toSort[i].Count == toSort[j].Count {
return strings.Compare(toSort[i].Name, toSort[j].Name) < 0
slices.SortFunc(toSort, func(a, b languageGuess) int {
if order := cmp.Compare(b.Count, a.Count); order != 0 {
return order
}

return toSort[i].Count > toSort[j].Count
return strings.Compare(a.Name, b.Name)
})

// fmt.Println(toSort)
Expand Down
4 changes: 2 additions & 2 deletions processor/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package processor

import (
"math/rand"
"math/rand/v2"
"os"
"testing"
)
Expand Down Expand Up @@ -207,7 +207,7 @@ const letterBytes = "abcdefghijklmnopqrstuvwxyz"
func randStringBytes(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
b[i] = letterBytes[rand.IntN(len(letterBytes))]
}
return string(b)
}
Loading

0 comments on commit c3aeee2

Please sign in to comment.