Skip to content

Commit c2a7119

Browse files
committed
Fix linting errors
1 parent 4fa89d4 commit c2a7119

File tree

14 files changed

+50
-57
lines changed

14 files changed

+50
-57
lines changed

cli/cliui/job.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func Job(cmd *cobra.Command, opts JobOptions) (codersdk.ProvisionerJob, error) {
3030
completed = false
3131
job codersdk.ProvisionerJob
3232
)
33-
_, _ = fmt.Fprintln(cmd.OutOrStdout(), fmt.Sprintf("%s%s %s", Styles.FocusedPrompt, opts.Title, Styles.Placeholder.Render("(ctrl+c to cancel)")))
33+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s%s %s\n", Styles.FocusedPrompt, opts.Title, Styles.Placeholder.Render("(ctrl+c to cancel)"))
3434

3535
spin.Writer = cmd.OutOrStdout()
3636
defer spin.Stop()
@@ -46,7 +46,7 @@ func Job(cmd *cobra.Command, opts JobOptions) (codersdk.ProvisionerJob, error) {
4646

4747
if !started && job.StartedAt != nil {
4848
spin.Stop()
49-
fmt.Fprintf(cmd.OutOrStdout(), Styles.Prompt.String()+"Started "+Styles.Placeholder.Render("[%dms]")+"\n", job.StartedAt.Sub(job.CreatedAt).Milliseconds())
49+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Styles.Prompt.String()+"Started "+Styles.Placeholder.Render("[%dms]")+"\n", job.StartedAt.Sub(job.CreatedAt).Milliseconds())
5050
spin.Start()
5151
started = true
5252
}
@@ -65,7 +65,7 @@ func Job(cmd *cobra.Command, opts JobOptions) (codersdk.ProvisionerJob, error) {
6565
if job.StartedAt != nil {
6666
started = *job.StartedAt
6767
}
68-
fmt.Fprintf(cmd.OutOrStderr(), Styles.Prompt.String()+msg+" "+Styles.Placeholder.Render("[%dms]")+"\n", job.CompletedAt.Sub(started).Milliseconds())
68+
_, _ = fmt.Fprintf(cmd.OutOrStderr(), Styles.Prompt.String()+msg+" "+Styles.Placeholder.Render("[%dms]")+"\n", job.CompletedAt.Sub(started).Milliseconds())
6969
spin.Start()
7070
completed = true
7171
}
@@ -95,11 +95,11 @@ func Job(cmd *cobra.Command, opts JobOptions) (codersdk.ProvisionerJob, error) {
9595
}
9696
}
9797
spin.Stop()
98-
fmt.Fprintf(cmd.OutOrStdout(), Styles.FocusedPrompt.String()+"Gracefully canceling... wait for exit or data loss may occur!\n")
98+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Styles.FocusedPrompt.String()+"Gracefully canceling... wait for exit or data loss may occur!\n")
9999
spin.Start()
100100
err := opts.Cancel()
101101
if err != nil {
102-
fmt.Fprintf(cmd.OutOrStdout(), "Failed to cancel %s...\n", err)
102+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Failed to cancel %s...\n", err)
103103
}
104104
refresh()
105105
}()
@@ -143,7 +143,7 @@ func Job(cmd *cobra.Command, opts JobOptions) (codersdk.ProvisionerJob, error) {
143143
case database.LogLevelInfo:
144144
style = defaultStyles.Note
145145
}
146-
fmt.Fprintln(cmd.OutOrStdout(), fmt.Sprintf("%s %s %s", Styles.Placeholder.Render("|"), style.Render(string(log.Level)), log.Output))
146+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s %s %s\n", Styles.Placeholder.Render("|"), style.Render(string(log.Level)), log.Output)
147147
spin.Start()
148148
}
149149
}

cli/cliui/parameter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ func ParameterSchema(cmd *cobra.Command, parameterSchema codersdk.ProjectVersion
2727
var value string
2828
if len(options) > 0 {
2929
// Move the cursor up a single line for nicer display!
30-
fmt.Fprint(cmd.OutOrStdout(), "\033[1A")
30+
_, _ = fmt.Fprint(cmd.OutOrStdout(), "\033[1A")
3131
value, err = Select(cmd, SelectOptions{
3232
Options: options,
3333
HideSearch: true,
3434
})
3535
if err == nil {
36-
fmt.Fprintln(cmd.OutOrStdout())
37-
fmt.Fprintln(cmd.OutOrStdout(), " "+Styles.Prompt.String()+Styles.Field.Render(value))
36+
_, _ = fmt.Fprintln(cmd.OutOrStdout())
37+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+Styles.Prompt.String()+Styles.Field.Render(value))
3838
}
3939
} else {
4040
value, err = Prompt(cmd, PromptOptions{

cli/cliui/prompt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
8484
return "", cmd.Context().Err()
8585
case <-interrupt:
8686
// Print a newline so that any further output starts properly on a new line.
87-
fmt.Fprintln(cmd.OutOrStdout())
87+
_, _ = fmt.Fprintln(cmd.OutOrStdout())
8888
return "", Canceled
8989
}
9090
}

cli/cliui/select.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cliui
22

33
import (
44
"errors"
5-
"fmt"
65
"io"
76
"strings"
87
"text/template"
@@ -50,7 +49,7 @@ func Select(cmd *cobra.Command, opts SelectOptions) (string, error) {
5049
Inactive: " {{ . }}",
5150
Label: "{{.}}",
5251
Selected: "{{ \"\" }}",
53-
Help: fmt.Sprintf(`{{ "Use" | faint }} {{ .SearchKey | faint }} {{ "to toggle search" | faint }}`),
52+
Help: `{{ "Use" | faint }} {{ .SearchKey | faint }} {{ "to toggle search" | faint }}`,
5453
},
5554
HideSelected: true,
5655
}
@@ -69,6 +68,6 @@ type writeCloser struct {
6968
io.Writer
7069
}
7170

72-
func (w *writeCloser) Close() error {
71+
func (*writeCloser) Close() error {
7372
return nil
7473
}

cli/projectcreate.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func projectCreate() *cobra.Command {
9898
return err
9999
}
100100

101-
_, _ = fmt.Fprintln(cmd.OutOrStdout(), fmt.Sprintf("The %s project has been created!", projectName))
101+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "The %s project has been created!\n", projectName)
102102
return nil
103103
},
104104
}
@@ -172,11 +172,7 @@ func createValidProjectVersion(cmd *cobra.Command, client *codersdk.Client, orga
172172
missingSchemas = append(missingSchemas, parameterSchema)
173173
}
174174
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Paragraph.Render("This project has required variables! They are scoped to the project, and not viewable after being set.")+"\r\n")
175-
for _, parameterSchema := range parameterSchemas {
176-
_, ok := valuesBySchemaID[parameterSchema.ID.String()]
177-
if ok {
178-
continue
179-
}
175+
for _, parameterSchema := range missingSchemas {
180176
value, err := cliui.ParameterSchema(cmd, parameterSchema)
181177
if err != nil {
182178
return nil, nil, err
@@ -202,5 +198,5 @@ func createValidProjectVersion(cmd *cobra.Command, client *codersdk.Client, orga
202198
if err != nil {
203199
return nil, nil, err
204200
}
205-
return &version, parameters, displayProjectVersionInfo(cmd, parameterSchemas, parameterValues, resources)
201+
return &version, parameters, displayProjectVersionInfo(cmd, resources)
206202
}

cli/projectcreate_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package cli_test
33
import (
44
"testing"
55

6+
"github.com/stretchr/testify/require"
7+
68
"github.com/coder/coder/cli/clitest"
79
"github.com/coder/coder/coderd/coderdtest"
810
"github.com/coder/coder/database"
911
"github.com/coder/coder/provisioner/echo"
1012
"github.com/coder/coder/pty/ptytest"
11-
"github.com/stretchr/testify/require"
1213
)
1314

1415
func TestProjectCreate(t *testing.T) {

cli/projectinit.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
"os"
66
"path/filepath"
77

8+
"github.com/spf13/cobra"
9+
810
"github.com/coder/coder/cli/cliui"
911
"github.com/coder/coder/examples"
1012
"github.com/coder/coder/provisionersdk"
11-
"github.com/spf13/cobra"
1213
)
1314

1415
func projectInit() *cobra.Command {

cli/projectinit_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"os"
55
"testing"
66

7+
"github.com/stretchr/testify/require"
8+
79
"github.com/coder/coder/cli/clitest"
810
"github.com/coder/coder/pty/ptytest"
9-
"github.com/stretchr/testify/require"
1011
)
1112

1213
func TestProjectInit(t *testing.T) {

cli/projects.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ func projects() *cobra.Command {
4242
return cmd
4343
}
4444

45-
func displayProjectVersionInfo(cmd *cobra.Command, parameterSchemas []codersdk.ProjectVersionParameterSchema, parameterValues []codersdk.ProjectVersionParameter, resources []codersdk.WorkspaceResource) error {
46-
schemaByID := map[string]codersdk.ProjectVersionParameterSchema{}
47-
for _, schema := range parameterSchemas {
48-
schemaByID[schema.ID.String()] = schema
49-
}
45+
func displayProjectVersionInfo(cmd *cobra.Command, resources []codersdk.WorkspaceResource) error {
5046
sort.Slice(resources, func(i, j int) bool {
5147
return fmt.Sprintf("%s.%s", resources[i].Type, resources[i].Name) < fmt.Sprintf("%s.%s", resources[j].Type, resources[j].Name)
5248
})
@@ -81,7 +77,7 @@ func displayProjectVersionInfo(cmd *cobra.Command, parameterSchemas []codersdk.P
8177
if resource.Agent != nil {
8278
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+cliui.Styles.Fuschia.Render("▲ allows ssh"))
8379
}
84-
fmt.Fprintln(cmd.OutOrStdout())
80+
_, _ = fmt.Fprintln(cmd.OutOrStdout())
8581
}
8682
return nil
8783
}

cli/start_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import (
1515
func TestStart(t *testing.T) {
1616
t.Parallel()
1717
t.Run("Production", func(t *testing.T) {
18+
t.Parallel()
1819
ctx, cancelFunc := context.WithCancel(context.Background())
1920
go cancelFunc()
2021
root, _ := clitest.New(t, "start", "--address", ":0")
2122
err := root.ExecuteContext(ctx)
2223
require.ErrorIs(t, err, context.Canceled)
2324
})
2425
t.Run("Development", func(t *testing.T) {
26+
t.Parallel()
2527
ctx, cancelFunc := context.WithCancel(context.Background())
2628
defer cancelFunc()
2729
root, cfg := clitest.New(t, "start", "--dev", "--tunnel=false", "--address", ":0")

cli/workspacecreate.go

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ func workspaceCreate() *cobra.Command {
7171
}
7272
}
7373

74-
fmt.Fprintln(cmd.OutOrStdout())
75-
fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Prompt.String()+"Creating with the "+cliui.Styles.Field.Render(project.Name)+" project...")
74+
_, _ = fmt.Fprintln(cmd.OutOrStdout())
75+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Prompt.String()+"Creating with the "+cliui.Styles.Field.Render(project.Name)+" project...")
7676

7777
workspaceName := args[0]
7878
_, err = client.WorkspaceByName(cmd.Context(), "", workspaceName)
@@ -96,7 +96,7 @@ func workspaceCreate() *cobra.Command {
9696
continue
9797
}
9898
if !printed {
99-
fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Paragraph.Render("This project has customizable parameters! These can be changed after create, but may have unintended side effects (like data loss).")+"\r\n")
99+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Paragraph.Render("This project has customizable parameters! These can be changed after create, but may have unintended side effects (like data loss).")+"\r\n")
100100
printed = true
101101
}
102102

@@ -112,20 +112,15 @@ func workspaceCreate() *cobra.Command {
112112
})
113113
}
114114
if printed {
115-
fmt.Fprintln(cmd.OutOrStdout())
116-
fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.FocusedPrompt.String()+"Previewing resources...")
117-
fmt.Fprintln(cmd.OutOrStdout())
118-
}
119-
120-
parameterValues, err := client.ProjectVersionParameters(cmd.Context(), projectVersion.ID)
121-
if err != nil {
122-
return err
115+
_, _ = fmt.Fprintln(cmd.OutOrStdout())
116+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.FocusedPrompt.String()+"Previewing resources...")
117+
_, _ = fmt.Fprintln(cmd.OutOrStdout())
123118
}
124119
resources, err := client.ProjectVersionResources(cmd.Context(), projectVersion.ID)
125120
if err != nil {
126121
return err
127122
}
128-
err = displayProjectVersionInfo(cmd, parameterSchemas, parameterValues, resources)
123+
err = displayProjectVersionInfo(cmd, resources)
129124
if err != nil {
130125
return err
131126
}
@@ -171,15 +166,15 @@ func workspaceCreate() *cobra.Command {
171166
if err != nil {
172167
return err
173168
}
169+
spin := spinner.New(spinner.CharSets[5], 100*time.Millisecond, spinner.WithColor("fgGreen"))
170+
spin.Writer = cmd.OutOrStdout()
171+
spin.Suffix = " Waiting for agent to connect..."
172+
spin.Start()
173+
defer spin.Stop()
174174
for _, resource := range resources {
175175
if resource.Agent == nil {
176176
continue
177177
}
178-
spin := spinner.New(spinner.CharSets[5], 100*time.Millisecond, spinner.WithColor("fgGreen"))
179-
spin.Writer = cmd.OutOrStdout()
180-
spin.Suffix = " Waiting for agent to connect..."
181-
spin.Start()
182-
defer spin.Stop()
183178
ticker := time.NewTicker(1 * time.Second)
184179
for {
185180
select {
@@ -195,11 +190,9 @@ func workspaceCreate() *cobra.Command {
195190
continue
196191
}
197192
spin.Stop()
198-
fmt.Fprintln(cmd.OutOrStdout())
199-
fmt.Fprintln(cmd.OutOrStdout(), fmt.Sprintf("The %s workspace has been created!", cliui.Styles.Keyword.Render(workspace.Name)))
200-
fmt.Fprintln(cmd.OutOrStdout())
201-
fmt.Fprintln(cmd.OutOrStdout(), " "+cliui.Styles.Code.Render("coder ssh "+workspace.Name))
202-
fmt.Fprintln(cmd.OutOrStdout())
193+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nThe %s workspace has been created!\n\n", cliui.Styles.Keyword.Render(workspace.Name))
194+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+cliui.Styles.Code.Render("coder ssh "+workspace.Name))
195+
_, _ = fmt.Fprintln(cmd.OutOrStdout())
203196
break
204197
}
205198
}

cli/workspacelist.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
"text/tabwriter"
66
"time"
77

8-
"github.com/coder/coder/cli/cliui"
98
"github.com/fatih/color"
109
"github.com/spf13/cobra"
10+
11+
"github.com/coder/coder/cli/cliui"
1112
)
1213

1314
func workspaceList() *cobra.Command {

cmd/templater/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func parse(cmd *cobra.Command, parameters []codersdk.CreateParameterRequest) err
159159
return xerrors.Errorf("Job wasn't successful, it was %q. Check the logs!", version.Job.Status)
160160
}
161161

162-
resources, err := client.ProjectVersionResources(cmd.Context(), version.ID)
162+
_, err = client.ProjectVersionResources(cmd.Context(), version.ID)
163163
if err != nil {
164164
return err
165165
}
@@ -191,7 +191,7 @@ func parse(cmd *cobra.Command, parameters []codersdk.CreateParameterRequest) err
191191
_, _ = fmt.Printf("terraform (%s): %s\n", log.Level, log.Output)
192192
}
193193

194-
resources, err = client.WorkspaceResourcesByBuild(cmd.Context(), workspace.LatestBuild.ID)
194+
resources, err := client.WorkspaceResourcesByBuild(cmd.Context(), workspace.LatestBuild.ID)
195195
if err != nil {
196196
return err
197197
}

provisionersdk/archive.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func Untar(directory string, archive []byte) error {
7272
if err != nil {
7373
return err
7474
}
75+
// #nosec
7576
target := filepath.Join(directory, header.Name)
7677
switch header.Typeflag {
7778
case tar.TypeDir:
@@ -81,14 +82,16 @@ func Untar(directory string, archive []byte) error {
8182
}
8283
}
8384
case tar.TypeReg:
84-
f, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
85+
file, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
8586
if err != nil {
8687
return err
8788
}
88-
if _, err := io.Copy(f, reader); err != nil {
89+
// Max file size of 10MB.
90+
_, err = io.CopyN(file, reader, (1<<20)*10)
91+
if err != nil {
8992
return err
9093
}
91-
_ = f.Close()
94+
_ = file.Close()
9295
}
9396
}
9497
}

0 commit comments

Comments
 (0)