From e569b9f74a60971e074e84cdf12fdc85b2d94cdb Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 18 Feb 2025 09:28:55 +0100 Subject: [PATCH 1/3] cli/internal/oauth: don't use naked returns (nakedret) cli/internal/oauth/jwt.go:62:3: naked return in func `GetClaims` with 9 lines of code (nakedret) return ^ cli/internal/oauth/jwt.go:67:2: naked return in func `GetClaims` with 9 lines of code (nakedret) return ^ Signed-off-by: Sebastiaan van Stijn --- cli/internal/oauth/jwt.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/internal/oauth/jwt.go b/cli/internal/oauth/jwt.go index 87ad1024e9..437ef42569 100644 --- a/cli/internal/oauth/jwt.go +++ b/cli/internal/oauth/jwt.go @@ -56,15 +56,19 @@ type Source struct { } // GetClaims returns claims from an access token without verification. -func GetClaims(accessToken string) (claims Claims, err error) { +func GetClaims(accessToken string) (Claims, error) { token, err := parseSigned(accessToken) if err != nil { - return + return Claims{}, err } + var claims Claims err = token.UnsafeClaimsWithoutVerification(&claims) + if err != nil { + return Claims{}, err + } - return + return claims, nil } // allowedSignatureAlgorithms is a list of allowed signature algorithms for JWTs. From a5020ea165c499947bccd923410d1dc5da985898 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 18 Feb 2025 09:29:15 +0100 Subject: [PATCH 2/3] cli/command/container: don't use naked returns (nakedret) cli/command/container/cp.go:206:3: naked return in func `resolveLocalPath` with 5 lines of code (nakedret) return ^ Signed-off-by: Sebastiaan van Stijn --- cli/command/container/cp.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/command/container/cp.go b/cli/command/container/cp.go index 5eb3d7113c..85e9f6164f 100644 --- a/cli/command/container/cp.go +++ b/cli/command/container/cp.go @@ -201,9 +201,10 @@ func runCopy(ctx context.Context, dockerCli command.Cli, opts copyOptions) error } } -func resolveLocalPath(localPath string) (absPath string, err error) { - if absPath, err = filepath.Abs(localPath); err != nil { - return +func resolveLocalPath(localPath string) (absPath string, _ error) { + absPath, err := filepath.Abs(localPath) + if err != nil { + return "", err } return archive.PreserveTrailingDotOrSeparator(absPath, localPath), nil } From 1c8243cc9540dff6d0d3e6d007eccf155d6e5bbd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 18 Feb 2025 09:35:30 +0100 Subject: [PATCH 3/3] golangci-lint: fix invalid nakedret config, disallow for any func length The regex was added before we migrateed from gometalinter in dbd96badb6959c2b7070664aecbcf0f7c299c538, and got migrated to golangci-lint in b7e06f2845bb4996269a49f2592a735e4cd03e49. The format used for the config was invalid, and migrating it to the right format didn't make a difference, so we can remove it. As naked returns are generally not desirable, also setting the minimum func length to 0 (i.e., don't allow any naked returns), instead of the default Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index fc4d8b48df..aa54d46c9b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,7 +17,7 @@ linters: - ineffassign - lll - misspell # Detects commonly misspelled English words in comments. - - nakedret + - nakedret # Detects uses of naked returns. - nilerr # Detects code that returns nil even if it checks that the error is not nil. - nolintlint # Detects ill-formed or insufficient nolint directives. - perfsprint # Detects fmt.Sprintf uses that can be replaced with a faster alternative. @@ -81,8 +81,9 @@ linters-settings: lll: line-length: 200 nakedret: - command: nakedret - pattern: ^(?P.*?\\.go):(?P\\d+)\\s*(?P.*)$ + # Disallow naked returns if func has more lines of code than this setting. + # Default: 30 + max-func-lines: 0 revive: rules: