From 5fbeb79fdc9150fcfff5e98816227d55cf42ab1a Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 16 Nov 2025 15:40:28 +0000 Subject: [PATCH] Lint --- reconcile-js/tsconfig.json | 4 ++-- src/operation_transformation/edited_text.rs | 13 +++++++++++++ src/utils/myers_diff.rs | 9 ++++++--- src/wasm.rs | 7 ++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/reconcile-js/tsconfig.json b/reconcile-js/tsconfig.json index d275639..08dee60 100644 --- a/reconcile-js/tsconfig.json +++ b/reconcile-js/tsconfig.json @@ -8,6 +8,6 @@ "declaration": true, "declarationDir": "./dist/types", "skipLibCheck": true, - "inlineSourceMap": true, - }, + "inlineSourceMap": true + } } diff --git a/src/operation_transformation/edited_text.rs b/src/operation_transformation/edited_text.rs index 6b65a68..f27fea4 100644 --- a/src/operation_transformation/edited_text.rs +++ b/src/operation_transformation/edited_text.rs @@ -107,6 +107,11 @@ where /// from the same original text. The operations are merged using the /// principles of Operational Transformation. The cursors are updated /// accordingly to reflect the changes made by the merged operations. + /// + /// # Panics + /// + /// Panics if there's an integer overflow (in i64) when calculating new + /// cursor positions. #[must_use] #[allow(clippy::too_many_lines)] pub fn merge(self, other: Self) -> Self { @@ -356,6 +361,10 @@ where /// /// Inserts are represented as strings, deletes as negative integers, /// and equal spans as positive integers. + /// + /// # Panics + /// + /// Panics if there's an integer overflow in i64. #[must_use] pub fn to_diff(&self) -> Vec { let mut result: Vec = Vec::with_capacity(self.operations.len()); @@ -414,6 +423,10 @@ where } /// Deserialize an `EditedText` from a change list and the original text. + /// + /// # Panics + /// + /// Panics if there's an integer overflow in i64. #[must_use] pub fn from_diff( original_text: &'a str, diff --git a/src/utils/myers_diff.rs b/src/utils/myers_diff.rs index df2239a..c89788d 100644 --- a/src/utils/myers_diff.rs +++ b/src/utils/myers_diff.rs @@ -144,7 +144,8 @@ where // By Lemma 1 in the paper, the optimal edit script length is odd or even as // `delta` is odd or even. - let delta = isize::try_from(n).expect("n must fit in isize") - isize::try_from(m).expect("m must fit in isize"); + let delta = isize::try_from(n).expect("n must fit in isize") + - isize::try_from(m).expect("m must fit in isize"); let odd = delta & 1 == 1; // The initial point at (0, -1) @@ -165,7 +166,8 @@ where } else { vf[k - 1] + 1 }; - let y = usize::try_from(isize::try_from(x).expect("x must fit in isize") - k).expect("x - k must be non-negative and fit in usize"); + let y = usize::try_from(isize::try_from(x).expect("x must fit in isize") - k) + .expect("x - k must be non-negative and fit in usize"); // The coordinate of the start of a snake let (x0, y0) = (x, y); @@ -203,7 +205,8 @@ where } else { vb[k - 1] + 1 }; - let mut y = usize::try_from(isize::try_from(x).expect("x must fit in isize") - k).expect("x - k must be non-negative and fit in usize"); + let mut y = usize::try_from(isize::try_from(x).expect("x must fit in isize") - k) + .expect("x - k must be non-negative and fit in usize"); // The coordinate of the start of a snake if x < n && y < m { diff --git a/src/wasm.rs b/src/wasm.rs index 54c256e..1b7a24b 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -95,6 +95,11 @@ pub fn diff(parent: &str, changed: &TextWithCursors, tokenizer: BuiltinTokenizer } /// Inverse of `diff`, applies a compact diff representation to a parent text +/// +/// # Panics +/// +/// Panics if the diff format is invalid or there's an integer overflow when +/// applying the diff. #[wasm_bindgen(js_name = undiff)] #[must_use] pub fn undiff(parent: &str, diff: Vec, tokenizer: BuiltinTokenizer) -> String { @@ -103,7 +108,7 @@ pub fn undiff(parent: &str, diff: Vec, tokenizer: BuiltinTokenizer) -> EditedText::from_diff( parent, diff.into_iter() - .map(|js_value| js_value.try_into()) + .map(std::convert::TryInto::try_into) .collect::>() .expect("Invalid diff format"), &*tokenizer,