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

Improve linting and fix found issues #435

Merged
merged 5 commits into from
Dec 18, 2019

Conversation

ferhatelmas
Copy link
Contributor

@ferhatelmas ferhatelmas commented Dec 13, 2019

Enable all rules from gocritic except some troublesome rules (see .golangci.yml for details).

Here is a part of what new rules bring:

  • don't shadow imports or builtins such as
    os and close respectively.
  • use wrapper ReplaceAll
  • combine types in func calls if same type
  • find duplicate imports
  • find suspicious regex
  • ensure proper comment format

To fix some of the issues, I created a type for os and arch, then exported it.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 13, 2019
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 13, 2019
* don't shadow imports or builtins such as
`os` and `close` respectively.
* use wrapper ReplaceAll
* combine types in func calls if same type
@codecov-io
Copy link

codecov-io commented Dec 13, 2019

Codecov Report

Merging #435 into master will decrease coverage by 0.1%.
The diff coverage is 78.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #435      +/-   ##
==========================================
- Coverage   56.35%   56.25%   -0.11%     
==========================================
  Files          19       19              
  Lines         928      928              
==========================================
- Hits          523      522       -1     
- Misses        350      351       +1     
  Partials       55       55
Impacted Files Coverage Δ
internal/installation/upgrade.go 0% <0%> (ø) ⬆️
internal/download/verifier.go 100% <100%> (ø) ⬆️
internal/receiptsmigration/migration.go 46.15% <100%> (ø) ⬆️
internal/installation/install.go 42.42% <100%> (ø) ⬆️
internal/download/downloader.go 68.14% <60%> (-0.28%) ⬇️
internal/installation/platform.go 76.92% <80%> (-2.25%) ⬇️
cmd/validate-krew-manifest/main.go 54.08% <81.48%> (-0.47%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 541b48b...4a908b4. Read the comment docs.

@ahmetb
Copy link
Member

ahmetb commented Dec 13, 2019

thanks for the work. looks good.
is there a linter option to catch these in the first place?

@ferhatelmas
Copy link
Contributor Author

@ahmetb It was mostly from my reading but checked linters and added more rules
and it found more issues so I added more refactoring.

})
}

// allPlatforms returns all <os,arch> pairs krew is supported on.
func allPlatforms() [][2]string {
func allPlatforms() []installation.GoOSArch {
// TODO(ahmetb) find a more authoritative source for this list
Copy link
Contributor Author

Choose a reason for hiding this comment

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

go tool dist list

Copy link
Contributor

Choose a reason for hiding this comment

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

well, now we now how to get a complete list :)

So what shall we do about it?

Copy link
Member

Choose a reason for hiding this comment

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

I am aware of that. But that would require us running a cmd and keeping code up to date periodically. This is ok for now.

@ferhatelmas ferhatelmas changed the title Some refactoring improvements Improve linting and fix found issues Dec 13, 2019
@corneliusweig
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 13, 2019
t.Errorf("returned OS=%q; expected=%q", outOS, inOS)
out := OSArch()
if inOS != out.OS {
t.Errorf("returned OS=%q; expected=%q", out.OS, inOS)
Copy link
Member

Choose a reason for hiding this comment

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

Use cmp.diff here
What if we add another field :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@@ -55,16 +55,29 @@ func matchPlatform(platforms []index.Platform, os, arch string) (index.Platform,
return index.Platform{}, false, nil
}

// osArch returns the OS/arch combination to be used on the current system. It
// GoOSArch is wrapper around operating system and architecture
type GoOSArch struct {
Copy link
Member

Choose a reason for hiding this comment

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

Can we call this Platform or is that too generic?
We don’t care about “Go” part that much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be used in index too (since exported I didn't want to change in a lint PR).
They are also go specific so for now, it might leave as it is.

Copy link
Contributor

@corneliusweig corneliusweig Dec 14, 2019

Choose a reason for hiding this comment

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

🤔 Wasn't GoOSArch just added in this PR? I think we can choose whatever name suits best. Besides, everything is internal now, so we don't have to bother.

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 rename to whatever you want.

What I mean is that with a better name it could be used in non-internal places too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok :)

So what about Platform as proposed by Ahmet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me since it's in the platform package. Renaming unless there is a better suggestion.

Copy link
Member

Choose a reason for hiding this comment

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

ClientPlatform or OSArchPair isn't that bad either.

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 think renaming it to Platform could be misleading with index.Platform.

It's just OS and Arch so a simple naming might be better. OSArchPair sounds somehow better to me.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 14, 2019
@ahmetb
Copy link
Member

ahmetb commented Dec 15, 2019

checked linters and added more rules

Is there a way we can add these linters preventing shadowing builtins to the CI validation, so that we don't have to go through this again?

@ferhatelmas
Copy link
Contributor Author

Is there a way we can add these linters preventing shadowing builtins to the CI validation

I already added, see the diff in .golangci.yml.

@ferhatelmas
Copy link
Contributor Author

Anything else is needed?

@ahmetb
Copy link
Member

ahmetb commented Dec 18, 2019

Thanks. I don't fully understand the list of linter check in .golangci.yml, but it's ok for now.
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 18, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmetb, ferhatelmas

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 Dec 18, 2019
@k8s-ci-robot k8s-ci-robot merged commit d7bc0ca into kubernetes-sigs:master Dec 18, 2019
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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants