From 7f4e6d5bdaef8ad38df3d0d99c032d3f92e9a575 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Thu, 2 Mar 2023 18:08:23 +0530 Subject: [PATCH] chore: lints --- Cargo.lock | 1 + api_routes/src/lib.rs | 4 ++-- build.rs | 2 +- db/db-core/src/lib.rs | 16 ++++++++-------- db/db-core/src/tests.rs | 12 ++++++------ db/db-sqlx-sqlite/src/lib.rs | 8 ++++---- federate/publiccodeyml/src/lib.rs | 6 +++--- federate/publiccodeyml/src/schema.rs | 8 ++------ forge/gitea/src/schema.rs | 12 ++++++------ src/dns/mod.rs | 2 +- src/introduce.rs | 6 +++--- src/pages/auth/add.rs | 4 ++-- src/pages/auth/verify.rs | 2 +- src/pages/chart/home.rs | 6 +++--- src/settings.rs | 22 +++++++++++----------- src/tests.rs | 8 ++++---- src/verify.rs | 2 -- 17 files changed, 58 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index be14cfa..9ab6877 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -311,6 +311,7 @@ dependencies = [ name = "api_routes" version = "0.1.0" dependencies = [ + "db-core", "serde", ] diff --git a/api_routes/src/lib.rs b/api_routes/src/lib.rs index a4a8438..dafe709 100644 --- a/api_routes/src/lib.rs +++ b/api_routes/src/lib.rs @@ -86,12 +86,12 @@ pub struct LatestResp { pub latest: String, } -#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)] +#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)] pub struct SearchRepositoryReq { pub query: String, } -#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)] +#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)] pub struct SearchRepositoryResp { pub repositories: Vec, } diff --git a/build.rs b/build.rs index b6b8480..531d0b3 100644 --- a/build.rs +++ b/build.rs @@ -20,7 +20,7 @@ use std::process::Command; fn main() { let output = Command::new("git") - .args(&["rev-parse", "HEAD"]) + .args(["rev-parse", "HEAD"]) .output() .expect("error in git command, is git installed?"); let git_hash = String::from_utf8(output.stdout).unwrap(); diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs index f0c16bb..62f7772 100644 --- a/db/db-core/src/lib.rs +++ b/db/db-core/src/lib.rs @@ -58,14 +58,14 @@ pub mod dev { pub use async_trait::async_trait; } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] /// Data related to a Starchart instance pub struct Starchart { /// URL of the Starchart instance pub instance_url: String, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] /// create a new forge on the database pub struct CreateForge<'a> { /// url of the Starchart instance @@ -88,7 +88,7 @@ pub fn clean_url(url: &Url) -> String { url.as_str().to_string() } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] /// user data pub struct User { /// url of the forge instance: with scheme but remove trailing slash @@ -104,7 +104,7 @@ pub struct User { pub import: bool, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] /// add new user to database pub struct AddUser<'a> { /// url of the forge instance: with scheme but remove trailing slash @@ -120,7 +120,7 @@ pub struct AddUser<'a> { pub import: bool, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] /// add new repository to database pub struct AddRepository<'a> { /// html link to the repository @@ -142,7 +142,7 @@ pub struct AddRepository<'a> { pub import: bool, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] /// data representing a forge instance pub struct Forge { /// url of the Starchart instance @@ -157,7 +157,7 @@ pub struct Forge { pub last_crawl_on: Option, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] /// repository pub struct Repository { /// html link to the repository @@ -295,7 +295,7 @@ impl Clone for Box { } /// Forge type: Gitea, Sourcehut, GitLab, etc. Support is currently only available for Gitea -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum ForgeImplementation { /// [Gitea](https://gitea.io) softare forge diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs index dd8016d..08b4155 100644 --- a/db/db-core/src/tests.rs +++ b/db/db-core/src/tests.rs @@ -67,7 +67,7 @@ pub async fn adding_forge_works<'a, T: SCDatabase>( .await .unwrap()); assert!(db - .is_word_mini_indexed(&add_user_msg2.username) + .is_word_mini_indexed(add_user_msg2.username) .await .unwrap()); @@ -78,18 +78,18 @@ pub async fn adding_forge_works<'a, T: SCDatabase>( .repository_exists(add_repo_msg.name, add_repo_msg.owner, &add_repo_msg.url) .await .unwrap()); - assert!(db.is_word_mini_indexed(&add_repo_msg.owner).await.unwrap()); - assert!(db.is_word_mini_indexed(&add_repo_msg.name).await.unwrap()); + assert!(db.is_word_mini_indexed(add_repo_msg.owner).await.unwrap()); + assert!(db.is_word_mini_indexed(add_repo_msg.name).await.unwrap()); assert!(db - .is_word_mini_indexed(&add_repo_msg.description.unwrap()) + .is_word_mini_indexed(add_repo_msg.description.unwrap()) .await .unwrap()); assert!(db - .is_word_mini_indexed(&add_repo_msg.website.unwrap()) + .is_word_mini_indexed(add_repo_msg.website.unwrap()) .await .unwrap()); - assert!(db.get_all_repositories(00, 1000).await.unwrap().len() >= 1); + assert!(!db.get_all_repositories(00, 1000).await.unwrap().is_empty()); let repo_search = db.search_repository(add_repo_msg.name).await.unwrap(); assert!(!repo_search.is_empty()); diff --git a/db/db-sqlx-sqlite/src/lib.rs b/db/db-sqlx-sqlite/src/lib.rs index a902e53..dcb7bc1 100644 --- a/db/db-sqlx-sqlite/src/lib.rs +++ b/db/db-sqlx-sqlite/src/lib.rs @@ -186,8 +186,8 @@ impl Database { for repo in repositories.drain(0..) { self.new_fts_repositories( &repo.name, - repo.description.as_ref().map(|d| d.as_str()), - repo.website.as_ref().map(|s| s.as_str()), + repo.description.as_deref(), + repo.website.as_deref(), &repo.html_url, ) .await?; @@ -675,7 +675,7 @@ impl SCDatabase for Database { /// delete user async fn delete_user(&self, username: &str, url: &Url) -> DBResult<()> { - let user = self.get_user(username, &url).await?; + let user = self.get_user(username, url).await?; self.rm_word_from_mini_index(&user.username).await?; let url = db_core::clean_url(url); @@ -980,7 +980,7 @@ impl SCDatabase for Database { mini_index: &str, ) -> DBResult<()> { // delete old index before importing fresh index - let _ = self.rm_imported_mini_index(&starchart_instance_url).await; + let _ = self.rm_imported_mini_index(starchart_instance_url).await; let url = db_core::clean_url(starchart_instance_url); sqlx::query!( "INSERT OR IGNORE INTO diff --git a/federate/publiccodeyml/src/lib.rs b/federate/publiccodeyml/src/lib.rs index 1b714c0..8729451 100644 --- a/federate/publiccodeyml/src/lib.rs +++ b/federate/publiccodeyml/src/lib.rs @@ -306,7 +306,7 @@ impl Federate for PccFederate { /// import archive from another Starchart instance async fn import( &self, - mut starchart_url: Url, + starchart_url: Url, client: &Client, db: &Box, ) -> Result<(), Self::Error> { @@ -365,7 +365,7 @@ impl Federate for PccFederate { let user_file = instance_dir_entry .path() - .join(&username) + .join(username) .join(USER_INFO_FILE); let user_file_content = fs::read_to_string(user_file).await.unwrap(); let mut user: AddUser<'_> = serde_yaml::from_str(&user_file_content).unwrap(); @@ -376,7 +376,7 @@ impl Federate for PccFederate { if !self.user_exists(username, &instance.url).await.unwrap() { let user_file = instance_dir_entry .path() - .join(&username) + .join(username) .join(USER_INFO_FILE); let user_file_content = fs::read_to_string(user_file).await.unwrap(); let mut user: AddUser<'_> = serde_yaml::from_str(&user_file_content).unwrap(); diff --git a/federate/publiccodeyml/src/schema.rs b/federate/publiccodeyml/src/schema.rs index bfd5214..fd805b0 100644 --- a/federate/publiccodeyml/src/schema.rs +++ b/federate/publiccodeyml/src/schema.rs @@ -145,16 +145,12 @@ impl Repository { .get("en") .as_ref() .unwrap() - .short_description - .as_ref() - .map(|s| s.as_str()); + .short_description.as_deref(); let website = self .description .get("en") .unwrap() - .documentation - .as_ref() - .map(|s| s.as_str()); + .documentation.as_deref(); AddRepository { html_link: self.url.as_str(), tags, diff --git a/forge/gitea/src/schema.rs b/forge/gitea/src/schema.rs index 7d28d97..233fe84 100644 --- a/forge/gitea/src/schema.rs +++ b/forge/gitea/src/schema.rs @@ -95,21 +95,21 @@ pub struct Repository { pub repo_transfer: Option, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct InternalIssueTracker { pub enable_time_tracker: bool, pub allow_only_contributors_to_track_time: bool, pub enable_issue_dependencies: bool, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct RepoTransfer { pub doer: User, pub recipient: User, pub teams: Option, } -#[derive(Debug, Clone, PartialEq, Serialize, Hash, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Hash, Deserialize)] pub struct Organization { pub avatar_url: String, pub description: String, @@ -122,7 +122,7 @@ pub struct Organization { pub website: String, } -#[derive(Debug, Clone, PartialEq, Serialize, Hash, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Hash, Deserialize)] #[serde(rename_all = "lowercase")] pub enum Permission { None, @@ -132,7 +132,7 @@ pub enum Permission { Owner, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Team { pub can_create_org_repo: bool, pub description: String, @@ -145,7 +145,7 @@ pub struct Team { pub units_map: HashMap, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Topics { pub topics: Vec, } diff --git a/src/dns/mod.rs b/src/dns/mod.rs index cedfa19..a268552 100644 --- a/src/dns/mod.rs +++ b/src/dns/mod.rs @@ -17,7 +17,7 @@ */ use serde::{Deserialize, Serialize}; -#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, Default, PartialEq, Eq, Clone, Serialize, Deserialize)] pub struct Configuration { pub spidering: bool, pub rate: Option, diff --git a/src/introduce.rs b/src/introduce.rs index a696e23..16ef046 100644 --- a/src/introduce.rs +++ b/src/introduce.rs @@ -17,7 +17,7 @@ */ use std::collections::HashSet; -use actix_web::web::{self, get}; +use actix_web::web; use actix_web::{HttpResponse, Responder}; use actix_web_codegen_const_routes::get; use actix_web_codegen_const_routes::post; @@ -145,8 +145,8 @@ impl Ctx { } self.import_forges(node_url, db).await?; let mini_index = self.client_get_mini_index(starchart.clone()).await?; - db.rm_imported_mini_index(&starchart).await?; - db.import_mini_index(&starchart, &mini_index.mini_index) + db.rm_imported_mini_index(starchart).await?; + db.import_mini_index(starchart, &mini_index.mini_index) .await?; } page += 1; diff --git a/src/pages/auth/add.rs b/src/pages/auth/add.rs index 877af18..233fceb 100644 --- a/src/pages/auth/add.rs +++ b/src/pages/auth/add.rs @@ -43,7 +43,7 @@ impl CtxError for AddChallenge { } } -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] pub struct AddChallengePayload { pub hostname: Url, } @@ -84,7 +84,7 @@ pub fn services(cfg: &mut web::ServiceConfig) { pub async fn add_submit( payload: web::Form, ) -> PageResult { - let link = PAGES.auth.verify_get(&payload.hostname.to_string()); + let link = PAGES.auth.verify_get(payload.hostname.as_ref()); Ok(HttpResponse::Found() .insert_header((http::header::LOCATION, link)) diff --git a/src/pages/auth/verify.rs b/src/pages/auth/verify.rs index 688b1f0..4603354 100644 --- a/src/pages/auth/verify.rs +++ b/src/pages/auth/verify.rs @@ -45,7 +45,7 @@ impl CtxError for VerifyChallenge { } } -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] pub struct VerifyChallengePayload { pub hostname: Url, } diff --git a/src/pages/chart/home.rs b/src/pages/chart/home.rs index 823fb46..396e879 100644 --- a/src/pages/chart/home.rs +++ b/src/pages/chart/home.rs @@ -47,7 +47,7 @@ impl CtxError for HomePage { } } -#[derive(Clone, Debug, PartialEq, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, Default, Deserialize, Serialize)] pub struct HomePagePayload { pub repos: Vec, pub next_page: String, @@ -76,7 +76,7 @@ pub fn services(cfg: &mut web::ServiceConfig) { cfg.service(home); } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Page { pub page: u32, } @@ -95,7 +95,7 @@ impl Page { } } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct OptionalPage { pub page: Option, } diff --git a/src/settings.rs b/src/settings.rs index b9ee4e2..3616832 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -25,7 +25,7 @@ use serde::{Deserialize, Serialize}; use url::Url; use validator::Validate; -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Server { pub port: u32, pub domain: String, @@ -40,7 +40,7 @@ impl Server { } } -#[derive(Debug, Display, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Display, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum LogLevel { #[display(fmt = "debug")] @@ -64,7 +64,7 @@ impl LogLevel { } } -#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] +#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)] pub struct Repository { pub root: String, } @@ -74,11 +74,11 @@ impl Repository { let root = Path::new(&self.root); if root.exists() { if !root.is_dir() { - fs::remove_file(&root).unwrap(); - fs::create_dir_all(&root).unwrap(); + fs::remove_file(root).unwrap(); + fs::create_dir_all(root).unwrap(); } } else { - fs::create_dir_all(&root).unwrap(); + fs::create_dir_all(root).unwrap(); } self.create_license_file(); } @@ -102,7 +102,7 @@ impl Repository { } } -#[derive(Debug, Display, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Display, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum DBType { #[display(fmt = "postgres")] @@ -111,14 +111,14 @@ pub enum DBType { Sqlite, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Database { pub url: String, pub pool: u32, pub database_type: DBType, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Crawler { pub ttl: u64, pub client_timeout: u64, @@ -126,13 +126,13 @@ pub struct Crawler { pub wait_before_next_api_call: u64, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Introducer { pub nodes: Vec, pub public_url: Url, } -#[derive(Debug, Validate, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Validate, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Settings { pub log: LogLevel, pub database: Database, diff --git a/src/tests.rs b/src/tests.rs index 79a9719..e3f3d96 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -141,7 +141,7 @@ macro_rules! get_app { .wrap(actix_web::middleware::NormalizePath::new( actix_web::middleware::TrailingSlash::Trim, )) - .configure(crate::routes::services) + .configure($crate::routes::services) }; ($settings:ident) => { @@ -150,9 +150,9 @@ macro_rules! get_app { ($ctx:expr, $db:expr, $federate:expr) => { test::init_service( get_app!("APP", &$ctx.settings) - .app_data(crate::WebDB::new($db.clone())) - .app_data(crate::WebCtx::new($ctx.clone())) - .app_data(crate::WebFederate::new($federate.clone())), + .app_data($crate::WebDB::new($db.clone())) + .app_data($crate::WebCtx::new($ctx.clone())) + .app_data($crate::WebFederate::new($federate.clone())), ) }; } diff --git a/src/verify.rs b/src/verify.rs index 616720d..2c6b50c 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -41,8 +41,6 @@ pub struct TXTChallenge { pub value: String, } -const VALUES_LEN: usize = 30; - impl TXTChallenge { pub fn get_challenge_txt_key_prefix(ctx: &ArcCtx) -> String { // starchart-{{ starchart instance's hostname}}.{{ forge instance's hostname }}