More lints

This commit is contained in:
Andras Schmelczer 2024-12-18 22:27:25 +00:00
commit 2d5c91a5ef
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
7 changed files with 27 additions and 20 deletions

View file

@ -17,3 +17,6 @@ path = "fuzz_targets/reconcile.rs"
test = false test = false
doc = false doc = false
bench = false bench = false
[lints]
workspace = true

View file

@ -5,5 +5,5 @@ extern crate reconcile;
fuzz_target!(|texts: (String, String, String)| { fuzz_target!(|texts: (String, String, String)| {
let (original, left, right) = texts; let (original, left, right) = texts;
reconcile::reconcile(&original, &left, &right); let _ = reconcile::reconcile(&original, &left, &right);
}); });

View file

@ -7,7 +7,8 @@ pub use operation::Operation;
use crate::tokenizer::Tokenizer; 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 { if left == right {
return left.to_owned(); return left.to_owned();
} }
@ -188,7 +189,7 @@ mod test {
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
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) { fn test_merge_both_ways(original: &str, edit_1: &str, edit_2: &str, expected: &str) {

View file

@ -110,8 +110,7 @@ where
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
debug_assert!( debug_assert!(
deleted_text deleted_text
.as_ref() .as_ref().is_none_or(|text| builder.get_slice(self.range()) == *text),
.map_or(true, |text| builder.get_slice(self.range()) == *text),
"Text to delete does not match the text in the rope" "Text to delete does not match the text in the rope"
); );

View file

@ -26,7 +26,6 @@ pub enum SyncServerError {
#[error("Unauthorized: {0}")] #[error("Unauthorized: {0}")]
Unauthorized(#[source] anyhow::Error), Unauthorized(#[source] anyhow::Error),
#[expect(dead_code)]
#[error("Permission denied error: {0}")] #[error("Permission denied error: {0}")]
PermissionDeniedError(#[source] anyhow::Error), PermissionDeniedError(#[source] anyhow::Error),
} }
@ -107,6 +106,7 @@ pub fn unauthorized_error(error: anyhow::Error) -> SyncServerError {
SyncServerError::Unauthorized(error) SyncServerError::Unauthorized(error)
} }
#[allow(dead_code)]
pub fn permission_denied_error(error: anyhow::Error) -> SyncServerError { pub fn permission_denied_error(error: anyhow::Error) -> SyncServerError {
info!("Permission denied error: {:?}", error); info!("Permission denied error: {:?}", error);
SyncServerError::PermissionDeniedError(error) SyncServerError::PermissionDeniedError(error)

View file

@ -70,7 +70,7 @@ pub async fn create_server(app_state: AppState) -> Result<()> {
)) ))
.layer( .layer(
CorsLayer::new() CorsLayer::new()
.allow_origin("*".parse::<HeaderValue>().unwrap()) .allow_origin("*".parse::<HeaderValue>().expect("Failed to parse origin"))
.allow_headers([http::header::CONTENT_TYPE, http::header::AUTHORIZATION]) .allow_headers([http::header::CONTENT_TYPE, http::header::AUTHORIZATION])
.allow_methods([Method::GET, Method::POST, Method::PUT, Method::DELETE]), .allow_methods([Method::GET, Method::POST, Method::PUT, Method::DELETE]),
) )

View file

@ -44,13 +44,15 @@ pub async fn update_document(
.get_document_version(&vault_id, request.parent_version_id, None) .get_document_version(&vault_id, request.parent_version_id, None)
.await .await
.map_err(server_error)? .map_err(server_error)?
.map(Ok) .map_or_else(
.unwrap_or_else(|| { || {
Err(not_found_error(anyhow!( Err(not_found_error(anyhow!(
"Parent version with id `{}` not found", "Parent version with id `{}` not found",
request.parent_version_id request.parent_version_id
))) )))
})?; },
Ok,
)?;
let mut transaction = state let mut transaction = state
.database .database
@ -69,12 +71,14 @@ pub async fn update_document(
.get_latest_document(&vault_id, &document_id, Some(&mut transaction)) .get_latest_document(&vault_id, &document_id, Some(&mut transaction))
.await .await
.map_err(server_error)? .map_err(server_error)?
.map(Ok) .map_or_else(
.unwrap_or_else(|| { || {
Err(not_found_error(anyhow!( Err(not_found_error(anyhow!(
"Document with id `{document_id}` not found", "Document with id `{document_id}` not found",
))) )))
})?; },
Ok,
)?;
let content_bytes = base64_to_bytes(&request.content_base64) let content_bytes = base64_to_bytes(&request.content_base64)
.context("Failed to decode base64 content in request") .context("Failed to decode base64 content in request")