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

Minor cleanup, resolve some Clippy lints #155

Merged
merged 18 commits into from
Apr 13, 2024

Conversation

Diomendius
Copy link
Contributor

I ran cargo clippy -- -W clippy::pedantic and fixed the issues it complained about that I thought were most reasonable. I also removed a redundant clone from watch.rs which Clippy surprisingly didn't complain about.

There were a few lints I decided against fixing, such as a |p| p.render() closure in handlebars_helpers.rs which would need to be expanded to the fully-qualified path handlebars::PathAndJson::render. There were a lot of instances of clippy::uninlined-format-args (fmt!("{} {}", x, y)fmt!("{x} {y}")) which I didn't bother with, though if you prefer the inline style, you could run cargo clippy --fix -- -A clippy::all -W clippy::uninlined-format-args to auto-fix them.

I also noticed the crate is on edition = "2018". Changing this to edition = "2021" doesn't seem to require any other changes to the code, so it should be an easy change if you want to do that at some point.

@SuperCuber
Copy link
Owner

Looks good. I like the inline format args and the edition suggestions, could you add them to the PR?

Implicit elision of type lifetime parameters is deprecated, as per the
rust-2018-idioms warning.
Clippy's needless_pass_by_value lint shows a couple functions that don't
need to own their arguments. undeploy() in particular takes a 240-byte
Options struct by value but, like deploy(), doesn't need mutable access.
Clippy's unnested-or-patterns lint caught this.
Clippy's match-same-arms lint caught this. The previous two functions
already used or-patterns like this, but condition() was overlooked.
Clippy's unused-self lint caught this.
Clippy's doc-markdown lint caught this.
Due to being in a move closure, this clone captures opt by value and
then clones it. This wouldn't work even if opt were used later in the
enclosing scope and serves no purpose as it is.
Clippy's uninlined-format-args lint caught this.
Clippy's redundant-else lint caught this.
Rustfmt wants this broken due to line length and requires {} for
multiline match arms, but doesn't insert a ; because it only sees
syntax, not types. Clippy then complains (when pedantic) about the
implicit () return.

Clippy's clippy::semicolon-if-nothing-returned lint caught this.
Clippy's redundant-closure lint caught this.
Replaces `assert_eq!(x, [true|false])` with `assert!([x|!x])`.

Clippy's bool-assert-comparison lint caught this.
When testing without the `scripting` feature, compilation would fail
because a `Configuration` was constructed assuming the `helpers` field
always exists, but it only exists when `scripting` is enabled.
In `deploy::test::{low_level_simple, low_level_skip}`,
`Default::default()` was used to construct a `BTreeMap`, with the only
indication of the variable's type being the signature of
`RealActionRunner::new()`, which it was passed by reference to.

Clippy's default-trait-access lint caught this.
@Diomendius
Copy link
Contributor Author

I think I wrongly assumed you would be notified when I pushed commits, so this has sat open for longer than I expected. Sorry about that.

Anyway, I've revisited this, rebased to resolve the minor conflict in handlebars_helpers.rs, fixed some more lints and fixed a compile error I found along the way which would occur when running cargo test --no-default-features. I suppose the compile error is slightly out of scope for this PR, but the fix only adds two #[cfg] annotations, so I've included it with everything else.

This doesn't quite resolve everything that Clippy complains about with -W clippy::pedantic, but what remains is dubiously helpful. You can have a look yourself with cargo clippy --tests -- -W clippy::pedantic if you like.

src/config.rs Outdated Show resolved Hide resolved
@SuperCuber
Copy link
Owner

Looks great :D I commented on the .is_err() assert but I assume there might be more asserts like it, or .is_ok, .is_some etc. Please replace them with .unwrap and .unwrap_err :)

Then it's ready for merge

This is less verbose and provides a more detailed panic message.
`config::tests` was the only test module not named `test`.
@Diomendius
Copy link
Contributor Author

I actually couldn't find any other uses of .is_err(), .is_ok(), .is_some() or .is_none() in an assert, but I pushed a commit to fix the one you noticed.

And, since I happened to notice, for good measure I also renamed the config::tests module to test, since it was the only one not following that naming convention. I swear I didn't set out to make a bunch of single-character commits on purpose. 😅

@SuperCuber
Copy link
Owner

THanks for the contribution :D

@SuperCuber SuperCuber merged commit d38a5dd into SuperCuber:master Apr 13, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants