diff --git a/Makefile b/Makefile index a23d8ca1..d6a70448 100644 --- a/Makefile +++ b/Makefile @@ -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 ###### @@ -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/golangci-lint@v1.50.1 + @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 ./... update-sdk: go get -u go.temporal.io/api@master @@ -49,5 +44,5 @@ update-sdk: clean: rm -rf bin - -ci-build: staticcheck errcheck workflowcheck bins test + +ci-build: lint workflowcheck bins test diff --git a/dsl/starter/main.go b/dsl/starter/main.go index 98476914..ca3e7ddd 100644 --- a/dsl/starter/main.go +++ b/dsl/starter/main.go @@ -3,8 +3,8 @@ package main import ( "context" "flag" - "io/ioutil" "log" + "os" "github.com/pborman/uuid" "go.temporal.io/sdk/client" @@ -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) } diff --git a/expense/activities.go b/expense/activities.go index 363fd66a..54c7f599 100644 --- a/expense/activities.go +++ b/expense/activities.go @@ -4,7 +4,7 @@ import ( "context" "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/url" @@ -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 } @@ -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) if err != nil { return "", err } @@ -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 } diff --git a/fileprocessing/activities.go b/fileprocessing/activities.go index f0f3a22e..276faac9 100644 --- a/fileprocessing/activities.go +++ b/fileprocessing/activities.go @@ -2,7 +2,6 @@ package fileprocessing import ( "context" - "io/ioutil" "os" "strings" "time" @@ -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 @@ -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. @@ -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 } diff --git a/workflowcheck.config.yaml b/workflowcheck.config.yaml new file mode 100644 index 00000000..3cc1837e --- /dev/null +++ b/workflowcheck.config.yaml @@ -0,0 +1,6 @@ +decls: + print: false + fmt.Printf: false + fmt.Sprintf: false + fmt.Sprint: false + fmt.Errorf: false