From c37c8f555e616ae06b3ccd4634e36c94298fcda7 Mon Sep 17 00:00:00 2001 From: chainchad <96362174+chainchad@users.noreply.github.com> Date: Sat, 23 Nov 2024 20:21:05 -0500 Subject: [PATCH] Address linting 2 --- tools/gomod-required-updater/internal/updater/interfaces.go | 6 +++--- .../internal/updater/module_operator.go | 3 ++- .../internal/updater/system_operator.go | 4 ---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/tools/gomod-required-updater/internal/updater/interfaces.go b/tools/gomod-required-updater/internal/updater/interfaces.go index 6542bac611e..f8dd222a038 100644 --- a/tools/gomod-required-updater/internal/updater/interfaces.go +++ b/tools/gomod-required-updater/internal/updater/interfaces.go @@ -4,7 +4,7 @@ package updater import ( - "fmt" + "errors" "os" "time" @@ -19,9 +19,9 @@ const ( // Errors that can be returned by the updater package var ( // ErrModOperation indicates a failure in a module-related operation - ErrModOperation = fmt.Errorf("module operation failed") + ErrModOperation = errors.New("module operation failed") // ErrInvalidConfig indicates invalid configuration parameters - ErrInvalidConfig = fmt.Errorf("invalid configuration") + ErrInvalidConfig = errors.New("invalid configuration") ) // ModuleOperator handles Git repository operations and module version management. diff --git a/tools/gomod-required-updater/internal/updater/module_operator.go b/tools/gomod-required-updater/internal/updater/module_operator.go index 83039aa5a72..4f59b2f5a5b 100644 --- a/tools/gomod-required-updater/internal/updater/module_operator.go +++ b/tools/gomod-required-updater/internal/updater/module_operator.go @@ -63,6 +63,7 @@ func validateGitInput(remote, branch string) error { // GetGitInfo retrieves the latest commit SHA and timestamp from a Git repository func (m *moduleOperator) GetGitInfo(remote, branch string) (string, time.Time, error) { + // Validate remote and branch against strict regex patterns before using in exec if err := validateGitInput(remote, branch); err != nil { return "", time.Time{}, err } @@ -74,7 +75,7 @@ func (m *moduleOperator) GetGitInfo(remote, branch string) (string, time.Time, e cmd := exec.CommandContext(ctx, "git", "ls-remote", remote, "refs/heads/"+branch) out, err := cmd.Output() if err != nil { - return "", time.Time{}, fmt.Errorf("%w: failed to get SHA: %v", ErrModOperation, err) + return "", time.Time{}, fmt.Errorf("%w: failed to get SHA: %w", ErrModOperation, err) } if len(out) == 0 { return "", time.Time{}, fmt.Errorf("%w: no output from git ls-remote", ErrModOperation) diff --git a/tools/gomod-required-updater/internal/updater/system_operator.go b/tools/gomod-required-updater/internal/updater/system_operator.go index 29e50f471aa..49ed7ae4b40 100644 --- a/tools/gomod-required-updater/internal/updater/system_operator.go +++ b/tools/gomod-required-updater/internal/updater/system_operator.go @@ -5,10 +5,6 @@ import ( "path/filepath" ) -const ( - defaultFileMode = 0644 -) - type systemOperator struct{} func NewSystemOperator() SystemOperator {