Skip to content

Issue 2428: Enforce comments on the codebase #2443

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

Merged
merged 1 commit into from
Jun 17, 2021

Conversation

Algebra8
Copy link
Contributor

@Algebra8 Algebra8 commented May 29, 2021

What type of PR is this?

/kind support

What this PR does / why we need it:

This PR enforces comments on the codebase via revive.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2428

Special notes for your reviewer:

Checklist:

  • squashed commits
  • includes documentation
  • adds unit tests
  • adds or updates e2e tests

Release note:

Enforced comments on the codebase using Revive (swapped with Golint), and resolved all linter errors.

The following linter errors were resolved:
* Resolve goimports errors
* Resolve deadcode errors by removing unused code
* Resolve misspell error by correcting spelling
* Resolve staticcheck errors
* Staticcheck linter was complaining about fmt.Printf being used with dynamic
first argument and no other arguments (SA1006). This can lead to unexpected
output. To solve this fmt.Printf was switched with fmt.Println.
Also, pkg/cloudtest/cloudtest.go V(level int) returned a logr.InfoLogger which
is deprecated, which Staticcheck complained about. This was swapped with the
newer logr.Logger.
* Exclude noctx error with descriptive comments
* Resolve gosimple errors

Since comments were updated, yamls had to be regenerated using `make regenerate`.

Also, the golangci exclude line "Using the variable on range scope `(tc)|(rt)|(tt)|
(test)|(testcase)|(testCase)` in function literal" was removed because it was
blocking what seemed to be a larger net of linters than it was supposed to, and
because it became redundant after the linter issues were resolved.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/support Categorizes issue or PR as a support question. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 29, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @Algebra8!

It looks like this is your first PR to kubernetes-sigs/cluster-api-provider-aws 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cluster-api-provider-aws has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 29, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @Algebra8. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 29, 2021
@Algebra8
Copy link
Contributor Author

@sedefsavas

Here is the WIP of #2428

Some things to note:

  • For the PR message I said this PR is /kind support but I'm not sure if that's correct.
  • I've swapped golint for revive and will change it back if revive is not wanted.
  • exclude-use-default is set to false because otherwise it will block some of the linter warnings we want for comments.
  • The line Using the variable on range scope `(tc)|(rt)|(tt)|(test)|(testcase)|(testCase)` in function literal in exclude prevents some/a lot of the other linter warnings from propagating so I've removed it for now until a solution can be found.
  • If golangci-lint is not run with the --fast=false flag then revive and some other linters will not be enabled, so during development I've been using the flag. Is the flag also used when running the pipeline?
  • The combination of removing the exclude line, setting fast to false, and adding exclude-use-defaults: false has caused other linter warnings to propagate. I am not sure what to do with them (enable/disable). Towards the end of this PR I will get a list of them and we can figure out what to do then?

I look forward to hearing any feedback 😄

Thanks!

@richardcase
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 1, 2021
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 6, 2021
@Algebra8
Copy link
Contributor Author

Algebra8 commented Jun 6, 2021

Question:

  • Should I squash my commits?

Somethings worth noting:

  • I swapped Golint with Revive
  • I added linters-settings for revive so that only exported is checked (since that is the scope of this PR)
  • This line in .golangci.yml blocks some linters from working (maybe it is too broad?). You can test this yourself by placing an exported function with no comments somewhere in the codebase (e.g. api/), and running golangci-lint run --fast=false api/..., once with the line commented out and once without. I've commented it out until a solution has been reached.

@Algebra8
Copy link
Contributor Author

Algebra8 commented Jun 6, 2021

It seems like the pipeline for pull-cluster-api-provider-aws-test is breaking:

level=error msg="Running error: no such linter revive, run 'golangci-lint linters' to see the list of supported linters"

I was under the impression that Revive is offered out of the box with golangci-lint?

@richardcase
Copy link
Member

* Should I squash my commits?

@Algebra8 - yes please.

@Algebra8 Algebra8 force-pushed the issue-2428 branch 2 times, most recently from 0bd76d3 to 6d92fcb Compare June 7, 2021 19:03
@Algebra8
Copy link
Contributor Author

Algebra8 commented Jun 7, 2021

With regards to pull-cluster-api-provider-aws-test failing as mentioned above, it seems like the issue is that golangci-lint doesn't include Revive as a linter until v1.37.0. The release version being used in this repo is v1.32.0.

I think the two most obvious solutions to this issue are 1_ Update golangci-lint to the most recent version (v1.40.1), 2_ Use Golint instead of Revive (I believe Golint is deprecated in up-to-date versions).

Another option may be to externally install revive but I'm not at this moment sure of how or if that would work.

Any suggestions?

@sedefsavas
Copy link
Contributor

@Algebra8 This PR bumps the lint version #2485 to v1.40.1, so we are good to use revive.

@Algebra8
Copy link
Contributor Author

Algebra8 commented Jun 9, 2021

A few notes on recent commits:

The following commits are related to removing linter warnings:

An important one to note is Exclude noctx error with descriptive comments, because it simply excludes the warning and I'm not sure if that's what we want. However, I believe the solution falls outside the scope of the PR because the Go versions that cluster-api-provider-aws supports matter. See here for more info. (I am more than happy to create an issue and another PR for this).

Finally, commit 2083cfd should resolve the breaking pipeline for pull-cluster-api-provider-aws-verify by re-generating generated yaml files using make generate.

@sedefsavas
I have not squashed these commits yet because I want to make sure they are approved first, so I look forward to any feedback.

@Algebra8 Algebra8 changed the title WIP: Issue 2428: Enforce comments on the codebase Issue 2428: Enforce comments on the codebase Jun 12, 2021
@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 Jun 12, 2021
@Algebra8
Copy link
Contributor Author

@CecileRobertMichon

Following the instructions of the k8s-ci-robot and tagging you!

Apologies for the large PR, but I was told beforehand that this PR was expected to be big.

However, I included some things that might fall out of the domain of the PR (please see #2443 (comment)). I would be more than happy to roll back the commit history and open up separate PRs if it was a mistake to include them (I included them because I assumed pull-cluster-api-provider-aws-test pipeline would break otherwise).

I look forward to your feedback and will assign you to this PR (as per the requests of k8s-ci-robot).

/assign @CecileRobertMichon

@CecileRobertMichon
Copy link

/unassign
/assign @sedefsavas @richardcase

.golangci.yml Outdated
Comment on lines 50 to 51
# TODO(algebra8): Find solution to line below or remove if not needed.
# - Using the variable on range scope `(tc)|(rt)|(tt)|(test)|(testcase)|(testCase)` in function literal
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these be removed?

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 forgot about that commented out line, thank you for bringing that to my attention.

I will set the PR as WIP again and try to figure out what that line did. As far as I can tell, that line was casting a wide net of linter exclusions - which I assumed was not desired. However, since all linters are passing now it should be ok to remove.

@sedefsavas
Copy link
Contributor

Minor comment otherwise lgtm

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sedefsavas

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 15, 2021
@Algebra8 Algebra8 changed the title Issue 2428: Enforce comments on the codebase WIP: Issue 2428: Enforce comments on the codebase Jun 15, 2021
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 15, 2021
@Algebra8 Algebra8 force-pushed the issue-2428 branch 2 times, most recently from dc0d6c7 to 888d25d Compare June 17, 2021 01:49
The following linter errors were resolved to fix any pipeline issues:
* Resolve goimports errors
* Resolve deadcode errors by removing unused code
* Resolve misspell error by correcting spelling
* Resolve staticcheck errors
* Staticcheck linter was complaining about fmt.Printf being used with dynamic
first argument and no other arguments (SA1006). This can lead to unexpected
output. To solve this fmt.Printf was switched with fmt.Println.
Also, pkg/cloudtest/cloudtest.go V(level int) returned a logr.InfoLogger which
is deprecated, which Staticcheck complained about. This was swapped with the
newer logr.Logger.
* Exclude noctx error with descriptive comments
* Resolve gosimple errors

Since comments were updated, yamls had to be regenerated using `make regenerate`:
* Generate yamls from changed comments using make generate

Also, the golangci exclude line "Using the variable on range scope `(tc)|(rt)|(tt)|
(test)|(testcase)|(testCase)` in function literal" was removed because it was
blocking what seemed to be a larger net of linters than it was supposed to and
because after the linter issues were resolved it became redundant.
@Algebra8 Algebra8 changed the title WIP: Issue 2428: Enforce comments on the codebase Issue 2428: Enforce comments on the codebase Jun 17, 2021
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 17, 2021
@sedefsavas sedefsavas removed the kind/support Categorizes issue or PR as a support question. label Jun 17, 2021
@sedefsavas
Copy link
Contributor

Thanks @Algebra8
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 17, 2021
@k8s-ci-robot k8s-ci-robot merged commit 6dc7290 into kubernetes-sigs:main Jun 17, 2021
@k8s-ci-robot k8s-ci-robot added this to the v0.7.0 milestone Jun 17, 2021
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enforce comments on the codebase
5 participants