Skip to content

Commit e83a667

Browse files
author
TP Honey
authored
(maint) clean up linting issues (#77)
1 parent 83b778c commit e83a667

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+161
-161
lines changed

.golangci.yml

-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ linters:
5959
disable-all: true
6060
enable:
6161
- bodyclose
62-
- deadcode
6362
- depguard
6463
- dogsled
6564
- errcheck
@@ -86,13 +85,11 @@ linters:
8685
- revive
8786
- rowserrcheck
8887
- staticcheck
89-
- structcheck
9088
- stylecheck
9189
- typecheck
9290
- unconvert
9391
- unparam
9492
- unused
95-
- varcheck
9693
- whitespace
9794

9895
# don't enable:

cli/client/http.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,29 @@ type HTTPClient struct {
6464
func (c *HTTPClient) Setup(ctx context.Context, in *api.SetupRequest) (*api.SetupResponse, error) {
6565
path := "setup"
6666
out := new(api.SetupResponse)
67-
_, err := c.do(ctx, c.Endpoint+path, http.MethodPost, in, out) // nolint:bodyclose
67+
_, err := c.do(ctx, c.Endpoint+path, http.MethodPost, in, out) //nolint:bodyclose
6868
return out, err
6969
}
7070

7171
// Destroy will clean up the resources created
7272
func (c *HTTPClient) Destroy(ctx context.Context, in *api.DestroyRequest) (*api.DestroyResponse, error) {
7373
path := "destroy"
7474
out := new(api.DestroyResponse)
75-
_, err := c.do(ctx, c.Endpoint+path, http.MethodPost, in, out) // nolint:bodyclose
75+
_, err := c.do(ctx, c.Endpoint+path, http.MethodPost, in, out) //nolint:bodyclose
7676
return out, err
7777
}
7878

7979
func (c *HTTPClient) StartStep(ctx context.Context, in *api.StartStepRequest) (*api.StartStepResponse, error) {
8080
path := "start_step"
8181
out := new(api.StartStepResponse)
82-
_, err := c.do(ctx, c.Endpoint+path, http.MethodPost, in, out) // nolint:bodyclose
82+
_, err := c.do(ctx, c.Endpoint+path, http.MethodPost, in, out) //nolint:bodyclose
8383
return out, err
8484
}
8585

8686
func (c *HTTPClient) PollStep(ctx context.Context, in *api.PollStepRequest) (*api.PollStepResponse, error) {
8787
path := "poll_step"
8888
out := new(api.PollStepResponse)
89-
_, err := c.do(ctx, c.Endpoint+path, http.MethodPost, in, out) // nolint:bodyclose
89+
_, err := c.do(ctx, c.Endpoint+path, http.MethodPost, in, out) //nolint:bodyclose
9090
return out, err
9191
}
9292

@@ -107,7 +107,7 @@ func (c *HTTPClient) RetryPollStep(ctx context.Context, in *api.PollStepRequest,
107107
Trace("RetryPollStep: step completed")
108108
return step, pollError
109109
}
110-
time.Sleep(time.Millisecond * 10) // nolint:gomnd
110+
time.Sleep(time.Millisecond * 10) //nolint:gomnd
111111
}
112112
}
113113

@@ -151,7 +151,7 @@ func (c *HTTPClient) GetStepLogOutput(ctx context.Context, in *api.StreamOutputR
151151
func (c *HTTPClient) Health(ctx context.Context) (*api.HealthResponse, error) {
152152
path := "healthz"
153153
out := new(api.HealthResponse)
154-
_, err := c.do(ctx, c.Endpoint+path, http.MethodGet, nil, out) // nolint:bodyclose
154+
_, err := c.do(ctx, c.Endpoint+path, http.MethodGet, nil, out) //nolint:bodyclose
155155
return out, err
156156
}
157157

@@ -177,12 +177,12 @@ func (c *HTTPClient) RetryHealth(ctx context.Context, timeout time.Duration) (*a
177177
WithField("retry_num", i).WithError(err).Traceln("health check failed. Retrying")
178178
lastErr = err
179179
}
180-
time.Sleep(time.Millisecond * 100) // nolint:gomnd
180+
time.Sleep(time.Millisecond * 100) //nolint:gomnd
181181
}
182182
}
183183

184184
// do is a helper function that posts a http request with the input encoded and response decoded from json.
185-
func (c *HTTPClient) do(ctx context.Context, path, method string, in, out interface{}) (*http.Response, error) { // nolint:unparam
185+
func (c *HTTPClient) do(ctx context.Context, path, method string, in, out interface{}) (*http.Response, error) { //nolint:unparam
186186
var r io.Reader
187187

188188
if in != nil {
@@ -204,7 +204,7 @@ func (c *HTTPClient) do(ctx context.Context, path, method string, in, out interf
204204
defer func() {
205205
// drain the response body so we can reuse
206206
// this connection.
207-
if _, cerr := io.Copy(io.Discard, io.LimitReader(res.Body, 4096)); cerr != nil { // nolint:gomnd
207+
if _, cerr := io.Copy(io.Discard, io.LimitReader(res.Body, 4096)); cerr != nil { //nolint:gomnd
208208
logrus.WithError(cerr).Errorln("failed to drain response body")
209209
}
210210
res.Body.Close()
@@ -227,7 +227,7 @@ func (c *HTTPClient) do(ctx context.Context, path, method string, in, out interf
227227
return res, err
228228
}
229229

230-
if res.StatusCode > 299 { // nolint:gomnd
230+
if res.StatusCode > 299 { //nolint:gomnd
231231
// if the response body includes an error message
232232
// we should return the error string.
233233
if len(body) != 0 {

engine/docker/convert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func isBindMount(volume *spec.Volume) bool {
307307

308308
// returns true if the volume is in-memory.
309309
func isTempfs(volume *spec.Volume) bool {
310-
return volume.EmptyDir != nil && volume.EmptyDir.Medium == "memory" // nolint:goconst
310+
return volume.EmptyDir != nil && volume.EmptyDir.Medium == "memory" //nolint:goconst
311311
}
312312

313313
// returns true if the volume is a data-volume.

engine/docker/docker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (e *Docker) Run(ctx context.Context, pipelineConfig *spec.PipelineConfig, s
208208
// emulate docker commands
209209
//
210210

211-
func (e *Docker) create(ctx context.Context, pipelineConfig *spec.PipelineConfig, step *spec.Step, output io.Writer) error { // nolint:gocyclo
211+
func (e *Docker) create(ctx context.Context, pipelineConfig *spec.PipelineConfig, step *spec.Step, output io.Writer) error { //nolint:gocyclo
212212
// create pull options with encoded authorization credentials.
213213
pullopts := types.ImagePullOptions{}
214214
if step.Auth != nil {

engine/engine.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (e *Engine) Setup(ctx context.Context, pipelineConfig *spec.PipelineConfig)
5959
continue
6060
}
6161

62-
if err := os.MkdirAll(path, 0777); err != nil { // nolint:gomnd
62+
if err := os.MkdirAll(path, 0777); err != nil { //nolint:gomnd
6363
return errors.Wrap(err,
6464
fmt.Sprintf("failed to create directory for host volume path: %s", path))
6565
}

internal/docker/errors/errors_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515

1616
func TestTrimExtraInfo(t *testing.T) {
1717
const (
18-
before = `Error response from daemon: container encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra info: { "User":"ContainerUser" }` // nolint:lll
19-
after = `Error response from daemon: container encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified.` // nolint:lll
18+
before = `Error response from daemon: container encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra info: { "User":"ContainerUser" }` //nolint:lll
19+
after = `Error response from daemon: container encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified.` //nolint:lll
2020
)
2121
errBefore := errors.New(before)
2222
errAfter := TrimExtraInfo(errBefore)

internal/docker/jsonmessage/jsonmessage.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"encoding/json"
1313
"fmt"
1414
"io"
15+
"net/http"
1516
)
1617

1718
type jsonError struct {
@@ -46,7 +47,7 @@ func Copy(in io.Reader, out io.Writer) error {
4647
}
4748

4849
if jm.Error != nil {
49-
if jm.Error.Code == 401 { // nolint:gomnd
50+
if jm.Error.Code == http.StatusUnauthorized {
5051
return fmt.Errorf("authentication is required")
5152
}
5253
fmt.Fprintf(out, "%s\n", jm.Error)

internal/docker/stdcopy/stdcopy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func NewStdWriter(w io.Writer, t StdType) io.Writer {
106106
// In other words: if `err` is non nil, it indicates a real underlying error.
107107
//
108108
// `written` will hold the total number of bytes written to `dstout` and `dsterr`.
109-
func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) { // nolint:gocyclo
109+
func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) { //nolint:gocyclo
110110
var (
111111
buf = make([]byte, startingBufLen)
112112
bufLen = len(buf)
@@ -136,7 +136,7 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error)
136136
// Check the first byte to know where to write
137137
switch StdType(buf[stdWriterFdIndex]) {
138138
case Stdin:
139-
fallthrough // nolint:gocritic
139+
fallthrough //nolint:gocritic
140140
case Stdout:
141141
// Write on stdout
142142
out = dstout

livelog/livelog.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (b *Writer) Close() error {
169169
if b.stop() {
170170
// Flush anything waiting on a new line
171171
if len(b.prev) > 0 {
172-
b.Write([]byte("\n")) // nolint:errcheck
172+
b.Write([]byte("\n")) //nolint:errcheck
173173
}
174174
b.flush()
175175
}
@@ -277,7 +277,7 @@ func (b *Writer) Start() {
277277
func (b *Writer) checkErrInLogs() {
278278
size := len(b.history)
279279
// Check last 10 log lines for errors. TODO(Shubham): see if this can be made better
280-
for idx := max(0, size-10); idx < size; idx++ { // nolint:gomnd
280+
for idx := max(0, size-10); idx < size; idx++ { //nolint:gomnd
281281
line := b.history[idx]
282282
// Iterate over the nudges and see if we get a match
283283
for _, n := range b.nudges {
@@ -295,7 +295,7 @@ func (b *Writer) checkErrInLogs() {
295295

296296
// return back two byte arrays after splitting on last \n.
297297
// Eg: ABC\nDEF\nGH will return ABC\nDEF\n and GH
298-
func splitLast(p []byte) ([]byte, []byte) { // nolint:gocritic
298+
func splitLast(p []byte) ([]byte, []byte) { //nolint:gocritic
299299
if !bytes.Contains(p, []byte("\n")) {
300300
return p, []byte{} // If no \n is present, return the string itself
301301
}

livelog/livelog_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestLineWriterSingle(t *testing.T) {
1919
w := New(client, "1", "1", nil)
2020
w.SetInterval(time.Duration(0))
2121
w.num = 4
22-
w.Write([]byte("foo\nbar\n")) // nolint:errcheck
22+
_, _ = w.Write([]byte("foo\nbar\n"))
2323

2424
a := w.pending
2525
b := []*logstream.Line{

logstream/remote/http.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewHTTPClient(endpoint, accountID, token string, indirectUpload, skipverify
5353
Transport: &http.Transport{
5454
Proxy: http.ProxyFromEnvironment,
5555
TLSClientConfig: &tls.Config{
56-
InsecureSkipVerify: true, // nolint:gosec
56+
InsecureSkipVerify: true, //nolint:gosec
5757
},
5858
},
5959
}
@@ -129,39 +129,39 @@ func (c *HTTPClient) uploadToRemoteStorage(ctx context.Context, key string, r io
129129
func (c *HTTPClient) uploadLink(ctx context.Context, key string) (*Link, error) {
130130
path := fmt.Sprintf(uploadLinkEndpoint, c.AccountID, key)
131131
out := new(Link)
132-
backoff := createBackoff(60 * time.Second) // nolint:gomnd
133-
_, err := c.retry(ctx, c.Endpoint+path, "POST", nil, out, false, backoff) // nolint:bodyclose
132+
backoff := createBackoff(60 * time.Second) //nolint:gomnd
133+
_, err := c.retry(ctx, c.Endpoint+path, "POST", nil, out, false, backoff) //nolint:bodyclose
134134
return out, err
135135
}
136136

137137
// uploadUsingLink takes in a reader and a link object and uploads directly to
138138
// remote storage.
139139
func (c *HTTPClient) uploadUsingLink(ctx context.Context, link string, r io.Reader) error {
140-
backoff := createBackoff(60 * time.Second) // nolint:gomnd
141-
_, err := c.retry(ctx, link, "PUT", r, nil, true, backoff) // nolint:bodyclose
140+
backoff := createBackoff(60 * time.Second) //nolint:gomnd
141+
_, err := c.retry(ctx, link, "PUT", r, nil, true, backoff) //nolint:bodyclose
142142
return err
143143
}
144144

145145
// Open opens the data stream.
146146
func (c *HTTPClient) Open(ctx context.Context, key string) error {
147147
path := fmt.Sprintf(streamEndpoint, c.AccountID, key)
148-
backoff := createBackoff(10 * time.Second) // nolint:gomnd
149-
_, err := c.retry(ctx, c.Endpoint+path, "POST", nil, nil, false, backoff) // nolint:bodyclose
148+
backoff := createBackoff(10 * time.Second) //nolint:gomnd
149+
_, err := c.retry(ctx, c.Endpoint+path, "POST", nil, nil, false, backoff) //nolint:bodyclose
150150
return err
151151
}
152152

153153
// Close closes the data stream.
154154
func (c *HTTPClient) Close(ctx context.Context, key string) error {
155155
path := fmt.Sprintf(streamEndpoint, c.AccountID, key)
156-
_, err := c.do(ctx, c.Endpoint+path, "DELETE", nil, nil) // nolint:bodyclose
156+
_, err := c.do(ctx, c.Endpoint+path, "DELETE", nil, nil) //nolint:bodyclose
157157
return err
158158
}
159159

160160
// Write writes logs to the data stream.
161161
func (c *HTTPClient) Write(ctx context.Context, key string, lines []*logstream.Line) error {
162162
path := fmt.Sprintf(streamEndpoint, c.AccountID, key)
163163
l := convertLines(lines)
164-
_, err := c.do(ctx, c.Endpoint+path, "PUT", &l, nil) // nolint:bodyclose
164+
_, err := c.do(ctx, c.Endpoint+path, "PUT", &l, nil) //nolint:bodyclose
165165
return err
166166
}
167167

@@ -189,7 +189,7 @@ func (c *HTTPClient) retry(ctx context.Context, method, path string, in, out int
189189
// 5xx's are typically not permanent errors and may
190190
// relate to outages on the server side.
191191

192-
if res.StatusCode >= 500 { // nolint:gomnd
192+
if res.StatusCode >= 500 { //nolint:gomnd
193193
logrus.WithError(err).WithField("path", path).Warnln("http: log-service server error: reconnect and retry")
194194
if duration == backoff.Stop {
195195
return nil, err
@@ -236,7 +236,7 @@ func (c *HTTPClient) do(ctx context.Context, path, method string, in, out interf
236236
defer func() {
237237
// drain the response body so we can reuse
238238
// this connection.
239-
if _, cerr := io.Copy(io.Discard, io.LimitReader(res.Body, 4096)); cerr != nil { // nolint:gomnd
239+
if _, cerr := io.Copy(io.Discard, io.LimitReader(res.Body, 4096)); cerr != nil { //nolint:gomnd
240240
logrus.WithError(cerr).Errorln("failed to drain response body")
241241
}
242242
res.Body.Close()
@@ -249,7 +249,7 @@ func (c *HTTPClient) do(ctx context.Context, path, method string, in, out interf
249249
// if the response body return no content we exit
250250
// immediately. We do not read or unmarshal the response
251251
// and we do not return an error.
252-
if res.StatusCode == 204 { // nolint:gomnd
252+
if res.StatusCode == 204 { //nolint:gomnd
253253
return res, nil
254254
}
255255

@@ -259,7 +259,7 @@ func (c *HTTPClient) do(ctx context.Context, path, method string, in, out interf
259259
return res, err
260260
}
261261

262-
if res.StatusCode > 299 { // nolint:gomnd
262+
if res.StatusCode > 299 { //nolint:gomnd
263263
// if the response body includes an error message
264264
// we should return the error string.
265265
if len(body) != 0 {

logstream/replacer.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ func NewReplacer(w Writer, secrets []string) Writer {
2929
for _, part := range strings.Split(secret, "\n") {
3030
part = strings.TrimSpace(part)
3131

32-
// avoid masking empty or single character
33-
// strings.
34-
if len(part) < 2 { // nolint:gomnd
32+
// avoid masking empty or single character strings.
33+
if len(part) < 2 { //nolint:gomnd
3534
continue
3635
}
3736

logstream/replacer_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestReplace(t *testing.T) {
1313

1414
sw := &nopWriter{}
1515
w := NewReplacer(&nopCloser{sw}, secrets)
16-
w.Write([]byte("username octocat password correct-horse-batter-staple")) // nolint:errcheck
16+
_, _ = w.Write([]byte("username octocat password correct-horse-batter-staple"))
1717
w.Close()
1818

1919
if got, want := sw.data[0], "username octocat password **************"; got != want {
@@ -40,7 +40,7 @@ r9nicR5wDy2W
4040

4141
sw := &nopWriter{}
4242
w := NewReplacer(&nopCloser{sw}, secrets)
43-
w.Write([]byte(line)) // nolint:errcheck
43+
_, _ = w.Write([]byte(line))
4444
w.Close()
4545

4646
if got, want := sw.data[0], "> **************"; got != want {
@@ -61,7 +61,7 @@ func TestReplaceMultilineJson(t *testing.T) {
6161

6262
sw := &nopWriter{}
6363
w := NewReplacer(&nopCloser{sw}, secrets)
64-
w.Write([]byte(line)) // nolint:errcheck
64+
_, _ = w.Write([]byte(line))
6565
w.Close()
6666

6767
if got, want := sw.data[0], "{\n **************\n}"; got != want {

pipeline/runtime/common.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func fetchOutputVariables(outputFile string, out io.Writer) (map[string]string,
7575
for s.Scan() {
7676
line := s.Text()
7777
sa := strings.Split(line, " ")
78-
if len(sa) < 2 { // nolint:gomnd
78+
if len(sa) < 2 { //nolint:gomnd
7979
log.WithField("variable", sa[0]).Warnln("output variable does not exist")
8080
} else {
8181
outputs[sa[0]] = line[len(sa[0])+1:]
@@ -90,7 +90,6 @@ func fetchOutputVariables(outputFile string, out io.Writer) (map[string]string,
9090

9191
// setTiEnvVariables sets the environment variables required for TI
9292
func setTiEnvVariables(step *spec.Step) {
93-
9493
config := pipeline.GetState().GetTIConfig()
9594
if config == nil {
9695
return

pipeline/runtime/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func executeRunStep(ctx context.Context, engine *engine.Engine, r *api.StartStep
4444

4545
if len(r.OutputVars) > 0 {
4646
if exited != nil && exited.Exited && exited.ExitCode == 0 {
47-
outputs, err := fetchOutputVariables(outputFile, out) // nolint:govet
47+
outputs, err := fetchOutputVariables(outputFile, out) //nolint:govet
4848
if err != nil {
4949
return exited, nil, err
5050
}

pipeline/runtime/runtest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func executeRunTestStep(ctx context.Context, engine *engine.Engine, r *api.Start
5656

5757
if len(r.OutputVars) > 0 {
5858
if exited != nil && exited.Exited && exited.ExitCode == 0 {
59-
outputs, err := fetchOutputVariables(outputFile, out) // nolint:govet
59+
outputs, err := fetchOutputVariables(outputFile, out) //nolint:govet
6060
if err != nil {
6161
return exited, nil, err
6262
}

0 commit comments

Comments
 (0)