-
Notifications
You must be signed in to change notification settings - Fork 1.8k
chore: Enable go fmt as a lint check for Go code #11830
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
Conversation
Hi @cmdevoto. Thanks for your PR. I'm waiting for a kubeflow member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
🚫 This command cannot be processed. Only organization members or owners can use the commands. |
.pre-commit-config.yaml
Outdated
@@ -65,3 +65,11 @@ repos: | |||
language: golang | |||
require_serial: true | |||
pass_filenames: false | |||
- repo: local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to change this to use a repo like https://github.com/Bahjat/pre-commit-golang or https://github.com/dnephin/pre-commit-golang
/ok-to-test |
love to see standardizing formatting |
@@ -56,7 +56,8 @@ func NewExperimentServiceGetExperimentV1ParamsWithHTTPClient(client *http.Client | |||
} | |||
} | |||
|
|||
/*ExperimentServiceGetExperimentV1Params contains all the parameters to send to the API endpoint | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file and many others modified in this PR are generated (see this for example).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@droctothorpe thanks for pointing this out. Yes, I agree that we should exclude generated files that developers are never expected to directly modify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, @droctothorpe & @mprahl! All of the files modified by go fmt ./...
were in backend/api/v1beta1/go_http_client
and backend/api/v2beta1/go_http_client
, which all seem to be autogenerated files. Do you still want the pre-commit hook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cmdevoto how about also adding goimports
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, @droctothorpe & @mprahl! All of the files modified by
go fmt ./...
were inbackend/api/v1beta1/go_http_client
andbackend/api/v2beta1/go_http_client
, which all seem to be autogenerated files. Do you still want the pre-commit hook?
IMO, yes. It will enforce standardized formatting for future, non-generated golang contributions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@droctothorpe @mprahl Version 2 of golangci-lint
introduced formatting with golangci-lint fmt
(along with some other configuration file changes). Thoughts on adding gofmt
and goimports
to the config file and just adding another pre-commit hook to run the format command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@droctothorpe @mprahl Hi all! Made the changes as described in my comment above - let me know what you think
- govet | ||
- ineffassign | ||
- misspell | ||
- staticcheck | ||
- stylecheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed as gosimple
and stylecheck
were removed in version 2
@@ -65,3 +65,11 @@ repos: | |||
language: golang | |||
require_serial: true | |||
pass_filenames: false | |||
- id: golangci-lint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are there two entries for golangci-lint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because each one has a different entry: golangci-lint run --new-from-rev HEAD --fix
and golangci-lint fmt
. I think you can have multiple entries for one hook ID but then you wouldn't be able to tell which command failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be misunderstanding, but wouldn't the second entry be more comprehensive than the first and thus making the first unnecessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that golangci-lint run
runs the linters while golangci-lint fmt
runs the formatters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, makes sense! I missed the run vs fmt distinction.
@@ -65,3 +65,11 @@ repos: | |||
language: golang | |||
require_serial: true | |||
pass_filenames: false | |||
- id: golangci-lint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd also be nice to have a Make target to run linting as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, added in latest commit 👍
@cmdevoto where is this enforced in the PR CI? |
cc @mprahl Do you mean as part of the github workflows? I don't believe any of the pre-commit hooks are enforced in a PR's CI currently (but correct me if I'm wrong). Do you want just the |
If you want to start with just |
7e7a991
to
7dc5621
Compare
@mprahl I added a new github workflow that only runs the |
/rerun-workflow "KFP e2e tests" |
/rerun-workflow "CI Check" |
Signed-off-by: Caroline DeVoto <cmdevoto@users.noreply.github.com>
/rerun-workflow "CI Check" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
/approve clean code ftw, thanks team! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: HumairAK, mprahl The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
signed off by: Caroline DeVoto cmdevoto@users.noreply.github.com
Resolves #11825
Description of your changes:
Added
golangci-lint fmt
a pre commit hook withgofmt
andgoimports
enabled to ensure standard format across Go source files. The.golangci.yaml
file was also refactored for version 2.Note that the
pycln
version is updated as well in the.pre-commit-config.yaml
due to an issue with Python >=3.12 that was fixed in the v2.2.0 release.Checklist: