Skip to content

Pass files to golint one at a time#67675

Merged
k8s-github-robot merged 3 commits intokubernetes:masterfrom
cblecker:fix-golint
Aug 22, 2018
Merged

Pass files to golint one at a time#67675
k8s-github-robot merged 3 commits intokubernetes:masterfrom
cblecker:fix-golint

Conversation

@cblecker
Copy link
Copy Markdown
Member

@cblecker cblecker commented Aug 21, 2018

What this PR does / why we need it:
When we pass multiple files into golint at once, and golint detects a fatal error in one of them, it will actually exit and not process any more of the files passed. For large packages, this increases the chance that golint will exit.

This change will, instead of golinting once per package, will use xargs to run each file through golint individually.

Special notes for your reviewer:
Out of interest, I timed the difference between using find and a regex to exclude the generated files, but ls | grep was about 15-20 seconds faster throughout the entire duration of the run (about 2 minutes).

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 21, 2018
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 21, 2018
@cblecker
Copy link
Copy Markdown
Member Author

/cc @nikhita

Still need to write stuff up on this one, but figured I might as well throw it in front of CI while I grab some lunch.

@k8s-ci-robot k8s-ci-robot requested a review from nikhita August 21, 2018 20:26
Copy link
Copy Markdown
Member

@nikhita nikhita Aug 21, 2018

Choose a reason for hiding this comment

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

@cblecker thank you!

This line looks good. If CI likes it overall, lgtm with an update to the comment. 👍

@nikhita
Copy link
Copy Markdown
Member

nikhita commented Aug 21, 2018

@cblecker just a heads up that once #67635 merges, the list would need to be updated again.

@nikhita
Copy link
Copy Markdown
Member

nikhita commented Aug 21, 2018

/cc @spxtr
since you had updated this file previously

@k8s-ci-robot k8s-ci-robot requested a review from spxtr August 21, 2018 20:38
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 22, 2018
@cblecker
Copy link
Copy Markdown
Member Author

This is what the failures look like now that it's actually looking at all files:
https://gist.github.com/cblecker/55b0f86d93b5b7c6d6857d68f35668fc

@cblecker cblecker changed the title [WIP] fix golint Pass files to golint one at a time Aug 22, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 22, 2018
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add some more details on why a package might contain a fatal error? Something like: as if one file in the package contains a fatal error due to the presence of a corresponding foo_test package.

The foo_test line in the script helped me find the problem in a second. :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: _test.go files?

@nikhita
Copy link
Copy Markdown
Member

nikhita commented Aug 22, 2018

Adding some more details so that if someone comes across this, it's easier for them to understand the line of thought. :)

When we pass multiple files into golint at once, and golint detects a fatal error in one of them, it will actually exit and not process any more of the files passed.

This is due to an existing golint bug: golang/lint#68 (comment). If we lint a package using golint p/*.go and the package p contains test files with the package name p_test, this gives a fatal error, something like:

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured_test.go is in package unstructured_test, not unstructured

and skips the linting. Current behaviour was to ignore this error, which also meant that we ignored the linting of these packages all together.

Also, it's not possible to lint the whole package together through golint p because that would not lint _test.go files due to another golint bug: golang/lint#200.

This change will, instead of golinting once per package, will use xargs to run each file through golint individually.

And so we use xargs to make sure we are linting all files and don't hit any errors. ✨

@cblecker
Copy link
Copy Markdown
Member Author

@nikhita Addressed your feedback. PTAL!

Also thanks for the amazing write up ✨ 🗒 ! I linked to this PR in the comments to so future bash spelunkers will be able to find it! :bash:

@nikhita
Copy link
Copy Markdown
Member

nikhita commented Aug 22, 2018

I linked to this PR in the comments to so future bash spelunkers will be able to find it!

🎉

/lgtm
/retest

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 22, 2018
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cblecker, nikhita

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link
Copy Markdown

Automatic merge from submit-queue (batch tested with PRs 67378, 67675, 67654). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 0c75bf6 into kubernetes:master Aug 22, 2018
@cblecker cblecker deleted the fix-golint branch August 22, 2018 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants