From f3d48f2c2c918f3b2ef91c295a805c8a00895c81 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 26 Feb 2024 09:47:10 -0500 Subject: [PATCH] Adding some recommended fixes from nightly clippy. (#4473) --- crates/api_common/src/utils.rs | 2 -- crates/apub/src/http/community.rs | 5 +---- crates/apub/src/objects/community.rs | 2 +- crates/apub/src/objects/instance.rs | 1 - crates/apub/src/objects/person.rs | 2 +- crates/apub/src/objects/post.rs | 2 -- .../src/protocol/activities/voting/vote.rs | 1 - crates/db_schema/src/impls/actor_language.rs | 20 +++---------------- crates/db_schema/src/utils.rs | 9 +++------ crates/utils/src/error.rs | 2 +- 10 files changed, 10 insertions(+), 36 deletions(-) diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index 138364c84..25dc10344 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -967,8 +967,6 @@ mod tests { #![allow(clippy::indexing_slicing)] use super::*; - use crate::utils::{honeypot_check, limit_expire_time, password_length_check}; - use chrono::{Days, Utc}; use pretty_assertions::assert_eq; use serial_test::serial; diff --git a/crates/apub/src/http/community.rs b/crates/apub/src/http/community.rs index e5c18a6ce..73e620dbe 100644 --- a/crates/apub/src/http/community.rs +++ b/crates/apub/src/http/community.rs @@ -123,10 +123,7 @@ pub(crate) mod tests { use crate::protocol::objects::{group::Group, tombstone::Tombstone}; use actix_web::body::to_bytes; use lemmy_db_schema::{ - source::{ - community::{Community, CommunityInsertForm}, - instance::Instance, - }, + source::{community::CommunityInsertForm, instance::Instance}, traits::Crud, CommunityVisibility, }; diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 36f26a9f4..ad8472915 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -257,7 +257,7 @@ pub(crate) mod tests { protocol::tests::file_to_json_object, }; use activitypub_federation::fetch::collection_id::CollectionId; - use lemmy_db_schema::{source::site::Site, traits::Crud}; + use lemmy_db_schema::source::site::Site; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; use serial_test::serial; diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index 61a70f6ea..165378ab6 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -218,7 +218,6 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object + C pub(crate) mod tests { use super::*; use crate::protocol::tests::file_to_json_object; - use lemmy_db_schema::traits::Crud; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; use serial_test::serial; diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index 8e0d335bc..7bfb68a04 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -225,7 +225,7 @@ pub(crate) mod tests { protocol::{objects::instance::Instance, tests::file_to_json_object}, }; use activitypub_federation::fetch::object_id::ObjectId; - use lemmy_db_schema::{source::site::Site, traits::Crud}; + use lemmy_db_schema::source::site::Site; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; use serial_test::serial; diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 94d240bfa..681fef2c4 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -34,7 +34,6 @@ use lemmy_api_common::{ }, }; use lemmy_db_schema::{ - self, source::{ community::Community, local_site::LocalSite, @@ -297,7 +296,6 @@ mod tests { community::{tests::parse_lemmy_community, ApubCommunity}, instance::ApubSite, person::{tests::parse_lemmy_person, ApubPerson}, - post::ApubPost, }, protocol::tests::file_to_json_object, }; diff --git a/crates/apub/src/protocol/activities/voting/vote.rs b/crates/apub/src/protocol/activities/voting/vote.rs index 0c199c729..013c15bfd 100644 --- a/crates/apub/src/protocol/activities/voting/vote.rs +++ b/crates/apub/src/protocol/activities/voting/vote.rs @@ -8,7 +8,6 @@ use activitypub_federation::{config::Data, fetch::object_id::ObjectId}; use lemmy_api_common::context::LemmyContext; use lemmy_utils::error::{LemmyError, LemmyErrorType}; use serde::{Deserialize, Serialize}; -use std::convert::TryFrom; use strum_macros::Display; use url::Url; diff --git a/crates/db_schema/src/impls/actor_language.rs b/crates/db_schema/src/impls/actor_language.rs index 1f8fa2e91..1cb5f4c77 100644 --- a/crates/db_schema/src/impls/actor_language.rs +++ b/crates/db_schema/src/impls/actor_language.rs @@ -306,9 +306,9 @@ impl CommunityLanguage { // tracing::warn!("unique error: {_info:#?}"); // _info.constraint_name() should be = "community_language_community_id_language_id_key" return Ok(()); - } else { - insert_res?; } + insert_res?; + Ok(()) }) as _ }) @@ -391,27 +391,13 @@ mod tests { use super::*; use crate::{ - impls::actor_language::{ - convert_read_languages, - convert_update_languages, - default_post_language, - get_conn, - CommunityLanguage, - DbPool, - Language, - LanguageId, - LocalUserLanguage, - QueryDsl, - RunQueryDsl, - SiteLanguage, - }, source::{ community::{Community, CommunityInsertForm}, instance::Instance, local_site::{LocalSite, LocalSiteInsertForm}, local_user::{LocalUser, LocalUserInsertForm}, person::{Person, PersonInsertForm}, - site::{Site, SiteInsertForm}, + site::SiteInsertForm, }, traits::Crud, utils::build_db_pool_for_tests, diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 6afc850b5..038ab129a 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -248,9 +248,8 @@ pub fn limit_and_offset( Some(page) => { if page < 1 { return Err(QueryBuilderError("Page is < 1".into())); - } else { - page } + page } None => 1, }; @@ -260,9 +259,8 @@ pub fn limit_and_offset( return Err(QueryBuilderError( format!("Fetch limit is > {FETCH_LIMIT_MAX}").into(), )); - } else { - limit } + limit } None => FETCH_LIMIT_DEFAULT, }; @@ -542,8 +540,7 @@ mod tests { #![allow(clippy::unwrap_used)] #![allow(clippy::indexing_slicing)] - use super::{fuzzy_search, *}; - use crate::utils::is_email_regex; + use super::*; use pretty_assertions::assert_eq; #[test] diff --git a/crates/utils/src/error.rs b/crates/utils/src/error.rs index a4ee4ee7d..0f68d70da 100644 --- a/crates/utils/src/error.rs +++ b/crates/utils/src/error.rs @@ -2,7 +2,7 @@ use cfg_if::cfg_if; use serde::{Deserialize, Serialize}; use std::fmt::Debug; use strum_macros::{Display, EnumIter}; -#[cfg(feature = "full")] +#[cfg(feature = "ts-rs")] use ts_rs::TS; #[derive(Display, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, EnumIter, Hash)]