Skip to content

Commit daaefd6

Browse files
authored
Enable more linters (#414)
1 parent 42a26b3 commit daaefd6

File tree

4 files changed

+51
-48
lines changed

4 files changed

+51
-48
lines changed

.golangci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ linters:
3838
- errname
3939
- errorlint
4040
- exhaustive
41+
- exptostd
4142
- forbidigo
4243
- forcetypeassert
44+
- funcorder
4345
# - funlen
4446
- ginkgolinter
4547
- gocheckcompilerdirectives
@@ -60,6 +62,7 @@ linters:
6062
- grouper
6163
- importas
6264
- interfacebloat
65+
- intrange
6366
# - ireturn
6467
- lll
6568
- loggercheck
@@ -80,11 +83,11 @@ linters:
8083
- prealloc
8184
- predeclared
8285
- promlinter
86+
- protogetter
8387
- reassign
8488
- revive
8589
- rowserrcheck
8690
- sqlclosecheck
87-
# - stylecheck
8891
- tagliatelle
8992
- testableexamples
9093
- testpackage

crawler/crawler.go

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"path"
1010
"regexp"
1111
"runtime"
12+
"slices"
1213
"strings"
1314
"sync"
1415

@@ -22,7 +23,6 @@ import (
2223
publiccode "github.com/italia/publiccode-parser-go/v4"
2324
log "github.com/sirupsen/logrus"
2425
"github.com/spf13/viper"
25-
"golang.org/x/exp/slices"
2626
)
2727

2828
// Crawler is a helper class representing a crawler.
@@ -162,47 +162,6 @@ func (c *Crawler) CrawlPublishers(publishers []common.Publisher) error {
162162
return c.crawl()
163163
}
164164

165-
func (c *Crawler) crawl() error {
166-
reposChan := make(chan common.Repository)
167-
168-
// Start the metrics server.
169-
go metrics.StartPrometheusMetricsServer()
170-
171-
defer c.publishersWg.Wait()
172-
173-
// Get cpus number
174-
numCPUs := runtime.NumCPU()
175-
log.Debugf("CPUs #: %d", numCPUs)
176-
177-
// Process the repositories in order to retrieve the files.
178-
for i := 0; i < numCPUs; i++ {
179-
c.repositoriesWg.Add(1)
180-
go func(id int) {
181-
log.Debugf("Starting ProcessRepositories() goroutine (#%d)", id)
182-
c.ProcessRepositories(reposChan)
183-
}(i)
184-
}
185-
186-
for repo := range c.repositories {
187-
reposChan <- repo
188-
}
189-
close(reposChan)
190-
c.repositoriesWg.Wait()
191-
192-
log.Infof(
193-
"Summary: Total repos scanned: %v. With good publiccode.yml file: %v. With bad publiccode.yml file: %v\n"+
194-
"Repos with good publiccode.yml file: New repos: %v, Known repos: %v, Failures saving to API: %v",
195-
metrics.GetCounterValue("repository_processed", c.Index),
196-
metrics.GetCounterValue("repository_good_publiccodeyml", c.Index),
197-
metrics.GetCounterValue("repository_bad_publiccodeyml", c.Index),
198-
metrics.GetCounterValue("repository_new", c.Index),
199-
metrics.GetCounterValue("repository_known", c.Index),
200-
metrics.GetCounterValue("repository_upsert_failures", c.Index),
201-
)
202-
203-
return nil
204-
}
205-
206165
// ScanPublisher scans all the publisher' repositories and sends the ones
207166
// with a valid publiccode.yml to the repositories channel.
208167
func (c *Crawler) ScanPublisher(publisher common.Publisher) {
@@ -484,6 +443,47 @@ func (c *Crawler) ProcessRepo(repository common.Repository) { //nolint:maintidx
484443
}
485444
}
486445

446+
func (c *Crawler) crawl() error {
447+
reposChan := make(chan common.Repository)
448+
449+
// Start the metrics server.
450+
go metrics.StartPrometheusMetricsServer()
451+
452+
defer c.publishersWg.Wait()
453+
454+
// Get cpus number
455+
numCPUs := runtime.NumCPU()
456+
log.Debugf("CPUs #: %d", numCPUs)
457+
458+
// Process the repositories in order to retrieve the files.
459+
for i := range numCPUs {
460+
c.repositoriesWg.Add(1)
461+
go func(id int) {
462+
log.Debugf("Starting ProcessRepositories() goroutine (#%d)", id)
463+
c.ProcessRepositories(reposChan)
464+
}(i)
465+
}
466+
467+
for repo := range c.repositories {
468+
reposChan <- repo
469+
}
470+
close(reposChan)
471+
c.repositoriesWg.Wait()
472+
473+
log.Infof(
474+
"Summary: Total repos scanned: %v. With good publiccode.yml file: %v. With bad publiccode.yml file: %v\n"+
475+
"Repos with good publiccode.yml file: New repos: %v, Known repos: %v, Failures saving to API: %v",
476+
metrics.GetCounterValue("repository_processed", c.Index),
477+
metrics.GetCounterValue("repository_good_publiccodeyml", c.Index),
478+
metrics.GetCounterValue("repository_bad_publiccodeyml", c.Index),
479+
metrics.GetCounterValue("repository_new", c.Index),
480+
metrics.GetCounterValue("repository_known", c.Index),
481+
metrics.GetCounterValue("repository_upsert_failures", c.Index),
482+
)
483+
484+
return nil
485+
}
486+
487487
// validateFile performs additional validations that are not strictly mandated
488488
// by the publiccode.yml Standard.
489489
// Using `one` command this check will be skipped.

git/repo_activity.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func CalculateRepoActivity(repository common.Repository, days int) (float64, map
9595
log.Warn(err)
9696
}
9797

98-
for i := 0; i < days; i++ {
98+
for i := range days {
9999
userCommunity = ranges("userCommunity", userCommunityLastDays(commitsLastDays[i]))
100100

101101
codeActivity = ranges("codeActivity", activityLastDays(commitsPerDay[i]))
@@ -271,7 +271,7 @@ func ranges(name string, value float64) float64 {
271271
func extractCommitsLastDays(days int, commits []*object.Commit) map[int][]*object.Commit {
272272
commitsLastDays := map[int][]*object.Commit{}
273273
// Populate the slice of commits in every day.
274-
for i := 0; i < days; i++ {
274+
for i := range days {
275275
lastDays := time.Now().AddDate(0, 0, -i)
276276
// Append all the commits created before lastDays date.
277277
for _, c := range commits {
@@ -288,7 +288,7 @@ func extractCommitsLastDays(days int, commits []*object.Commit) map[int][]*objec
288288
func extractCommitsPerDay(days int, commits []*object.Commit) map[int][]*object.Commit {
289289
commitsPerDay := map[int][]*object.Commit{}
290290
// Populate the slice of commits in every day.
291-
for i := 0; i < days; i++ {
291+
for i := range days {
292292
lastDays := time.Now().AddDate(0, 0, -i)
293293
// Append all the commits created before lastDays date.
294294
for _, c := range commits {
@@ -306,7 +306,7 @@ func extractCommitsPerDay(days int, commits []*object.Commit) map[int][]*object.
306306
// extractTagsPerDay returns a map of #[days] commits where a tag is created.
307307
func extractTagsPerDay(days int, tags []*object.Commit) map[int][]*object.Commit {
308308
tagsPerDays := map[int][]*object.Commit{}
309-
for i := 0; i < days; i++ {
309+
for i := range days {
310310
lastDays := time.Now().AddDate(0, 0, -i)
311311
// Append all the commits created before lastDays date.
312312
for _, t := range tags {

metrics/prometheus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func GetCounterValue(name, namespace string) float64 {
4040
return 0
4141
}
4242

43-
return m.Counter.GetValue()
43+
return m.GetCounter().GetValue()
4444
}
4545

4646
// RegisterPrometheusCounter register a new Counter of given name with help text.

0 commit comments

Comments
 (0)