Refactor with the help of Clippy #462
No reviewers
Labels
No labels
A: API
A: Backend
A: Federation
A: Front-End
A: I18N
A: Meta
A: Security
Build
C: Bug
C: Discussion
C: Enhancement
C: Feature
Compatibility
Dependency
Design
Documentation
Good first issue
Help welcome
Mobile
Rendering
S: Blocked
S: Duplicate
S: Incomplete
S: Instance specific
S: Invalid
S: Needs Voting/Discussion
S: Ready for review
Suggestion
S: Voted on Loomio
S: Wontfix
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: Plume/Plume#462
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "refactor/clippy"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
We add clippy as our build — also rectifying the missing
plume-clibuild!In the next step we follow clippy's advise and fix some of the "simple" mistakes in our code, such as style or map usage.
Finally, we refactor some hard bits that need extraction of new types, or refactoring of function call-types, especially those that thread thru macros, and, of course functions with ~15 parameters should probably be rethought.
(Most functions with ~15 parameters are routes, we won't be able to fix these warnings)
Codecov Report
couldn't we extract some of those parameters into a Struct?
We could create a struct containing
DbConn,Worker,I18n,SearcherandOption<User>(current connected user). Most routes requires at least 3 of these, so requires allI'm thinking of this:
i'm not sure about the name of the
structyet (or where to put it)Really looks better! I'm not 100% sure about the
PlumeRocketname, I would have named itAppStateor something like that, but I don't know maybe it's not really important. Otherwise it is really great as I said. 👍@ -33,3 +33,4 @@let intl = rockets.intl;Ok(render!(blogs::details(&(&*conn, &intl.catalog, user.clone()),Maybe Rust supports destructuring (I don't remember to be honest, so you could try to do:
@ -123,3 +131,3 @@#[post("/~/<name>/delete")]pub fn delete(conn: DbConn, name: String, user: Option<User>, intl: I18n, searcher: Searcher) -> Result<Redirect, Ructe>{pub fn delete(name: String, rockets: PlumeRocket) -> Result<Redirect, Ructe>{Maybe in another PR (because I think it is a bit out of scope for this one), we could replace all the "login required" routes with something like:
(I don't remember if
ok_oris the correct function to use here, but I think you got what I wanted to do)@ -1,3 +1,4 @@#![warn(clippy::too_many_arguments)]use atom_syndication::{ContentBuilder, Entry, EntryBuilder, LinkBuilder, Person, PersonBuilder};use rocket::{http::{have you tried asking for a PlumeRocket while not logged in? I think this would fail because of this line
There is a lot of work in there.
The only truly blocking thing is PlumeRocket's guard failing when user is not logged in, I through you had fixed that but apparently you didn't yet
@ -323,4 +327,4 @@impl ToString for PlumeQuery {fn to_string(&self) -> String {let mut result = String::new();seeing
parse_query, I think this function could be moved into it, and then we can callparse_queryinstead offrom_str_req@ -33,3 +33,4 @@let intl = rockets.intl;Ok(render!(blogs::details(&(&*conn, &intl.catalog, user.clone()),Your syntax is not right, but there is a way https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=572b846e985d4780607766e40563e6ba
(This is supposed to be a reply to https://github.com/Plume-org/Plume/pull/462#discussion_r265160941 but I failed apparently)
These could be
Searcher<'a>andWorker<'a>instead ofOption<...>@ -1,3 +1,4 @@#![warn(clippy::too_many_arguments)]use atom_syndication::{ContentBuilder, Entry, EntryBuilder, LinkBuilder, Person, PersonBuilder};use rocket::{http::{up
👍
I'm not sure this kind of comments should reach master?
👍