Skip to content

Commit 45c8002

Browse files
committed
chore: golangci-lint linting fixes
1 parent b198910 commit 45c8002

29 files changed

+81
-282
lines changed

attr.go

Lines changed: 0 additions & 112 deletions
This file was deleted.

cli/clidisplay/resources.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func WorkspaceTags(writer io.Writer, tags types.TagBlocks) hcl.Diagnostics {
3131
tableWriter.AppendRow(table.Row{k, v, ""})
3232
continue
3333
// diags = diags.Extend(tDiags)
34-
//if !diags.HasErrors() {
34+
// if !diags.HasErrors() {
3535
// tableWriter.AppendRow(table.Row{k, v, ""})
3636
// continue
3737
//}
@@ -42,11 +42,11 @@ func WorkspaceTags(writer io.Writer, tags types.TagBlocks) hcl.Diagnostics {
4242
tableWriter.AppendRow(table.Row{k, "??", strings.Join(refs, "\n")})
4343

4444
// refs := tb.AllReferences()
45-
//refsStr := make([]string, 0, len(refs))
46-
//for _, ref := range refs {
45+
// refsStr := make([]string, 0, len(refs))
46+
// for _, ref := range refs {
4747
// refsStr = append(refsStr, ref.String())
4848
//}
49-
//tableWriter.AppendRow(table.Row{unknown, "???", strings.Join(refsStr, "\n")})
49+
// tableWriter.AppendRow(table.Row{unknown, "???", strings.Join(refsStr, "\n")})
5050
}
5151
}
5252
_, _ = fmt.Fprintln(writer, tableWriter.Render())
@@ -68,13 +68,13 @@ func Parameters(writer io.Writer, params []types.Parameter, files map[string]*hc
6868
}
6969
// value := p.Value.Value
7070
//
71-
//if value.IsNull() {
71+
// if value.IsNull() {
7272
// strVal = "null"
73-
//} else if !p.Value.Value.IsKnown() {
73+
// } else if !p.Value.Value.IsKnown() {
7474
// strVal = "unknown"
75-
//} else if value.Type().Equals(cty.String) {
75+
// } else if value.Type().Equals(cty.String) {
7676
// strVal = value.AsString()
77-
//} else {
77+
// } else {
7878
// strVal = value.GoString()
7979
//}
8080

@@ -86,7 +86,6 @@ func Parameters(writer io.Writer, params []types.Parameter, files map[string]*hc
8686
var out bytes.Buffer
8787
WriteDiagnostics(&out, files, hcl.Diagnostics(p.Diagnostics))
8888
tableWriter.AppendRow(table.Row{out.String()})
89-
9089
}
9190

9291
tableWriter.AppendSeparator()
@@ -100,29 +99,29 @@ func formatOptions(selected []string, options []*types.ParameterOption) string {
10099
found := false
101100

102101
for _, opt := range options {
103-
str.WriteString(sep)
102+
_, _ = str.WriteString(sep)
104103
prefix := "[ ]"
105104
if slices.Contains(selected, opt.Value.AsString()) {
106105
prefix = "[X]"
107106
found = true
108107
}
109108

110-
str.WriteString(fmt.Sprintf("%s %s (%s)", prefix, opt.Name, opt.Value.AsString()))
109+
_, _ = str.WriteString(fmt.Sprintf("%s %s (%s)", prefix, opt.Name, opt.Value.AsString()))
111110
if opt.Description != "" {
112-
str.WriteString(fmt.Sprintf("\n %s", maxLength(opt.Description, 25)))
111+
_, _ = str.WriteString(fmt.Sprintf("\n %s", maxLength(opt.Description, 25)))
113112
}
114113
sep = "\n"
115114
}
116115
if !found {
117-
str.WriteString(sep)
118-
str.WriteString(fmt.Sprintf("= %s", selected))
116+
_, _ = str.WriteString(sep)
117+
_, _ = str.WriteString(fmt.Sprintf("= %s", selected))
119118
}
120119
return str.String()
121120
}
122121

123-
func maxLength(s string, max int) string {
124-
if len(s) > max {
125-
return s[:max] + "..."
122+
func maxLength(s string, m int) string {
123+
if len(s) > m {
124+
return s[:m] + "..."
126125
}
127126
return s
128127
}

cli/env.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/coder/serpent"
1111
)
1212

13-
func (r *RootCmd) SetEnv() *serpent.Command {
13+
func (*RootCmd) SetEnv() *serpent.Command {
1414
var (
1515
vars []string
1616
groups []string
@@ -38,7 +38,7 @@ func (r *RootCmd) SetEnv() *serpent.Command {
3838
},
3939
},
4040
Hidden: false,
41-
Handler: func(i *serpent.Invocation) error {
41+
Handler: func(_ *serpent.Invocation) error {
4242
for _, val := range vars {
4343
parts := strings.Split(val, "=")
4444
if len(parts) != 2 {
@@ -49,7 +49,7 @@ func (r *RootCmd) SetEnv() *serpent.Command {
4949
if err != nil {
5050
return err
5151
}
52-
fmt.Println("CODER_PARAMETER_" + hex.EncodeToString(sum[:]) + "=" + parts[1])
52+
_, _ = fmt.Println("CODER_PARAMETER_" + hex.EncodeToString(sum[:]) + "=" + parts[1])
5353
}
5454

5555
return nil

cli/plan.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/coder/serpent"
1111
)
1212

13-
func (r *RootCmd) TerraformPlan() *serpent.Command {
13+
func (*RootCmd) TerraformPlan() *serpent.Command {
1414
cmd := &serpent.Command{
1515
Use: "plan",
1616
Short: "Runs `terraform init -upgrade` and `terraform plan`, saving the output.",
@@ -54,6 +54,7 @@ func (r *RootCmd) TerraformPlan() *serpent.Command {
5454

5555
var indented bytes.Buffer
5656
_ = json.Indent(&indented, buf.Bytes(), "", " ")
57+
//nolint:gosec
5758
_ = os.WriteFile("plan.json", indented.Bytes(), 0644)
5859
return nil
5960
},

cli/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ func (r *RootCmd) Root() *serpent.Command {
106106
clidisplay.Parameters(os.Stdout, output.Parameters, output.Files)
107107

108108
if !output.ModuleOutput.IsNull() && !(output.ModuleOutput.Type().IsObjectType() && output.ModuleOutput.LengthInt() == 0) {
109-
fmt.Println("Module output")
109+
_, _ = fmt.Println("Module output")
110110
data, _ := ctyjson.Marshal(output.ModuleOutput, output.ModuleOutput.Type())
111111
var buf bytes.Buffer
112112
_ = json.Indent(&buf, data, "", " ")
113-
fmt.Println(buf.String())
113+
_, _ = fmt.Println(buf.String())
114114
}
115115

116116
return nil
@@ -122,6 +122,7 @@ func (r *RootCmd) Root() *serpent.Command {
122122
return cmd
123123
}
124124

125+
//nolint:unused
125126
func hclExpr(expr string) hcl.Expression {
126127
file, diags := hclsyntax.ParseConfig([]byte(fmt.Sprintf(`expr = %s`, expr)), "test.tf", hcl.InitialPos)
127128
if diags.HasErrors() {

cli/static/index.html

Lines changed: 0 additions & 55 deletions
This file was deleted.

cli/web.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cli
33
import (
44
"bufio"
55
"context"
6-
"embed"
76
"encoding/json"
87
"fmt"
98
"io/fs"
@@ -13,6 +12,7 @@ import (
1312
"os/exec"
1413
"path/filepath"
1514
"slices"
15+
"time"
1616

1717
"github.com/go-chi/chi"
1818

@@ -24,13 +24,9 @@ import (
2424
"github.com/coder/websocket"
2525
)
2626

27-
//go:embed static/*
28-
var static embed.FS
29-
3027
type responseRecorder struct {
3128
http.ResponseWriter
32-
headerWritten bool
33-
logger slog.Logger
29+
logger slog.Logger
3430
}
3531

3632
// Implement Hijacker interface for WebSocket support
@@ -54,7 +50,7 @@ func debugMiddleware(logger slog.Logger) func(http.Handler) http.Handler {
5450
}
5551
}
5652

57-
func (r *RootCmd) WebsocketServer() *serpent.Command {
53+
func (*RootCmd) WebsocketServer() *serpent.Command {
5854
var (
5955
address string
6056
siteDir string
@@ -132,7 +128,7 @@ func (r *RootCmd) WebsocketServer() *serpent.Command {
132128
}
133129
_ = json.NewEncoder(rw).Encode(availableUsers)
134130
})
135-
mux.HandleFunc("/directories", func(rw http.ResponseWriter, r *http.Request) {
131+
mux.HandleFunc("/directories", func(rw http.ResponseWriter, _ *http.Request) {
136132
entries, err := fs.ReadDir(dataDirFS, ".")
137133
if err != nil {
138134
http.Error(rw, "Could not read directory", http.StatusInternalServerError)
@@ -163,9 +159,10 @@ func (r *RootCmd) WebsocketServer() *serpent.Command {
163159
srv := &http.Server{
164160
Addr: address,
165161
Handler: mux,
166-
BaseContext: func(listener net.Listener) context.Context {
162+
BaseContext: func(_ net.Listener) context.Context {
167163
return ctx
168164
},
165+
ReadHeaderTimeout: time.Second * 30,
169166
}
170167

171168
if siteDir != "" {
@@ -184,7 +181,6 @@ func (r *RootCmd) WebsocketServer() *serpent.Command {
184181
// Kill the server if pnpm exits
185182
_ = srv.Shutdown(ctx)
186183
}()
187-
188184
}
189185

190186
logger.Info(ctx, "Starting server", slog.F("address", address))
@@ -197,7 +193,6 @@ func (r *RootCmd) WebsocketServer() *serpent.Command {
197193

198194
func websocketHandler(logger slog.Logger, dirFS fs.FS) func(rw http.ResponseWriter, r *http.Request) {
199195
return func(rw http.ResponseWriter, r *http.Request) {
200-
201196
logger.Debug(r.Context(), "WebSocket connection attempt",
202197
slog.F("remote_addr", r.RemoteAddr),
203198
slog.F("path", r.URL.Path),

0 commit comments

Comments
 (0)