diff --git a/.gitignore b/.gitignore index 31c27ed97..5ef399ba7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ # VS Code .vscode +# IntelliJ +.idea + # macOS .DS_Store diff --git a/api/queries_repo.go b/api/queries_repo.go index 9d0c4f00d..14c839e9a 100644 --- a/api/queries_repo.go +++ b/api/queries_repo.go @@ -97,7 +97,7 @@ type RepoNetworkResult struct { // RepoNetwork inspects the relationship between multiple GitHub repositories func RepoNetwork(client *Client, repos []ghrepo.Interface) (RepoNetworkResult, error) { - queries := []string{} + queries := make([]string, 0, len(repos)) for i, repo := range repos { queries = append(queries, fmt.Sprintf(` repo_%03d: repository(owner: %q, name: %q) { @@ -150,7 +150,7 @@ func RepoNetwork(client *Client, repos []ghrepo.Interface) (RepoNetworkResult, e return result, err } - keys := []string{} + keys := make([]string, 0, len(graphqlResult)) for key := range graphqlResult { keys = append(keys, key) } diff --git a/command/issue.go b/command/issue.go index 686baaa99..1565b776c 100644 --- a/command/issue.go +++ b/command/issue.go @@ -429,7 +429,7 @@ func labelList(issue api.Issue) string { return "" } - labelNames := []string{} + labelNames := make([]string, 0, len(issue.Labels.Nodes)) for _, label := range issue.Labels.Nodes { labelNames = append(labelNames, label.Name) } diff --git a/command/pr_checkout.go b/command/pr_checkout.go index 43556c67f..b1f21e361 100644 --- a/command/pr_checkout.go +++ b/command/pr_checkout.go @@ -38,8 +38,7 @@ func prCheckout(cmd *cobra.Command, args []string) error { headRemote, _ = remotes.FindByRepo(pr.HeadRepositoryOwner.Login, pr.HeadRepository.Name) } - cmdQueue := [][]string{} - + cmdQueue := make([][]string, 0, 4) newBranchName := pr.HeadRefName if headRemote != nil { // there is an existing git remote for PR head diff --git a/command/root.go b/command/root.go index 5130f74c9..529b3165b 100644 --- a/command/root.go +++ b/command/root.go @@ -97,7 +97,7 @@ var initContext = func() context.Context { // BasicClient returns an API client that borrows from but does not depend on // user configuration func BasicClient() (*api.Client, error) { - opts := []api.ClientOption{} + opts := make([]api.ClientOption, 0, 1) if verbose := os.Getenv("DEBUG"); verbose != "" { opts = append(opts, apiVerboseLog()) } @@ -122,7 +122,7 @@ var apiClientForContext = func(ctx context.Context) (*api.Client, error) { if err != nil { return nil, err } - opts := []api.ClientOption{} + opts := make([]api.ClientOption, 0, 4) if verbose := os.Getenv("DEBUG"); verbose != "" { opts = append(opts, apiVerboseLog()) } diff --git a/command/title_body_survey.go b/command/title_body_survey.go index fa34384af..67473eb49 100644 --- a/command/title_body_survey.go +++ b/command/title_body_survey.go @@ -54,7 +54,7 @@ func selectTemplate(templatePaths []string) (string, error) { Index int }{} if len(templatePaths) > 1 { - templateNames := []string{} + templateNames := make([]string, 0, len(templatePaths)) for _, p := range templatePaths { templateNames = append(templateNames, githubtemplate.ExtractName(p)) } @@ -110,7 +110,7 @@ func titleBodySurvey(cmd *cobra.Command, providedTitle string, providedBody stri }, } - qs := []*survey.Question{} + var qs = []*survey.Question{} if providedTitle == "" { qs = append(qs, titleQuestion) } diff --git a/context/context.go b/context/context.go index 385425958..af4dd65fb 100644 --- a/context/context.go +++ b/context/context.go @@ -38,7 +38,7 @@ func ResolveRemotesToRepos(remotes Remotes, client *api.Client, base string) (Re hasBaseOverride := base != "" baseOverride := ghrepo.FromFullName(base) foundBaseOverride := false - repos := []ghrepo.Interface{} + repos := make([]ghrepo.Interface, 0, lenRemotesForLookup) for _, r := range remotes[:lenRemotesForLookup] { repos = append(repos, r) if ghrepo.IsSame(r, baseOverride) { diff --git a/git/ssh_config.go b/git/ssh_config.go index 1ac5e828e..fe58f2dad 100644 --- a/git/ssh_config.go +++ b/git/ssh_config.go @@ -57,7 +57,7 @@ func ParseSSHConfig() SSHAliasMap { configFiles = append([]string{userConfig}, configFiles...) } - openFiles := []io.Reader{} + openFiles := make([]io.Reader, 0, len(configFiles)) for _, file := range configFiles { f, err := os.Open(file) if err != nil { diff --git a/internal/cobrafish/completion.go b/internal/cobrafish/completion.go index 5d70945f7..9fbe6946f 100644 --- a/internal/cobrafish/completion.go +++ b/internal/cobrafish/completion.go @@ -117,7 +117,7 @@ func flagRequiresArgumentCompletion(flag *pflag.Flag) string { } func subCommandPath(rootCmd *cobra.Command, cmd *cobra.Command) string { - path := []string{} + path := make([]string, 0, 1) currentCmd := cmd if rootCmd == cmd { return "" @@ -142,7 +142,7 @@ func rangeCommands(cmd *cobra.Command, callback func(subCmd *cobra.Command)) { func commandCompletionCondition(rootCmd, cmd *cobra.Command) string { localNonPersistentFlags := cmd.LocalNonPersistentFlags() - bareConditions := []string{} + bareConditions := make([]string, 0, 1) if rootCmd != cmd { bareConditions = append(bareConditions, fmt.Sprintf("__fish_%s_seen_subcommand_path %s", rootCmd.Name(), subCommandPath(rootCmd, cmd))) } else {