chore: update golangci-lint and fix all issues (#3575)

* chore: Update golangci-lint

Signed-off-by: Lars Francke <git@lars-francke.de>

* chore: fix all golangci-lint issues

- Remove deprecated `// +build` tags
- Fix godoclint, modernize, wsl_v5, govet, lll, gci, noctx issues
- Update linter configuration
- Modernize code to use Go 1.22+ features (for range N, slices.Contains, etc.)
- Update make check lint the privileged tests

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>

---------

Signed-off-by: Lars Francke <git@lars-francke.de>
Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
Co-authored-by: Lars Francke <git@lars-francke.de>
This commit is contained in:
Andrei Aaron
2025-11-22 23:36:48 +02:00
committed by GitHub
parent 566286ae42
commit da426850e7
242 changed files with 811 additions and 1010 deletions
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
+4 -6
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
@@ -28,7 +27,7 @@ var (
)
func makeGETRequest(ctx context.Context, url, username, password string,
verifyTLS bool, debug bool, resultsPtr interface{}, configWriter io.Writer,
verifyTLS bool, debug bool, resultsPtr any, configWriter io.Writer,
) (http.Header, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
@@ -54,7 +53,7 @@ func makeHEADRequest(ctx context.Context, url, username, password string, verify
}
func makeGraphQLRequest(ctx context.Context, url, query, username,
password string, verifyTLS bool, debug bool, resultsPtr interface{}, configWriter io.Writer,
password string, verifyTLS bool, debug bool, resultsPtr any, configWriter io.Writer,
) error {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, bytes.NewBufferString(query))
if err != nil {
@@ -78,7 +77,7 @@ func makeGraphQLRequest(ctx context.Context, url, query, username,
}
func doHTTPRequest(req *http.Request, verifyTLS bool, debug bool,
resultsPtr interface{}, configWriter io.Writer,
resultsPtr any, configWriter io.Writer,
) (http.Header, error) {
var httpClient *http.Client
@@ -518,14 +517,13 @@ func isNotationSigned(ctx context.Context, repo, digestStr string, searchConf Se
func isCosignSigned(ctx context.Context, repo, digestStr string, searchConf SearchConfig,
username, password string,
) bool {
var result interface{}
var result any
cosignTag := strings.Replace(digestStr, ":", "-", 1) + "." + common.CosignSignatureTagSuffix
URL := fmt.Sprintf("%s/v2/%s/manifests/%s", searchConf.ServURL, repo, cosignTag)
_, err := makeGETRequest(ctx, URL, username, password, searchConf.VerifyTLS,
searchConf.Debug, &result, searchConf.ResultWriter)
if err == nil {
return true
}
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client_test
+20 -23
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
@@ -8,6 +7,7 @@ import (
"fmt"
"os"
"path"
"slices"
"strconv"
"strings"
"text/tabwriter"
@@ -41,6 +41,7 @@ func NewConfigCommand() *cobra.Command {
}
configPath := path.Join(home, "/.zot")
switch len(args) {
case noArgs:
if isListing { // zot config -l
@@ -162,7 +163,7 @@ func NewConfigRemoveCommand() *cobra.Command {
return configRemoveCmd
}
func getConfigMapFromFile(filePath string) ([]interface{}, error) {
func getConfigMapFromFile(filePath string) ([]any, error) {
file, err := os.OpenFile(filePath, os.O_RDONLY|os.O_CREATE, defaultConfigPerms)
if err != nil {
return nil, err
@@ -175,7 +176,7 @@ func getConfigMapFromFile(filePath string) ([]interface{}, error) {
return nil, err
}
var jsonMap map[string]interface{}
var jsonMap map[string]any
json := jsoniter.ConfigCompatibleWithStandardLibrary
@@ -185,7 +186,7 @@ func getConfigMapFromFile(filePath string) ([]interface{}, error) {
return nil, zerr.ErrEmptyJSON
}
configs, ok := jsonMap["configs"].([]interface{})
configs, ok := jsonMap["configs"].([]any)
if !ok {
return nil, zerr.ErrCliBadConfig
}
@@ -193,10 +194,10 @@ func getConfigMapFromFile(filePath string) ([]interface{}, error) {
return configs, nil
}
func saveConfigMapToFile(filePath string, configMap []interface{}) error {
func saveConfigMapToFile(filePath string, configMap []any) error {
json := jsoniter.ConfigCompatibleWithStandardLibrary
listMap := make(map[string]interface{})
listMap := make(map[string]any)
listMap["configs"] = configMap
marshalled, err := json.MarshalIndent(&listMap, "", " ")
@@ -226,7 +227,7 @@ func getConfigNames(configPath string) (string, error) {
writer := tabwriter.NewWriter(&builder, 0, 8, 1, '\t', tabwriter.AlignRight) //nolint:mnd
for _, val := range configs {
configMap, ok := val.(map[string]interface{})
configMap, ok := val.(map[string]any)
if !ok {
return "", zerr.ErrBadConfig
}
@@ -256,7 +257,7 @@ func addConfig(configPath, configName, url string) error {
return zerr.ErrDuplicateConfigName
}
configMap := make(map[string]interface{})
configMap := make(map[string]any)
configMap["url"] = url
configMap[nameKey] = configName
addDefaultConfigs(configMap)
@@ -277,7 +278,7 @@ func removeConfig(configPath, configName string) error {
}
for i, val := range configs {
configMap, ok := val.(map[string]interface{})
configMap, ok := val.(map[string]any)
if !ok {
return zerr.ErrBadConfig
}
@@ -302,7 +303,7 @@ func removeConfig(configPath, configName string) error {
return zerr.ErrConfigNotFound
}
func addDefaultConfigs(config map[string]interface{}) {
func addDefaultConfigs(config map[string]any) {
if _, ok := config[showspinnerConfig]; !ok {
config[showspinnerConfig] = true
}
@@ -323,7 +324,7 @@ func getConfigValue(configPath, configName, key string) (string, error) {
}
for _, val := range configs {
configMap, ok := val.(map[string]interface{})
configMap, ok := val.(map[string]any)
if !ok {
return "", zerr.ErrBadConfig
}
@@ -358,7 +359,7 @@ func resetConfigValue(configPath, configName, key string) error {
}
for _, val := range configs {
configMap, ok := val.(map[string]interface{})
configMap, ok := val.(map[string]any)
if !ok {
return zerr.ErrBadConfig
}
@@ -396,7 +397,7 @@ func setConfigValue(configPath, configName, key, value string) error {
}
for _, val := range configs {
configMap, ok := val.(map[string]interface{})
configMap, ok := val.(map[string]any)
if !ok {
return zerr.ErrBadConfig
}
@@ -437,7 +438,7 @@ func getAllConfig(configPath, configName string) (string, error) {
var builder strings.Builder
for _, value := range configs {
configMap, ok := value.(map[string]interface{})
configMap, ok := value.(map[string]any)
if !ok {
return "", zerr.ErrBadConfig
}
@@ -461,19 +462,15 @@ func getAllConfig(configPath, configName string) (string, error) {
return "", zerr.ErrConfigNotFound
}
func configNameExists(configs []interface{}, configName string) bool {
for _, val := range configs {
configMap, ok := val.(map[string]interface{})
func configNameExists(configs []any, configName string) bool {
return slices.ContainsFunc(configs, func(val any) bool {
configMap, ok := val.(map[string]any)
if !ok {
return false
}
if configMap[nameKey] == configName {
return true
}
}
return false
return configMap[nameKey] == configName
})
}
const (
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client_test
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
-3
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client_test
@@ -1131,10 +1130,8 @@ func getMockCveScanner(metaDB mTypes.MetaDB) cveinfo.Scanner {
for _, imageLayer := range manifestData.Manifests[0].Manifest.Layers {
switch imageLayer.MediaType {
case ispec.MediaTypeImageLayerGzip, ispec.MediaTypeImageLayer, string(regTypes.DockerLayer):
return true, nil
default:
return false, zerr.ErrScanNotSupported
}
}
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
+5 -1
View File
@@ -1,5 +1,4 @@
//go:build search && needprivileges
// +build search,needprivileges
package client_test
@@ -25,6 +24,7 @@ import (
func TestElevatedPrivilegesTLSNewControllerPrivilegedCert(t *testing.T) {
Convey("Privileged certs - Make a new controller", t, func() {
//nolint: noctx // old code, no context available
cmd := exec.Command("mkdir", "-p", "/etc/containers/certs.d/127.0.0.1:8089/") //nolint: gosec
_, err := cmd.Output()
@@ -32,6 +32,7 @@ func TestElevatedPrivilegesTLSNewControllerPrivilegedCert(t *testing.T) {
panic(err)
}
//nolint: noctx // old code, no context available
defer exec.Command("rm", "-rf", "/etc/containers/certs.d/127.0.0.1:8089/")
workDir, _ := os.Getwd()
@@ -41,6 +42,7 @@ func TestElevatedPrivilegesTLSNewControllerPrivilegedCert(t *testing.T) {
caGlob, _ := filepath.Glob("ca.*")
for _, file := range clientGlob {
//nolint: noctx // old code, no context available
cmd = exec.Command("cp", file, "/etc/containers/certs.d/127.0.0.1:8089/")
res, err := cmd.CombinedOutput()
@@ -50,6 +52,7 @@ func TestElevatedPrivilegesTLSNewControllerPrivilegedCert(t *testing.T) {
}
for _, file := range caGlob {
//nolint: noctx // old code, no context available
cmd = exec.Command("cp", file, "/etc/containers/certs.d/127.0.0.1:8089/")
res, err := cmd.CombinedOutput()
@@ -61,6 +64,7 @@ func TestElevatedPrivilegesTLSNewControllerPrivilegedCert(t *testing.T) {
allGlob, _ := filepath.Glob("/etc/containers/certs.d/127.0.0.1:8089/*.key")
for _, file := range allGlob {
//nolint: noctx // old code, no context available
cmd = exec.Command("chmod", "a=rwx", file)
res, err := cmd.CombinedOutput()
+5 -6
View File
@@ -1,14 +1,13 @@
//go:build search
// +build search
package client
import (
"fmt"
"slices"
"strings"
zerr "zotregistry.dev/zot/v2/errors"
"zotregistry.dev/zot/v2/pkg/common"
)
const (
@@ -91,7 +90,7 @@ func (e *CVEListSortFlag) String() string {
}
func (e *CVEListSortFlag) Set(val string) error {
if !common.Contains(CVEListSortOptions(), val) {
if !slices.Contains(CVEListSortOptions(), val) {
return fmt.Errorf("%w %s", zerr.ErrFlagValueUnsupported, CVEListSortOptionsStr())
}
@@ -111,7 +110,7 @@ func (e *ImageListSortFlag) String() string {
}
func (e *ImageListSortFlag) Set(val string) error {
if !common.Contains(ImageListSortOptions(), val) {
if !slices.Contains(ImageListSortOptions(), val) {
return fmt.Errorf("%w %s", zerr.ErrFlagValueUnsupported, ImageListSortOptionsStr())
}
@@ -131,7 +130,7 @@ func (e *ImageSearchSortFlag) String() string {
}
func (e *ImageSearchSortFlag) Set(val string) error {
if !common.Contains(ImageSearchSortOptions(), val) {
if !slices.Contains(ImageSearchSortOptions(), val) {
return fmt.Errorf("%w %s", zerr.ErrFlagValueUnsupported, ImageSearchSortOptionsStr())
}
@@ -151,7 +150,7 @@ func (e *RepoListSortFlag) String() string {
}
func (e *RepoListSortFlag) Set(val string) error {
if !common.Contains(RepoListSortOptions(), val) {
if !slices.Contains(RepoListSortOptions(), val) {
return fmt.Errorf("%w %s", zerr.ErrFlagValueUnsupported, RepoListSortOptionsStr())
}
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client_test
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client_test
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client_test
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client_test
+1 -2
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
@@ -11,7 +10,7 @@ import (
"zotregistry.dev/zot/v2/pkg/log"
)
// "zli" - client-side cli.
// NewCliRootCmd creates the root command for "zli" - client-side cli.
func NewCliRootCmd() *cobra.Command {
showVersion := false
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client_test
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client_test
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
@@ -1,5 +1,4 @@
//go:build search
// +build search
//
//nolint:dupl
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client //nolint:testpackage
+1 -2
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
@@ -687,7 +686,7 @@ func (service searchService) getImagesByDigest(ctx context.Context, config Searc
// errors are returned in the stringResult channel, the unmarshalled payload is in resultPtr.
func (service searchService) makeGraphQLQuery(ctx context.Context,
config SearchConfig, username, password, query string,
resultPtr interface{},
resultPtr any,
) error {
endPoint, err := combineServerAndEndpointURL(config.ServURL, constants.FullSearchPrefix)
if err != nil {
+4 -5
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client
@@ -251,9 +250,9 @@ func printReferrersTableHeader(config SearchConfig, writer io.Writer, maxArtifac
if maxArtifactTypeLen > len("ARTIFACT TYPE") {
offset = strings.Repeat(" ", maxArtifactTypeLen-len("ARTIFACT TYPE"))
row[refArtifactTypeIndex] = "ARTIFACT TYPE" + offset
row[refArtifactTypeIndex] = "ARTIFACT TYPE" + offset //nolint: gosec
} else {
row[refArtifactTypeIndex] = "ARTIFACT TYPE"
row[refArtifactTypeIndex] = "ARTIFACT TYPE" //nolint: gosec
}
row[refDigestIndex] = "DIGEST"
@@ -290,9 +289,9 @@ func printRepoTableHeader(writer io.Writer, repoMaxLen, maxTimeLen int, verbose
if repoMaxLen > len("LAST UPDATED") {
offset = strings.Repeat(" ", repoMaxLen-len("LAST UPDATED"))
row[repoLastUpdatedIndex] = "LAST UPDATED" + offset
row[repoLastUpdatedIndex] = "LAST UPDATED" + offset //nolint: gosec
} else {
row[repoLastUpdatedIndex] = "LAST UPDATED"
row[repoLastUpdatedIndex] = "LAST UPDATED" //nolint: gosec
}
row[repoSizeIndex] = sizeColumn
-1
View File
@@ -1,5 +1,4 @@
//go:build search
// +build search
package client