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

nogo: add missing go vet checks #6218

Merged
merged 4 commits into from
Mar 25, 2024
Merged

Conversation

sluongng
Copy link
Contributor

@sluongng sluongng commented Mar 22, 2024

Remove usage of vet = True in nogo definition. It's simply a shortcut
attribute to appends some additional analyzers to the nogo binary.

Instead, run go tool vet help and copy all listed analyzers in the doc
to our analyzer. This list is more up-to-date than the one in current
rules_go.

Fix 2 new vet issues found with new analyzers added:

Also re-enabled nilness shows a range of issues in our code base that compares nil == nil, non-nil != nil. Fixed those issues in a separate commit for easier review.

Change log: https://tip.golang.org/doc/go1.22

Since musl toolchain in --config=static is not compatible with the
latest Go version, disable static workflows for now.

Issue is reported in uber/hermetic_cc_toolchain#171
Remove usage of `vet = True` in nogo definition. It's simply a shortcut
attribute to appends some additional analyzers to the nogo binary.

Instead, run `go tool vet help` and copy all listed analyzers in the doc
to our analyzer. This list is more up-to-date than the one in current
rules_go.

Fix 2 vet issues found with new analyzers added:

- Misuse of unbuffered os.Signal channel as argument to signal.Notify
  The channel should be buffered with minimal size of 1.

- time.Since should not be used in defer statement
  See golang/go#60048 for more information
@sluongng
Copy link
Contributor Author

based on #6217

@sluongng sluongng changed the title sluongng/new go vet analyzers nogo: add missing go vet checks Mar 22, 2024
Copy link
Contributor

@maggie-lou maggie-lou left a comment

Choose a reason for hiding this comment

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

A couple small things but mostly looks good

enterprise/server/scheduling/task_leaser/task_leaser.go Outdated Show resolved Hide resolved
server/util/ioutil/ioutil.go Outdated Show resolved Hide resolved
@sluongng sluongng force-pushed the sluongng/new-go-vet-analyzers branch from ead5a49 to 5f640d7 Compare March 23, 2024 09:18
@@ -174,9 +174,13 @@ func exportNormalizedDashboard(d *Dashboard) error {
return err
}
outPath := filepath.Join(dashboardsDir, fileName)
outFile, err := os.ReadFile(outPath)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

nit: the original intent was to write the file if it did not exist or if it contains different bytes

Suggested change
if err != nil {
if err != nil && !os.IsNotExist(err) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case the file does not exist, the byte slice content return will be nil and after the bytes.Equal result 🤔

I guess we want to write when the previous file was not there (i.e. on the first time exporting)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sent a fix that would handle the nil content case.

@sluongng sluongng merged commit cfcb474 into master Mar 25, 2024
15 of 16 checks passed
@sluongng sluongng deleted the sluongng/new-go-vet-analyzers branch March 25, 2024 16:52
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.

4 participants