-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix clippy warnings #52
Conversation
Here are the fixed warnings:
|
let ns = match ns { | ||
Some(namespace) => namespace.to_string(), | ||
None => { | ||
if !config.contexts.is_empty() && !config.contexts[0].context.namespace.is_empty() { |
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.
Thank you! That function wasn't the prettiest one 😅
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.
No worries, it was correct after all 😄
@@ -65,7 +65,7 @@ pub fn context(args: Cli) { | |||
"{}/{}:{}", | |||
&DEST.as_str(), | |||
str::replace(&ctx, ":", "_"), | |||
KUBECONFIG.to_string() | |||
*KUBECONFIG |
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 have no idea what the * here does but seems to work!
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's the dereferencing operator, usually used to retrieve concrete values from references, i.e. turn a &i64
into i64
. It's available on all types implementing Deref .
lazy_static stores our lazy string behind a proxy struct pub struct Lazy<T: Sync>(Cell<Option<T>>, Once);
that implements Deref
to return the underlying value (T
in the type signature, which is String
in our case). So we are dereferencing the proxy struct to get the concrete String value.
Though I'd be lying if I said I really understand its implementation 😄
This thread tries to explain it: https://users.rust-lang.org/t/after-more-than-half-years-of-rust-in-production-i-still-dont-understand-how-lazy-static-works-what-am-i-doing-wrong/31870
Are you able to merge this yourself if it's approved? (curious about the permission settings) |
I agree! I'll add it right away! Edit: Added clippy-action but there seems to be a bug #84, I'l leave it for now |
I can't, Github shows me the following:
You're right 🤔 I'll give it a try in a test repo when I have the time :) |
Sent an invite to you as a collaborator but if you don't want that I can manage the merges! |
Thank you for your trust! I'm now indeed able to merge the approved PR :) |
Description
Hi Ramilito,
nothing big this time, just used
cargo clippy
to check the code base for linter warnings.Mostly small changes like superfluous dereferences or excessive
.to_string()
.The biggest change worth looking at would be the rewrite of the pattern matching in
config.rs
line 13 to avoid the unwrap().We could also add a Github Action to automatically run cargo clippy on PRs to ensure code quality, what do you think?
For example https://github.com/giraffate/clippy-action, maintained by a member of the rust-lang clippy team.
We could add it in this PR or a separate one.
Type of change
How Has This Been Tested?
No specific tests, just fixes linter warnings
Checklist: