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

enable linting and bingo management of the lint tool #1524

Merged
merged 6 commits into from
Feb 10, 2025

Conversation

grokspawn
Copy link
Contributor

@grokspawn grokspawn commented Dec 20, 2024

Closes #1525

Discovered that the lint make target doesn't lint anything. It only checks whether go imports are in expected grouping/ordering.

This PR introduces gci support (replacing goimports) as a targeted linter, and implements golang-linter support via a bingo-managed version.

There are discrete commits to topically collect:

  1. adding lint infrastructure
  2. automated lint fixes
  3. manual test lint fixes
  4. manual functional lint fixes
  5. bingo update of golangci-lint version
  6. review updates

The parent issue has a link to a google sheet which includes a list of every single update made here, categorized and broken down by reporting linter.

The ONLY FOCUS of this PR is to establish a "bright line" beyond which no new reports will slip through the cracks, but due to the age (and the "feature completeness") of much of the reported code, there are a LOT of issues which are specifically and locally disabled to remove them from lint reports without making updates.

I'd initially felt sanguine about updating style changes which modified (read: broke) APIs, but I backed away from this after seeing how prevalent those changes would need to be.

The only included case of a stylistic breaking API change was the JSONUnmarshaller, since this is a recent addition that was added for internal use, so it seemed a safe bet to not break anyone's access.

I was initially much more willing to make updates to test code to bring them up to date, but

  1. again, the scope of this was soul-destroying; and
  2. I started encountering some unit test failures because the tests weren't seamlessly constructed. These were of the nature of "called twice" or "doesn't need to be called" failure scenarios, and I just restored the original flows and disabled the specific linter in that specific scenario

Description of the change:

Motivation for the change:

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /docs
  • Commit messages sensible and descriptive

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 20, 2024
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 20, 2024
@grokspawn grokspawn force-pushed the add-linting branch 2 times, most recently from e3d597f to 2a7814d Compare December 20, 2024 21:38
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 60.54591% with 159 lines in your changes missing coverage. Please review.

Project coverage is 46.80%. Comparing base (81056f9) to head (ac872de).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pkg/sqlite/query.go 63.04% 13 Missing and 4 partials ⚠️
pkg/mirror/options.go 0.00% 14 Missing ⚠️
pkg/lib/bundle/validate.go 7.14% 11 Missing and 2 partials ⚠️
pkg/containertools/runner.go 0.00% 12 Missing ⚠️
pkg/sqlite/load.go 65.62% 11 Missing ⚠️
pkg/containertools/containertool.go 0.00% 9 Missing ⚠️
pkg/registry/csv.go 63.63% 4 Missing and 4 partials ⚠️
pkg/sqlite/migrations/003_required_apis.go 61.11% 2 Missing and 5 partials ⚠️
pkg/client/kubeclient.go 0.00% 6 Missing ⚠️
pkg/registry/empty.go 0.00% 6 Missing ⚠️
... and 28 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1524      +/-   ##
==========================================
+ Coverage   46.76%   46.80%   +0.04%     
==========================================
  Files         135      135              
  Lines       15776    15873      +97     
==========================================
+ Hits         7377     7430      +53     
- Misses       7358     7402      +44     
  Partials     1041     1041              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@grokspawn grokspawn force-pushed the add-linting branch 2 times, most recently from e831f94 to 3b764ff Compare January 2, 2025 16:24
@grokspawn grokspawn force-pushed the add-linting branch 4 times, most recently from ef05a4a to c9deb72 Compare January 9, 2025 15:39
# Default timeout is 1m, up to give more room
timeout: 4m

linters:
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't have to, but if it's easy enough, we could add govet here as well (then maybe drop it from the Makefile if it's there)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the .golangci.yaml file in this project is a copy of that in op-con. Since that one has just updated, I can take that change, but IMO we can update the Makefile in a separate PR. This one is already way beyond any reasonable complexity.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @grokspawn

You are with an outdated version :-P
See that we added govet there and we cleanup the staff: operator-framework/operator-controller@099a6cf

Copy link
Contributor

Choose a reason for hiding this comment

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

But I am ok with we move forward as it is and add govet in a follow up.
It is fine for me too. @perdasilva wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -500,13 +500,13 @@ func removeJSONWhitespace(cfg *DeclarativeConfig) {
for ib := range cfg.Bundles {
for ip := range cfg.Bundles[ib].Properties {
var buf bytes.Buffer
json.Compact(&buf, cfg.Bundles[ib].Properties[ip].Value)
_ = json.Compact(&buf, cfg.Bundles[ib].Properties[ip].Value)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe also require.NoError ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No test object available in this scope, or I would've. 🤷

cfg.Bundles[ib].Properties[ip].Value = buf.Bytes()
}
}
for io := range cfg.Others {
var buf bytes.Buffer
json.Compact(&buf, cfg.Others[io].Blob)
_ = json.Compact(&buf, cfg.Others[io].Blob)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same problem as pre-ditto.

@@ -276,7 +276,7 @@ func pushLoadImages(client *kubernetes.Clientset, w io.Writer, images ...string)
}
} else {
for _, image := range images {
pushWith("docker", image)
err = pushWith("docker", image)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

if err := pushWith("docker", image); err != nil {
	return 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.

err is declared in line 262. Is there some benefit to re-defining it in this scope? (I'd missed this)

@grokspawn grokspawn force-pushed the add-linting branch 7 times, most recently from e223708 to edc24a7 Compare February 7, 2025 17:30
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 7, 2025
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 7, 2025
- errcheck
- stylecheck
- nestif
- prealloc
- errorlint
- nonamedreturns
- gosec
- gosimple
- govet
- importas
- staticcheck
- unused

Signed-off-by: Jordan Keister <[email protected]>
Signed-off-by: Jordan Keister <[email protected]>
@grokspawn grokspawn changed the title WIP: enable linting and bingo management of the lint tool enable linting and bingo management of the lint tool Feb 7, 2025
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 7, 2025
Copy link

@azych azych left a comment

Choose a reason for hiding this comment

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

That's great and I completely agree with your decision to back out of actually fixing those lint issues in favor of silencing most of them just to establish a baseline given the already significant scope of work - I'm sure people can be good scouts and gradually make fixes as they touch upon different areas of the code they work on.

I didn't notice anything critical silenced, so if it passes CI, it's good to me.

Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm

🚀

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 10, 2025
Copy link
Contributor

openshift-ci bot commented Feb 10, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: azych, camilamacedo86, grokspawn

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

@openshift-merge-bot openshift-merge-bot bot merged commit 5531412 into operator-framework:master Feb 10, 2025
11 of 12 checks passed
@grokspawn grokspawn deleted the add-linting branch February 10, 2025 19:43
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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lint make target... doesn't lint
5 participants