Skip to content

Commit be85d56

Browse files
authored
Merge pull request #2 from git-pkgs/fix-lint-issues
Fix all golangci-lint issues
2 parents 4ad6979 + 8745766 commit be85d56

9 files changed

Lines changed: 717 additions & 603 deletions

File tree

brief.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ const (
2525
SourceConfigFile Source = "config_file"
2626
)
2727

28+
// Scope values for DepInfo.
29+
const (
30+
ScopeRuntime = "runtime"
31+
ScopeDevelopment = "development"
32+
ScopeTest = "test"
33+
ScopeBuild = "build"
34+
)
35+
2836
// Command is a runnable command with provenance.
2937
type Command struct {
3038
Run string `json:"run"`

cmd/brief/diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func cmdDiff(args []string) {
4848
ref1 = fs.Arg(0)
4949
includeUncommitted = true
5050
diffRef = ref1 + " (+ uncommitted)"
51-
case 2:
51+
case 2: //nolint:mnd // two refs
5252
ref1 = fs.Arg(0)
5353
ref2 = fs.Arg(1)
5454
diffRef = ref1 + ".." + ref2

cmd/brief/enrich.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,43 @@ func cmdEnrich(args []string) {
4747
_, _ = fmt.Fprintf(os.Stderr, "error: %v\n", err)
4848
os.Exit(1)
4949
}
50-
defer src.Cleanup()
5150

51+
code := runEnrich(src.Dir, *scanDepth, *skip, *jsonFlag, *humanFlag, *verbose)
52+
src.Cleanup()
53+
os.Exit(code)
54+
}
55+
56+
func runEnrich(dir string, scanDepth int, skip string, jsonFlag, humanFlag, verbose bool) int {
5257
knowledgeBase, err := kb.Load(brief.KnowledgeFS)
5358
if err != nil {
5459
_, _ = fmt.Fprintf(os.Stderr, "error loading knowledge base: %v\n", err)
55-
os.Exit(1)
60+
return 1
5661
}
5762

58-
engine := detect.New(knowledgeBase, src.Dir)
59-
engine.ScanDepth = *scanDepth
60-
if *skip != "" {
61-
engine.SkipDirs = strings.Split(*skip, ",")
63+
engine := detect.New(knowledgeBase, dir)
64+
engine.ScanDepth = scanDepth
65+
if skip != "" {
66+
engine.SkipDirs = strings.Split(skip, ",")
6267
}
6368
r, err := engine.Run()
6469
if err != nil {
6570
_, _ = fmt.Fprintf(os.Stderr, "error: %v\n", err)
66-
os.Exit(1)
71+
return 1
6772
}
6873

6974
ctx := context.Background()
70-
r.Enrichment = enrich(ctx, r, src.Dir)
75+
r.Enrichment = enrich(ctx, r, dir)
7176

72-
useJSON := *jsonFlag || (!*humanFlag && !isTTY())
77+
useJSON := jsonFlag || (!humanFlag && !isTTY())
7378
if useJSON {
7479
if err := report.JSON(os.Stdout, r); err != nil {
7580
_, _ = fmt.Fprintf(os.Stderr, "error writing JSON: %v\n", err)
76-
os.Exit(1)
81+
return 1
7782
}
7883
} else {
79-
report.Human(os.Stdout, r, *verbose)
84+
report.Human(os.Stdout, r, verbose)
8085
}
86+
return 0
8187
}
8288

8389
func enrich(ctx context.Context, r *brief.Report, root string) *brief.EnrichmentInfo {
@@ -87,7 +93,7 @@ func enrich(ctx context.Context, r *brief.Report, root string) *brief.Enrichment
8793
var mu sync.Mutex
8894

8995
// Published packages
90-
purls := detectPublishedPURLs(root, r)
96+
purls := detectPublishedPURLs(root)
9197
if len(purls) > 0 {
9298
wg.Add(1)
9399
go func() {
@@ -124,7 +130,7 @@ func enrich(ctx context.Context, r *brief.Report, root string) *brief.Enrichment
124130

125131
// detectPublishedPURLs figures out what packages this repo publishes by
126132
// reading the project's own identity from manifest files.
127-
func detectPublishedPURLs(root string, r *brief.Report) []string {
133+
func detectPublishedPURLs(root string) []string {
128134
var purls []string
129135

130136
// Go module
@@ -207,7 +213,7 @@ func pythonPackagePURL(root string) string {
207213
for _, line := range strings.Split(string(data), "\n") {
208214
line = strings.TrimSpace(line)
209215
if strings.HasPrefix(line, "name") && strings.Contains(line, "=") {
210-
parts := strings.SplitN(line, "=", 2)
216+
parts := strings.SplitN(line, "=", 2) //nolint:mnd // key=value split
211217
name := strings.TrimSpace(parts[1])
212218
if name != "" {
213219
return "pkg:pypi/" + name
@@ -424,8 +430,8 @@ func productFromFile(file string) string {
424430

425431
func majorMinor(version string) string {
426432
version = strings.TrimSpace(version)
427-
parts := strings.SplitN(version, ".", 3)
428-
if len(parts) < 2 {
433+
parts := strings.SplitN(version, ".", 3) //nolint:mnd // major.minor.patch
434+
if len(parts) < 2 { //nolint:mnd // need at least major.minor
429435
return version
430436
}
431437
return parts[0] + "." + parts[1]

cmd/brief/main.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,39 +79,45 @@ func cmdScan(args []string) {
7979
_, _ = fmt.Fprintf(os.Stderr, "error: %v\n", err)
8080
os.Exit(1)
8181
}
82-
defer src.Cleanup()
8382

83+
code := runScan(src.Dir, *scanDepth, *skip, *category, *jsonFlag, *humanFlag, *verbose)
84+
src.Cleanup()
85+
os.Exit(code)
86+
}
87+
88+
func runScan(dir string, scanDepth int, skip, category string, jsonFlag, humanFlag, verbose bool) int {
8489
knowledgeBase, err := kb.Load(brief.KnowledgeFS)
8590
if err != nil {
8691
_, _ = fmt.Fprintf(os.Stderr, "error loading knowledge base: %v\n", err)
87-
os.Exit(1)
92+
return 1
8893
}
8994

90-
engine := detect.New(knowledgeBase, src.Dir)
91-
engine.ScanDepth = *scanDepth
92-
if *skip != "" {
93-
engine.SkipDirs = strings.Split(*skip, ",")
95+
engine := detect.New(knowledgeBase, dir)
96+
engine.ScanDepth = scanDepth
97+
if skip != "" {
98+
engine.SkipDirs = strings.Split(skip, ",")
9499
}
95100
r, err := engine.Run()
96101
if err != nil {
97102
_, _ = fmt.Fprintf(os.Stderr, "error: %v\n", err)
98-
os.Exit(1)
103+
return 1
99104
}
100105

101-
if *category != "" {
102-
r = filterCategory(r, *category)
106+
if category != "" {
107+
r = filterCategory(r, category)
103108
}
104109

105-
useJSON := *jsonFlag || (!*humanFlag && !isTTY())
110+
useJSON := jsonFlag || (!humanFlag && !isTTY())
106111

107112
if useJSON {
108113
if err := report.JSON(os.Stdout, r); err != nil {
109114
_, _ = fmt.Fprintf(os.Stderr, "error writing JSON: %v\n", err)
110-
os.Exit(1)
115+
return 1
111116
}
112117
} else {
113-
report.Human(os.Stdout, r, *verbose)
118+
report.Human(os.Stdout, r, verbose)
114119
}
120+
return 0
115121
}
116122

117123
func cmdList(args []string) {

0 commit comments

Comments
 (0)