Fix: Ensure constant format strings in fmt and printf calls

Go 1.24 introduces stricter checks for format string validation.
This commit fixes instances where non-constant format strings were
used in calls to functions like `fmt.Errorf`, `fmt.Printf`, and similar.

Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
This commit is contained in:
Mikel Olasagasti Uranga 2025-01-20 16:27:25 +01:00
parent fe74349fe4
commit 4396e40a31
4 changed files with 9 additions and 8 deletions

View file

@ -88,7 +88,7 @@ func tokenRun(opts *TokenOptions) error {
if opts.Username != "" {
errMsg += fmt.Sprintf(" account %s", opts.Username)
}
return fmt.Errorf(errMsg)
return fmt.Errorf("%s", errMsg)
}
if val != "" {

View file

@ -648,14 +648,14 @@ Alternatively, you can run "create" with the "--default-permissions" option to c
assert.EqualError(t, err, tt.wantErr.Error())
}
if err != nil && tt.wantErr == nil {
t.Logf(err.Error())
t.Logf("%s", err.Error())
}
if got := stdout.String(); got != tt.wantStdout {
t.Logf(t.Name())
t.Logf("%s", t.Name())
t.Errorf(" stdout = %v, want %v", got, tt.wantStdout)
}
if got := stderr.String(); got != tt.wantStderr {
t.Logf(t.Name())
t.Logf("%s", t.Name())
t.Errorf(" stderr = %v, want %v", got, tt.wantStderr)
}

View file

@ -384,13 +384,14 @@ func (m *mergeContext) deleteLocalBranch() error {
if m.merged {
if m.opts.IO.CanPrompt() && !m.opts.IsDeleteBranchIndicated {
confirmed, err := m.opts.Prompter.Confirm(fmt.Sprintf("Pull request %s#%d was already merged. Delete the branch locally?", ghrepo.FullName(m.baseRepo), m.pr.Number), false)
message := fmt.Sprintf("Pull request %s#%d was already merged. Delete the branch locally?", ghrepo.FullName(m.baseRepo), m.pr.Number)
confirmed, err := m.opts.Prompter.Confirm(message, false)
if err != nil {
return fmt.Errorf("could not prompt: %w", err)
}
m.deleteBranch = confirmed
} else {
_ = m.warnf(fmt.Sprintf("%s Pull request %s#%d was already merged\n", m.cs.WarningIcon(), ghrepo.FullName(m.baseRepo), m.pr.Number))
_ = m.warnf("%s Pull request %s#%d was already merged\n", m.cs.WarningIcon(), ghrepo.FullName(m.baseRepo), m.pr.Number)
}
}
@ -431,7 +432,7 @@ func (m *mergeContext) deleteLocalBranch() error {
}
if err := m.opts.GitClient.Pull(ctx, baseRemote.Name, targetBranch); err != nil {
_ = m.warnf(fmt.Sprintf("%s warning: not possible to fast-forward to: %q\n", m.cs.WarningIcon(), targetBranch))
_ = m.warnf("%s warning: not possible to fast-forward to: %q\n", m.cs.WarningIcon(), targetBranch)
}
switchedToBranch = targetBranch

View file

@ -156,7 +156,7 @@ func viewRun(opts *ViewOptions) error {
fmt.Fprintf(stdout, "description:\t%s\n", repo.Description)
if readme != nil {
fmt.Fprintln(stdout, "--")
fmt.Fprintf(stdout, readme.Content)
fmt.Fprintf(stdout, "%s", readme.Content)
fmt.Fprintln(stdout)
}