Lint
This commit is contained in:
parent
9c23229627
commit
5fbeb79fdc
4 changed files with 27 additions and 6 deletions
|
|
@ -8,6 +8,6 @@
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"declarationDir": "./dist/types",
|
"declarationDir": "./dist/types",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"inlineSourceMap": true,
|
"inlineSourceMap": true
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,11 @@ where
|
||||||
/// from the same original text. The operations are merged using the
|
/// from the same original text. The operations are merged using the
|
||||||
/// principles of Operational Transformation. The cursors are updated
|
/// principles of Operational Transformation. The cursors are updated
|
||||||
/// accordingly to reflect the changes made by the merged operations.
|
/// 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]
|
#[must_use]
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub fn merge(self, other: Self) -> Self {
|
pub fn merge(self, other: Self) -> Self {
|
||||||
|
|
@ -356,6 +361,10 @@ where
|
||||||
///
|
///
|
||||||
/// Inserts are represented as strings, deletes as negative integers,
|
/// Inserts are represented as strings, deletes as negative integers,
|
||||||
/// and equal spans as positive integers.
|
/// and equal spans as positive integers.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if there's an integer overflow in i64.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn to_diff(&self) -> Vec<NumberOrString> {
|
pub fn to_diff(&self) -> Vec<NumberOrString> {
|
||||||
let mut result: Vec<NumberOrString> = Vec::with_capacity(self.operations.len());
|
let mut result: Vec<NumberOrString> = Vec::with_capacity(self.operations.len());
|
||||||
|
|
@ -414,6 +423,10 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deserialize an `EditedText` from a change list and the original text.
|
/// Deserialize an `EditedText` from a change list and the original text.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if there's an integer overflow in i64.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn from_diff(
|
pub fn from_diff(
|
||||||
original_text: &'a str,
|
original_text: &'a str,
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,8 @@ where
|
||||||
|
|
||||||
// By Lemma 1 in the paper, the optimal edit script length is odd or even as
|
// By Lemma 1 in the paper, the optimal edit script length is odd or even as
|
||||||
// `delta` is odd or even.
|
// `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;
|
let odd = delta & 1 == 1;
|
||||||
|
|
||||||
// The initial point at (0, -1)
|
// The initial point at (0, -1)
|
||||||
|
|
@ -165,7 +166,8 @@ where
|
||||||
} else {
|
} else {
|
||||||
vf[k - 1] + 1
|
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
|
// The coordinate of the start of a snake
|
||||||
let (x0, y0) = (x, y);
|
let (x0, y0) = (x, y);
|
||||||
|
|
@ -203,7 +205,8 @@ where
|
||||||
} else {
|
} else {
|
||||||
vb[k - 1] + 1
|
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
|
// The coordinate of the start of a snake
|
||||||
if x < n && y < m {
|
if x < n && y < m {
|
||||||
|
|
|
||||||
|
|
@ -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
|
/// 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)]
|
#[wasm_bindgen(js_name = undiff)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn undiff(parent: &str, diff: Vec<JsValue>, tokenizer: BuiltinTokenizer) -> String {
|
pub fn undiff(parent: &str, diff: Vec<JsValue>, tokenizer: BuiltinTokenizer) -> String {
|
||||||
|
|
@ -103,7 +108,7 @@ pub fn undiff(parent: &str, diff: Vec<JsValue>, tokenizer: BuiltinTokenizer) ->
|
||||||
EditedText::from_diff(
|
EditedText::from_diff(
|
||||||
parent,
|
parent,
|
||||||
diff.into_iter()
|
diff.into_iter()
|
||||||
.map(|js_value| js_value.try_into())
|
.map(std::convert::TryInto::try_into)
|
||||||
.collect::<Result<_, _>>()
|
.collect::<Result<_, _>>()
|
||||||
.expect("Invalid diff format"),
|
.expect("Invalid diff format"),
|
||||||
&*tokenizer,
|
&*tokenizer,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue