Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move to golangci-lint and address linting issues #242

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
############################# Main targets #############################
# Run all checks, build, and test.
install: clean staticcheck errcheck workflowcheck bins test
install: clean lint workflowcheck bins test
########################################################################

##### Variables ######
Expand All @@ -27,20 +27,15 @@ test:
$(NEWLINE))
@! grep -q "^--- FAIL" test.log

staticcheck:
@printf $(COLOR) "Run static check..."
@GO111MODULE=off go get -u honnef.co/go/tools/cmd/staticcheck
@staticcheck ./...

errcheck:
@printf $(COLOR) "Run error check..."
@GO111MODULE=off go get -u github.com/kisielk/errcheck
@errcheck ./...
lint:
@printf $(COLOR) "Run checks..."
@go install github.com/golangci/golangci-lint/cmd/[email protected]
@golangci-lint run --disable-all -E errcheck -E staticcheck

workflowcheck:
@printf $(COLOR) "Run workflow check..."
@go install go.temporal.io/sdk/contrib/tools/workflowcheck
@workflowcheck -show-pos ./...
@workflowcheck -config workflowcheck.config.yaml -show-pos ./...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this config? Is something triggering it?


update-sdk:
go get -u go.temporal.io/api@master
Expand All @@ -49,5 +44,5 @@ update-sdk:

clean:
rm -rf bin
ci-build: staticcheck errcheck workflowcheck bins test

ci-build: lint workflowcheck bins test
4 changes: 2 additions & 2 deletions dsl/starter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"context"
"flag"
"io/ioutil"
"log"
"os"

"github.com/pborman/uuid"
"go.temporal.io/sdk/client"
Expand All @@ -18,7 +18,7 @@ func main() {
flag.StringVar(&dslConfig, "dslConfig", "dsl/workflow1.yaml", "dslConfig specify the yaml file for the dsl workflow.")
flag.Parse()

data, err := ioutil.ReadFile(dslConfig)
data, err := os.ReadFile(dslConfig)
if err != nil {
log.Fatalln("failed to load dsl config file", err)
}
Expand Down
14 changes: 7 additions & 7 deletions expense/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"

Expand All @@ -20,8 +20,8 @@ func CreateExpenseActivity(ctx context.Context, expenseID string) error {
if err != nil {
return err
}
body, err := ioutil.ReadAll(resp.Body)
_ = resp.Body.Close()
defer resp.Body.Close() // nolint:errcheck
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
Expand Down Expand Up @@ -57,8 +57,8 @@ func WaitForDecisionActivity(ctx context.Context, expenseID string) (string, err
logger.Info("waitForDecisionActivity failed to register callback.", "Error", err)
return "", err
}
body, err := ioutil.ReadAll(resp.Body)
_ = resp.Body.Close()
defer resp.Body.Close() // nolint:errcheck
body, err := io.ReadAll(resp.Body)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should leave this how it was and just change ioutil to os. We want to explicitly show we ignore errors and there is no benefit to changing this to a defer here.

if err != nil {
return "", err
}
Expand Down Expand Up @@ -86,8 +86,8 @@ func PaymentActivity(ctx context.Context, expenseID string) error {
if err != nil {
return err
}
body, err := ioutil.ReadAll(resp.Body)
_ = resp.Body.Close()
defer resp.Body.Close() // nolint:errcheck
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions fileprocessing/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fileprocessing

import (
"context"
"io/ioutil"
"os"
"strings"
"time"
Expand Down Expand Up @@ -40,7 +39,7 @@ func (a *Activities) ProcessFileActivity(ctx context.Context, fileName string) (
defer func() { _ = os.Remove(fileName) }() // cleanup temp file

// read downloaded file
data, err := ioutil.ReadFile(fileName)
data, err := os.ReadFile(fileName)
if err != nil {
logger.Error("processFileActivity failed to read file.", "FileName", fileName, "Error", err)
return "", err
Expand Down Expand Up @@ -84,7 +83,7 @@ func (b *BlobStore) downloadFile(fileID string) []byte {

func (b *BlobStore) uploadFile(ctx context.Context, filename string) error {
// dummy uploader
_, err := ioutil.ReadFile(filename)
_, err := os.ReadFile(filename)
for i := 0; i < 5; i++ {
time.Sleep(1 * time.Second)
// Demonstrates that heartbeat accepts progress data.
Expand All @@ -110,7 +109,7 @@ func transcodeData(ctx context.Context, data []byte) []byte {
}

func saveToTmpFile(data []byte) (f *os.File, err error) {
tmpFile, err := ioutil.TempFile("", "temporal_sample")
tmpFile, err := os.CreateTemp("", "temporal_sample")
if err != nil {
return nil, err
}
Expand Down
6 changes: 6 additions & 0 deletions workflowcheck.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
decls:
print: false
fmt.Printf: false
fmt.Sprintf: false
fmt.Sprint: false
fmt.Errorf: false