Fix linting issues: canonicalheader, embeddedstructfieldcheck, iotamixing, makezero, testableexamples, wastedassign, usetesting, tparallel, unconvert, intrange, iface
- canonicalheader: fix cacheTTL header value to canonical form - embeddedstructfieldcheck: move embedded fields before regular fields in 4 structs - iotamixing: split const blocks mixing iota with non-iota constants - makezero: use make([]T, 0, n) instead of make([]T, n) before appending - testableexamples: add missing Output: comment to ExampleOption_UnwrapOrZero - wastedassign: remove wasted initial assignments in 4 locations - usetesting: replace os.MkdirTemp/os.Setenv with t.TempDir/t.Setenv in tests - tparallel: add t.Parallel() to 8 top-level test functions - unconvert: remove 16 unnecessary type conversions - intrange: convert 3 for loops to use integer range syntax - iface: consolidate identical EditPrompter and Prompt interfaces via type alias Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
6c11ecd9ab
commit
dca59d52b6
113 changed files with 222 additions and 287 deletions
|
|
@ -363,6 +363,7 @@ func Test_checkoutRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSpecificPRResolver(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("when the PR Finder returns results, those are returned", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
@ -398,6 +399,7 @@ func TestSpecificPRResolver(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPromptingPRResolver(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("when the PR Lister has results, then we prompt for a choice", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
|
|||
|
|
@ -540,7 +540,6 @@ func createRun(opts *CreateOptions) error {
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
|
||||
if !opts.TitleProvided {
|
||||
err = shared.TitleSurvey(opts.Prompter, opts.IO, state)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -2632,7 +2632,6 @@ func mockRetrieveProjects(_ *testing.T, reg *httpmock.Registry) {
|
|||
// TODO projectsV1Deprecation
|
||||
// Remove this test.
|
||||
func TestProjectsV1Deprecation(t *testing.T) {
|
||||
|
||||
t.Run("non-interactive submission", func(t *testing.T) {
|
||||
t.Run("when projects v1 is supported, queries for it", func(t *testing.T) {
|
||||
ios, _, _, _ := iostreams.Test()
|
||||
|
|
|
|||
|
|
@ -341,7 +341,9 @@ type sanitizer struct{ transform.NopResetter }
|
|||
|
||||
// Transform implements transform.Transformer.
|
||||
func (t sanitizer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
|
||||
for r, size := rune(0), 0; nSrc < len(src); {
|
||||
var r rune
|
||||
var size int
|
||||
for nSrc < len(src) {
|
||||
if r = rune(src[nSrc]); r < utf8.RuneSelf {
|
||||
size = 1
|
||||
} else if r, size = utf8.DecodeRune(src[nSrc:]); size == 1 && !atEOF && !utf8.FullRune(src[nSrc:]) {
|
||||
|
|
@ -355,7 +357,7 @@ func (t sanitizer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err e
|
|||
err = transform.ErrShortDst
|
||||
break
|
||||
}
|
||||
for i := 0; i < size; i++ {
|
||||
for range size {
|
||||
dst[nDst] = src[nSrc]
|
||||
nDst++
|
||||
nSrc++
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ import (
|
|||
)
|
||||
|
||||
type EditOptions struct {
|
||||
shared.Editable
|
||||
|
||||
HttpClient func() (*http.Client, error)
|
||||
IO *iostreams.IOStreams
|
||||
|
||||
|
|
@ -35,8 +37,6 @@ type EditOptions struct {
|
|||
|
||||
SelectorArg string
|
||||
Interactive bool
|
||||
|
||||
shared.Editable
|
||||
}
|
||||
|
||||
func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Command {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,6 @@ func TestPRRevert_acceptedIdentifierFormats(t *testing.T) {
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
http := &httpmock.Registry{}
|
||||
defer http.Verify(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -164,5 +164,4 @@ func TestPrCheckStatusSummaryWithColor(t *testing.T) {
|
|||
out := PrCheckStatusSummaryWithColor(cs, testCase.args)
|
||||
assert.Equal(t, testCase.want, out)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ type EditableSlice struct {
|
|||
// It contains a flag to indicate whether the assignees are actors or not.
|
||||
type EditableAssignees struct {
|
||||
EditableSlice
|
||||
|
||||
ActorAssignees bool
|
||||
DefaultLogins []string // For disambiguating actors from display names
|
||||
}
|
||||
|
|
@ -52,6 +53,7 @@ type EditableAssignees struct {
|
|||
// EditableReviewers is a special case of EditableSlice.
|
||||
type EditableReviewers struct {
|
||||
EditableSlice
|
||||
|
||||
DefaultLogins []string // For disambiguating actors from display names
|
||||
}
|
||||
|
||||
|
|
@ -59,6 +61,7 @@ type EditableReviewers struct {
|
|||
// Keep that map along with standard EditableSlice data.
|
||||
type EditableProjects struct {
|
||||
EditableSlice
|
||||
|
||||
ProjectItems map[string]string
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -484,7 +484,6 @@ func TestTryDetermineDefaultPRHead(t *testing.T) {
|
|||
require.Equal(t, "feature-branch", defaultPRHead.BranchName)
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func dummyRemotesFn() (ghContext.Remotes, error) {
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import (
|
|||
var _ GitConfigClient = &CachedBranchConfigGitConfigClient{}
|
||||
|
||||
type CachedBranchConfigGitConfigClient struct {
|
||||
CachedBranchConfig git.BranchConfig
|
||||
GitConfigClient
|
||||
CachedBranchConfig git.BranchConfig
|
||||
}
|
||||
|
||||
func (c CachedBranchConfigGitConfigClient) ReadBranchConfig(ctx context.Context, branchName string) (git.BranchConfig, error) {
|
||||
|
|
|
|||
|
|
@ -167,7 +167,6 @@ func (m *mockLister) List(opt ListOptions) (*api.PullRequestAndTotalCount, error
|
|||
}
|
||||
|
||||
if m.expectFields != nil {
|
||||
|
||||
if !isEqualSet(m.expectFields, opt.Fields) {
|
||||
return nil, fmt.Errorf("unexpected fields: %v", opt.Fields)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ const (
|
|||
EditCommitMessageAction
|
||||
EditCommitSubjectAction
|
||||
SubmitDraftAction
|
||||
)
|
||||
|
||||
const (
|
||||
noMilestone = "(none)"
|
||||
|
||||
submitLabel = "Submit"
|
||||
|
|
@ -35,14 +37,7 @@ const (
|
|||
cancelLabel = "Cancel"
|
||||
)
|
||||
|
||||
type Prompt interface {
|
||||
Input(prompt string, defaultValue string) (string, error)
|
||||
Select(prompt string, defaultValue string, options []string) (int, error)
|
||||
MarkdownEditor(prompt string, defaultValue string, blankAllowed bool) (string, error)
|
||||
Confirm(prompt string, defaultValue bool) (bool, error)
|
||||
MultiSelect(prompt string, defaults []string, options []string) ([]int, error)
|
||||
MultiSelectWithSearch(prompt, searchPrompt string, defaults []string, persistentOptions []string, searchFunc func(string) prompter.MultiSelectSearchResult) ([]string, error)
|
||||
}
|
||||
type Prompt = EditPrompter
|
||||
|
||||
func ConfirmIssueSubmission(p Prompt, allowPreview bool, allowMetadata bool) (Action, error) {
|
||||
return confirmSubmission(p, allowPreview, allowMetadata, false, false)
|
||||
|
|
|
|||
|
|
@ -189,9 +189,9 @@ func (m *templateManager) Choose() (Template, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
names := make([]string, len(m.templates))
|
||||
for i, t := range m.templates {
|
||||
names[i] = t.Name()
|
||||
names := make([]string, 0, len(m.templates))
|
||||
for _, t := range m.templates {
|
||||
names = append(names, t.Name())
|
||||
}
|
||||
|
||||
blankOption := "Open a blank issue"
|
||||
|
|
|
|||
|
|
@ -298,7 +298,6 @@ func printPrs(io *iostreams.IOStreams, totalCount int, prs ...api.PullRequest) {
|
|||
if pr.AutoMergeRequest != nil {
|
||||
fmt.Fprintf(w, " %s", cs.Green("✓ Auto-merge enabled"))
|
||||
}
|
||||
|
||||
} else {
|
||||
fmt.Fprintf(w, " - %s", shared.StateTitleWithColor(cs, pr))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue