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

Conversation

miku
Copy link

@miku miku commented Jan 3, 2023

What was changed

Previously, two separate checks "errcheck" and "staticcheck" were used. These are also part of "golangci-lint" [1] metalinter.

In addition, "golangci-lint" has a nolint directive [2], which at least "errcheck" did not seem to have.

At this point in time, "golangci-lint" bundles 72 linters [3] (of which this project uses two) - so additional check can easily be added. A configuration file was required to suppress false positives regarding determinism stemming from "print" and "fmt" functions.

As this project use "go 1.16" some safe linting suggestions have been applied (e.g. related to deprecation of https://pkg.go.dev/io/ioutil).

Why?

I wanted to use the nolint directive of golangci-lint to selectively ignore checks, e.g. to ignore an error in defer when closing an HTTP response body.

At the same time, it seemed to simplify the Makefile to use a single "metalinter" instead of two separate linters.

Checklist

  1. How was this tested:

Tested locally, via:

$ make
  1. Any docs updates needed?

Not required.

Previously, two separate checks "errcheck" and "staticcheck" were used.
These are also part of "golangci-lint" [1] metalinter.

In addition, "golangci-lint" has a nolint directive [2], which at least
"errcheck" did not seem to have.

At this point in time, "golangci-lint" bundles 72 linters [3] (of which this
project uses two) - so additional check can easily be added. A
configuration file was required to suppress false positives regarding
determinism stemming from "print" and "fmt" functions.

As this project use "go 1.16" some safe linting suggestions have been
applied (e.g. related to deprecation of https://pkg.go.dev/io/ioutil).

[1] https://golangci-lint.run/
[2] https://golangci-lint.run/usage/false-positives/#nolint-directive
[3] https://golangci-lint.run/usage/linters/
@CLAassistant
Copy link

CLAassistant commented Jan 3, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

Thanks! I think we should do the same to https://github.com/temporalio/sdk-go then too. It's a bit off to do it one way in our samples but another in the canonical Go SDK project. (some in-progress PRs are already changing from using ioutil, so we may have to wait until after those)

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.


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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants