Skip to content

Commit fa8f07e

Browse files
committed
Clean up golangci lint errors
Linter was noting a lot of issues with the hack/extract-licenses.go, but we are pretty certain we want this to be this way.
1 parent c17c6d0 commit fa8f07e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

hack/extract-licenses.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ the environment: https://go.dev/ref/mod#module-cache`,
8181

8282
// Gather license files from every module into the target directory.
8383
for module, directory := range directories {
84-
for _, license := range findLicenses(ctx, directory) {
84+
for _, license := range findLicenses(directory) {
8585
relative := module + strings.TrimPrefix(license, directory)
8686
destination := filepath.Join(flags.Arg(0), relative)
8787

@@ -95,9 +95,12 @@ the environment: https://go.dev/ref/mod#module-cache`,
9595
data, err = os.ReadFile(license)
9696
}
9797
if err == nil {
98+
//nolint:gosec // gosec warns on permissions more open than 600
99+
// but we need these licenses to be readable by all
98100
err = os.WriteFile(destination, data, 0o644)
99101
}
100102
if err == nil {
103+
//nolint:forbidigo // This is an intentional print to console to inform the user
101104
fmt.Println(license, "=>", destination)
102105
}
103106
if err != nil {
@@ -113,6 +116,7 @@ func downloadModules(ctx context.Context, modules ...string) map[string]string {
113116

114117
// Download modules and read their details into a series of JSON objects.
115118
// - https://go.dev/ref/mod#go-mod-download
119+
//nolint:gosec // Suppressing unnecessary warning re: potentially tainted inputs (G204)
116120
cmd := exec.CommandContext(ctx, os.Getenv("GO"), append([]string{"mod", "download", "-json"}, modules...)...)
117121
if cmd.Path == "" {
118122
cmd.Path, cmd.Err = exec.LookPath("go")
@@ -132,7 +136,11 @@ func downloadModules(ctx context.Context, modules ...string) map[string]string {
132136
// - https://go.dev/ref/mod#module-cache
133137
// - https://go.dev/ref/mod#module-path
134138
for {
135-
var module struct{ Path, Version, Dir string }
139+
var module struct {
140+
Path string `json:"path,omitempty"`
141+
Version string `json:"version,omitempty"`
142+
Dir string `json:"dir,omitempty"`
143+
}
136144
err := decoder.Decode(&module)
137145

138146
if err == nil {
@@ -150,7 +158,7 @@ func downloadModules(ctx context.Context, modules ...string) map[string]string {
150158
return results
151159
}
152160

153-
func findLicenses(ctx context.Context, directory string) []string {
161+
func findLicenses(directory string) []string {
154162
var results []string
155163

156164
// Syft maintains a list of license filenames that began as a list maintained by
@@ -188,6 +196,7 @@ func identifyModules(ctx context.Context, executables ...string) []string {
188196

189197
// Use `go version -m` to read the embedded module information as a text table.
190198
// - https://go.dev/ref/mod#go-version-m
199+
//nolint:gosec // Suppressing unnecessary warning re: potentially tainted inputs (G204)
191200
cmd := exec.CommandContext(ctx, os.Getenv("GO"), append([]string{"version", "-m"}, executables...)...)
192201
if cmd.Path == "" {
193202
cmd.Path, cmd.Err = exec.LookPath("go")

0 commit comments

Comments
 (0)