-
Notifications
You must be signed in to change notification settings - Fork 372
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
Improve linting and fix found issues #435
Conversation
* don't shadow imports or builtins such as `os` and `close` respectively. * use wrapper ReplaceAll * combine types in func calls if same type
d57022a
to
1273c64
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
thanks for the work. looks good. |
@ahmetb It was mostly from my reading but checked linters and added more rules |
}) | ||
} | ||
|
||
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go tool dist list
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
/lgtm |
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) |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
internal/installation/platform.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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? |
I already added, see the diff in |
Anything else is needed? |
Thanks. I don't fully understand the list of linter check in .golangci.yml, but it's ok for now. |
[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 |
Enable all rules from gocritic except some troublesome rules (see
.golangci.yml
for details).Here is a part of what new rules bring:
os
andclose
respectively.To fix some of the issues, I created a type for os and arch, then exported it.