Skip to content

Conversation

cmdevoto
Copy link
Contributor

@cmdevoto cmdevoto commented Apr 15, 2025

signed off by: Caroline DeVoto cmdevoto@users.noreply.github.com
Resolves #11825

Description of your changes:
Added golangci-lint fmt a pre commit hook with gofmt and goimports 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:

Copy link

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

Copy link

🚫 This command cannot be processed. Only organization members or owners can use the commands.

@@ -65,3 +65,11 @@ repos:
language: golang
require_serial: true
pass_filenames: false
- repo: local
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zazulam
Copy link
Collaborator

zazulam commented Apr 15, 2025

/ok-to-test

@zazulam
Copy link
Collaborator

zazulam commented Apr 15, 2025

love to see standardizing formatting
/lgtm

@@ -56,7 +56,8 @@ func NewExperimentServiceGetExperimentV1ParamsWithHTTPClient(client *http.Client
}
}

/*ExperimentServiceGetExperimentV1Params contains all the parameters to send to the API endpoint
/*
Copy link
Collaborator

@droctothorpe droctothorpe Apr 22, 2025

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).

Copy link
Collaborator

Choose a reason for hiding this comment

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

@HumairAK @mprahl do you have a preference on whether or not to exclude generated files from go fmt?

Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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?

Copy link
Collaborator

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?

IMO, yes. It will enforce standardized formatting for future, non-generated golang contributions.

Copy link
Contributor Author

@cmdevoto cmdevoto Apr 23, 2025

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?

Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Collaborator

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?

Copy link
Contributor Author

@cmdevoto cmdevoto May 1, 2025

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.

Copy link
Collaborator

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?

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 believe that golangci-lint run runs the linters while golangci-lint fmt runs the formatters

Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
Contributor Author

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 👍

@HumairAK HumairAK moved this to In Review in KFP Project Tracker May 7, 2025
@HumairAK HumairAK moved this from In Review to In Progress in KFP Project Tracker May 7, 2025
@cmdevoto cmdevoto requested a review from mprahl May 12, 2025 15:20
@mprahl
Copy link
Collaborator

mprahl commented May 12, 2025

@cmdevoto where is this enforced in the PR CI?

@cmdevoto
Copy link
Contributor Author

@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 golangci-lint as part of the CI or all of the pre-commit hooks? If yes to either, it might make sense to add that as part of a separate PR that would precede this one.

@mprahl
Copy link
Collaborator

mprahl commented May 12, 2025

@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 golangci-lint as part of the CI or all of the pre-commit hooks? If yes to either, it might make sense to add that as part of a separate PR that would precede this one.

If you want to start with just golangci-lint for now and include it in this PR, then I think that'd be fine.

@cmdevoto cmdevoto force-pushed the gofmt-changes branch 3 times, most recently from 7e7a991 to 7dc5621 Compare May 13, 2025 02:50
@cmdevoto
Copy link
Contributor Author

@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 golangci-lint as part of the CI or all of the pre-commit hooks? If yes to either, it might make sense to add that as part of a separate PR that would precede this one.

If you want to start with just golangci-lint for now and include it in this PR, then I think that'd be fine.

@mprahl I added a new github workflow that only runs the golangci-lint pre-commit hooks currently. Here are the passing checks in the PR CI.

@mprahl
Copy link
Collaborator

mprahl commented May 14, 2025

/rerun-workflow "KFP e2e tests"

@mprahl
Copy link
Collaborator

mprahl commented May 14, 2025

/rerun-workflow "CI Check"

Signed-off-by: Caroline DeVoto <cmdevoto@users.noreply.github.com>
@zazulam
Copy link
Collaborator

zazulam commented May 16, 2025

/rerun-workflow "CI Check"

Copy link
Collaborator

@mprahl mprahl left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@HumairAK
Copy link
Collaborator

/approve

clean code ftw, thanks team!

Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit e329fa3 into kubeflow:master May 19, 2025
45 of 46 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in KFP Project Tracker May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

chore: Enable go fmt as a lint check for Go code
5 participants