From f9ecf600467a55c7add7b336897a36a541b603e4 Mon Sep 17 00:00:00 2001 From: Miroito Date: Mon, 24 Apr 2023 18:49:39 +0200 Subject: [PATCH] fix: Apply clippy suggestions --- Cargo.lock | 61 +--------------------- client/src/api/routes/transaction.rs | 6 +-- client/src/api/types/paginated_response.rs | 14 ++--- client/src/components/the_header.rs | 6 +-- client/src/templates/transactions.rs | 2 +- client/tests/index.rs | 6 +-- server/Cargo.toml | 1 - server/src/amf/service/information_req.rs | 8 +-- server/src/logger/mod.rs | 7 --- server/src/main.rs | 2 - server/src/task/mod.rs | 2 +- 11 files changed, 21 insertions(+), 94 deletions(-) delete mode 100644 server/src/logger/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 86dc8c8..f30fc7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,17 +228,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "debc29dde2e69f9e47506b525f639ed42300fc014a3e007832592448fa8e4599" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -900,19 +889,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "env_logger" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "envy" version = "0.4.2" @@ -1260,15 +1236,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.2.6" @@ -1333,15 +1300,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - [[package]] name = "hyper" version = "0.14.26" @@ -1763,7 +1721,7 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi", "libc", ] @@ -2079,16 +2037,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" -[[package]] -name = "pretty_env_logger" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" -dependencies = [ - "env_logger", - "log", -] - [[package]] name = "proc-macro-crate" version = "0.1.5" @@ -2157,12 +2105,6 @@ dependencies = [ "syn 1.0.108", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quote" version = "1.0.26" @@ -2767,7 +2709,6 @@ dependencies = [ "log", "lopdf", "migration", - "pretty_env_logger", "reqwest", "sea-orm", "serde", diff --git a/client/src/api/routes/transaction.rs b/client/src/api/routes/transaction.rs index 03bd5ce..ab22897 100644 --- a/client/src/api/routes/transaction.rs +++ b/client/src/api/routes/transaction.rs @@ -38,7 +38,7 @@ impl FastInsidersApi { .await .map_err(|_| ())?; - return Ok(res); + Ok(res) } pub async fn get_aggregated_transactions( @@ -72,7 +72,7 @@ impl FastInsidersApi { .await .map_err(|_| ())?; - return Ok(res); + Ok(res) } pub async fn get_latest_transactions( @@ -103,6 +103,6 @@ impl FastInsidersApi { .await .map_err(|_| ())?; - return Ok(res); + Ok(res) } } diff --git a/client/src/api/types/paginated_response.rs b/client/src/api/types/paginated_response.rs index 88a1cda..37c6d8f 100644 --- a/client/src/api/types/paginated_response.rs +++ b/client/src/api/types/paginated_response.rs @@ -9,7 +9,7 @@ pub trait IntoTableData where G: GenericNode, { - fn into_table_data<'a>(self, cx: Scope<'a>) -> TableContent; + fn into_table_data(self, cx: Scope) -> TableContent; } #[derive(Clone, Serialize, Deserialize)] @@ -23,7 +23,7 @@ impl IntoTableData for PaginatedResponse where G: GenericNode, { - fn into_table_data<'a>(self, cx: Scope<'a>) -> TableContent { + fn into_table_data(self, cx: Scope) -> TableContent { let headers_view = vec![ view! {cx, "Company" }, view! {cx, "Date published" }, @@ -45,7 +45,7 @@ where let mut res = vec![]; res.push(view! {cx, a (href=format!("transactions/{}", t.company.slug), - class="text-indigo-800 dark:text-indigo-300 hover:text-indigo-500 dark:hover:text-indigo-600 hover:underline", + class="text-indigo-800 dark:text-indigo-300 hover:text-indigo-500 hover:underline dark:hover:text-indigo-600", ) { (t.company.name.to_owned()) } @@ -76,7 +76,7 @@ impl IntoTableData for PaginatedResponse where G: GenericNode, { - fn into_table_data<'a>(self, cx: Scope<'a>) -> TableContent { + fn into_table_data(self, cx: Scope) -> TableContent { let headers_view = vec![ view! {cx, "Company" }, view! {cx, "Transactions" }, @@ -89,7 +89,7 @@ where let mut res = vec![]; res.push(view! {cx, a (href=format!("transactions/{}", t.slug), - class="text-indigo-800 dark:text-indigo-300 hover:text-indigo-500 dark:hover:text-indigo-600 hover:underline", + class="text-indigo-800 dark:text-indigo-300 hover:text-indigo-500 hover:underline dark:hover:text-indigo-600", ) { (t.name.to_owned()) } @@ -111,7 +111,7 @@ impl IntoTableData for PaginatedResponse where G: GenericNode, { - fn into_table_data<'a>(self, cx: Scope<'a>) -> TableContent { + fn into_table_data(self, cx: Scope) -> TableContent { let headers_view = vec![ view! {cx, "Company" }, view! {cx, "nature" }, @@ -125,7 +125,7 @@ where let mut res = vec![]; res.push(view! {cx, a (href=format!("transactions/{}", t.slug), - class="text-indigo-800 dark:text-indigo-300 hover:text-indigo-500 dark:hover:text-indigo-600 hover:underline", + class="text-indigo-800 dark:text-indigo-300 hover:text-indigo-500 hover:underline dark:hover:text-indigo-600", ) { (t.company_name.to_owned()) } diff --git a/client/src/components/the_header.rs b/client/src/components/the_header.rs index bd489ca..da83957 100644 --- a/client/src/components/the_header.rs +++ b/client/src/components/the_header.rs @@ -4,7 +4,7 @@ use sycamore::prelude::*; use crate::global_state::AppStateRx; #[component] -pub fn TheHeader<'a, G: Html>(cx: Scope<'a>) -> View { +pub fn TheHeader(cx: Scope) -> View { // This is ugly and is only caused by the get_global_state function panicking when running on the server at build time let global_state_sig: &Signal> = create_signal(cx, None); @@ -15,7 +15,7 @@ pub fn TheHeader<'a, G: Html>(cx: Scope<'a>) -> View { let dark_mode = create_signal(cx, true); create_effect(cx, move || { - if let Some(gstate) = (*global_state_sig.get()).clone() { + if let Some(gstate) = *global_state_sig.get() { dark_mode.set(*gstate.dark_mode.get()); } }); @@ -26,7 +26,7 @@ pub fn TheHeader<'a, G: Html>(cx: Scope<'a>) -> View { }; view! { cx, - header (class="shadow-md h-11 p-2 align-middle w-full bg-gray-100 dark:bg-slate-500/30 backdrop-blur-lg") { + header (class="p-2 w-full h-11 align-middle bg-gray-100 shadow-md backdrop-blur-lg dark:bg-slate-500/30") { div (class="flex") { div (class="flex-none mr-12") { a (href="/", class="hover:underline") { diff --git a/client/src/templates/transactions.rs b/client/src/templates/transactions.rs index ff407a9..b30b2d0 100644 --- a/client/src/templates/transactions.rs +++ b/client/src/templates/transactions.rs @@ -49,7 +49,7 @@ fn transactions_page<'a, G: Html>(cx: Scope, state: &TransactionsPageStateRx) -> let route_ref = create_ref(cx, |n, l| api_scope_ref.get_company_by_name(n, l)); let async_select_prop: AsyncSelectRx<_, _, _> = AsyncSelectRx { - route: create_ref(cx, |n, l| api_scope_ref.get_company_by_name(n, l)), + route: route_ref, selected_item: create_signal(cx, None), }; diff --git a/client/tests/index.rs b/client/tests/index.rs index a722b4f..79c9a0f 100644 --- a/client/tests/index.rs +++ b/client/tests/index.rs @@ -52,7 +52,7 @@ async fn index(c: &mut Client) -> Result<(), fantoccini::error::CmdError> { .select_by_value(&page_size.to_string()) .await?; - let table_rows = c.find_all(Locator::Css("table tr")).await?.iter().count(); + let table_rows = c.find_all(Locator::Css("table tr")).await?.len(); let page_size_select = c.find(Locator::Css("#size-select")).await?; let browser_page_size = page_size_select .prop("value") @@ -71,7 +71,7 @@ async fn index(c: &mut Client) -> Result<(), fantoccini::error::CmdError> { .await? .text() .await? - .split("/") + .split('/') .map(|x| x.parse().unwrap()) .collect::>(); assert_eq!(page_numbers[0], 1); @@ -81,7 +81,7 @@ async fn index(c: &mut Client) -> Result<(), fantoccini::error::CmdError> { .await? .text() .await? - .split("/") + .split('/') .map(|x| x.parse().unwrap()) .collect::>(); assert_eq!(new_page_numbers[0], page_numbers[0] + 1); diff --git a/server/Cargo.toml b/server/Cargo.toml index f9e8efe..bbc7a45 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -25,7 +25,6 @@ sea-orm = { version = "0.11.0", features = [ lopdf = "0.29.0" bytes = { version = "1.3.0", features = ["serde"] } lazy_static = "1.4.0" -pretty_env_logger = "0.4.0" log = "0.4.17" futures = "0.3.25" async-trait = "0.1.61" diff --git a/server/src/amf/service/information_req.rs b/server/src/amf/service/information_req.rs index 3bbb3f3..f194cee 100644 --- a/server/src/amf/service/information_req.rs +++ b/server/src/amf/service/information_req.rs @@ -41,16 +41,12 @@ impl AMFRequest { } } +#[derive(Default)] pub enum AMFRequestType { + #[default] DD, } -impl Default for AMFRequestType { - fn default() -> Self { - AMFRequestType::DD - } -} - impl fmt::Display for AMFRequestType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/server/src/logger/mod.rs b/server/src/logger/mod.rs deleted file mode 100644 index 050a88a..0000000 --- a/server/src/logger/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -extern crate pretty_env_logger; -use log::SetLoggerError; - -/// For this function to do anything the RUST_LOG environment variable should be set. -pub fn init_log() -> Result<(), SetLoggerError> { - pretty_env_logger::try_init_timed() -} diff --git a/server/src/main.rs b/server/src/main.rs index acf6b65..1b70a73 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -3,7 +3,6 @@ // Macros #[macro_use] extern crate lazy_static; -extern crate pretty_env_logger; #[macro_use] extern crate log; @@ -30,7 +29,6 @@ mod amf; mod db; mod env; mod error; -mod logger; mod model; mod repo; mod route; diff --git a/server/src/task/mod.rs b/server/src/task/mod.rs index bd605ed..e046090 100644 --- a/server/src/task/mod.rs +++ b/server/src/task/mod.rs @@ -21,7 +21,7 @@ pub async fn run_tasks(tasks_pool: &DatabaseConnection) -> Result<(), sea_orm::D loop { inter.tick().await; info!("Running task: getamftransactions"); - match GetAMFTransactions::new(1000).run(&tasks_pool).await { + match GetAMFTransactions::new(1000).run(tasks_pool).await { Ok(_) => (), Err(e) => error!("Task failed: {}", e), }; -- 2.36.3