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

🌱 golangci-lint: add recommended revive checks to linter-settings but d… #3034

Merged

Conversation

oscr
Copy link
Contributor

@oscr oscr commented Oct 22, 2022

  • Updates golangci-lint version from 1.49.0 -> 1.50.1
  • Adds all recommended revive checks to the config file. However to keep this pr simpler some new checks where disabled. But at least it's explicit now there are recommended checks that aren't enabled. I would gladly look into each of the disabled checks in follow up prs.
  • Fixes the finding:
    test/e2e/utils/test_context.go:273:1: receiver-naming: receiver name tc should be consistent with previous receiver name t for TestContext (revive)
    
    func (tc TestContext) LoadImageToKindClusterWithName(image string) error {
         cluster := "kind"
         if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
                 cluster = v
         }
         kindOptions := []string{"load", "docker-image", "--name", cluster, image}
         cmd := exec.Command("kind", kindOptions...)
         _, err := tc.Run(cmd)
         return err
    }
    

…isable checks with to many findings. Fix findings
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 22, 2022
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 22, 2022
@@ -13,8 +17,42 @@ linters-settings:
enable=fieldalignment: true
revive:
rules:
- name: if-return
disabled: true
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
Copy link
Member

Choose a reason for hiding this comment

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

I think we merged the revive by mistake.
Why should we have revive and golangci?

Also, note that we are only using golangci and we do not test the projects with revive.
In this way, ihmo we need to remove:

linters-settings:
  govet:
    enable=fieldalignment: true
  revive:
    rules:
    - name: if-return
      disabled: true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest I just noticed revive was enabled but not with the recommended configuration and therefor I made a pr to work towards the recommended configuration. I believe that if you remove that section you will get default configuration instead.

As for the question of should there be / how much linting should a project have. I think that's a question you have more experience to answer. IMO there is a value for some linting. The question is always where do we get most value out of the least amount of linting overhead.

Copy link
Member

@camilamacedo86 camilamacedo86 Oct 24, 2022

Choose a reason for hiding this comment

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

HI @oscr,

I believe that if you remove that section you will get default configuration instead.

I would we get that?
We are not downloading or testing using revive. We just use golangci.
Am I missing something here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@camilamacedo86 golangci-lint is not a linter in itself, it's a linter runner. So you can configure golangci to run fewer or more or less linters. Then to make everything more complicated some linters (such as revive) are metalinters and they can be configured with even more checks.

https://golangci-lint.run/usage/linters/

Copy link
Member

Choose a reason for hiding this comment

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

Hun, I catcher. So, we are calling the revive checks when you run make lint and test the project with golangci.
In this way, I am ok with the changes made too.

- name: indent-error-flow
- name: errorf
- name: empty-block
disabled: true # TODO: Investigate if it should be enabled. Disabled for now due to many findings.
Copy link
Member

Choose a reason for hiding this comment

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

If that is the recommendation we might want in a follow up fix the issues and then enable right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think that would be good to do. You might want them. You might not. But I disabled the checks that found many / non trivial findings to keep the complexity and size of this pr smaller.

Copy link
Member

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

I am OK with the changes made.
Would be nice to fix the lint issues found in the other checks in follow-ups 🥇

@oscr see that I updated the PR title to use 🌱 . This change does not affect end-users and the PR should not be used to create the changelog. It only changes the checks used to lint the KB code itself.

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Oct 24, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, oscr

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 Oct 24, 2022
@camilamacedo86 camilamacedo86 changed the title ✨ golangci-lint: add recommended revive checks to linter-settings but d… 🌱 golangci-lint: add recommended revive checks to linter-settings but d… Oct 24, 2022
@camilamacedo86
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 24, 2022
@k8s-ci-robot k8s-ci-robot merged commit 523907a into kubernetes-sigs:master Oct 24, 2022
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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants