From 2d5c91a5efa71c2e32ab966c23dabd6c85fd5252 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Wed, 18 Dec 2024 22:27:25 +0000 Subject: [PATCH] More lints --- backend/fuzz/Cargo.toml | 3 ++ backend/fuzz/fuzz_targets/reconcile.rs | 2 +- .../reconcile/src/operation_transformation.rs | 5 ++-- .../src/operation_transformation/operation.rs | 3 +- backend/sync_server/src/errors.rs | 2 +- backend/sync_server/src/server.rs | 2 +- .../sync_server/src/server/update_document.rs | 30 +++++++++++-------- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/backend/fuzz/Cargo.toml b/backend/fuzz/Cargo.toml index d69b009..c8ed165 100644 --- a/backend/fuzz/Cargo.toml +++ b/backend/fuzz/Cargo.toml @@ -17,3 +17,6 @@ path = "fuzz_targets/reconcile.rs" test = false doc = false bench = false + +[lints] +workspace = true diff --git a/backend/fuzz/fuzz_targets/reconcile.rs b/backend/fuzz/fuzz_targets/reconcile.rs index e986ccb..b97c782 100644 --- a/backend/fuzz/fuzz_targets/reconcile.rs +++ b/backend/fuzz/fuzz_targets/reconcile.rs @@ -5,5 +5,5 @@ extern crate reconcile; fuzz_target!(|texts: (String, String, String)| { let (original, left, right) = texts; - reconcile::reconcile(&original, &left, &right); + let _ = reconcile::reconcile(&original, &left, &right); }); diff --git a/backend/reconcile/src/operation_transformation.rs b/backend/reconcile/src/operation_transformation.rs index e4f1d7c..6cad9d6 100644 --- a/backend/reconcile/src/operation_transformation.rs +++ b/backend/reconcile/src/operation_transformation.rs @@ -7,7 +7,8 @@ pub use operation::Operation; use crate::tokenizer::Tokenizer; -#[must_use] pub fn reconcile(original: &str, left: &str, right: &str) -> String { +#[must_use] +pub fn reconcile(original: &str, left: &str, right: &str) -> String { if left == right { return left.to_owned(); } @@ -188,7 +189,7 @@ mod test { }) .collect::>(); - reconcile(&contents[0], &contents[1], &contents[2]); + let _ = reconcile(&contents[0], &contents[1], &contents[2]); } fn test_merge_both_ways(original: &str, edit_1: &str, edit_2: &str, expected: &str) { diff --git a/backend/reconcile/src/operation_transformation/operation.rs b/backend/reconcile/src/operation_transformation/operation.rs index d83d2d2..bac6972 100644 --- a/backend/reconcile/src/operation_transformation/operation.rs +++ b/backend/reconcile/src/operation_transformation/operation.rs @@ -110,8 +110,7 @@ where #[cfg(debug_assertions)] debug_assert!( deleted_text - .as_ref() - .map_or(true, |text| builder.get_slice(self.range()) == *text), + .as_ref().is_none_or(|text| builder.get_slice(self.range()) == *text), "Text to delete does not match the text in the rope" ); diff --git a/backend/sync_server/src/errors.rs b/backend/sync_server/src/errors.rs index 13a35aa..b97aadc 100644 --- a/backend/sync_server/src/errors.rs +++ b/backend/sync_server/src/errors.rs @@ -26,7 +26,6 @@ pub enum SyncServerError { #[error("Unauthorized: {0}")] Unauthorized(#[source] anyhow::Error), - #[expect(dead_code)] #[error("Permission denied error: {0}")] PermissionDeniedError(#[source] anyhow::Error), } @@ -107,6 +106,7 @@ pub fn unauthorized_error(error: anyhow::Error) -> SyncServerError { SyncServerError::Unauthorized(error) } +#[allow(dead_code)] pub fn permission_denied_error(error: anyhow::Error) -> SyncServerError { info!("Permission denied error: {:?}", error); SyncServerError::PermissionDeniedError(error) diff --git a/backend/sync_server/src/server.rs b/backend/sync_server/src/server.rs index e668447..7ebe789 100644 --- a/backend/sync_server/src/server.rs +++ b/backend/sync_server/src/server.rs @@ -70,7 +70,7 @@ pub async fn create_server(app_state: AppState) -> Result<()> { )) .layer( CorsLayer::new() - .allow_origin("*".parse::().unwrap()) + .allow_origin("*".parse::().expect("Failed to parse origin")) .allow_headers([http::header::CONTENT_TYPE, http::header::AUTHORIZATION]) .allow_methods([Method::GET, Method::POST, Method::PUT, Method::DELETE]), ) diff --git a/backend/sync_server/src/server/update_document.rs b/backend/sync_server/src/server/update_document.rs index 31358a3..7e4f4dc 100644 --- a/backend/sync_server/src/server/update_document.rs +++ b/backend/sync_server/src/server/update_document.rs @@ -44,13 +44,15 @@ pub async fn update_document( .get_document_version(&vault_id, request.parent_version_id, None) .await .map_err(server_error)? - .map(Ok) - .unwrap_or_else(|| { - Err(not_found_error(anyhow!( - "Parent version with id `{}` not found", - request.parent_version_id - ))) - })?; + .map_or_else( + || { + Err(not_found_error(anyhow!( + "Parent version with id `{}` not found", + request.parent_version_id + ))) + }, + Ok, + )?; let mut transaction = state .database @@ -69,12 +71,14 @@ pub async fn update_document( .get_latest_document(&vault_id, &document_id, Some(&mut transaction)) .await .map_err(server_error)? - .map(Ok) - .unwrap_or_else(|| { - Err(not_found_error(anyhow!( - "Document with id `{document_id}` not found", - ))) - })?; + .map_or_else( + || { + Err(not_found_error(anyhow!( + "Document with id `{document_id}` not found", + ))) + }, + Ok, + )?; let content_bytes = base64_to_bytes(&request.content_base64) .context("Failed to decode base64 content in request")