From 8f5be6c1d4e175497480b45c45845b55d8d4cc60 Mon Sep 17 00:00:00 2001 From: streamich Date: Sat, 21 Dec 2024 19:58:47 +0100 Subject: [PATCH] =?UTF-8?q?style(json-crdt-extensions):=20=F0=9F=92=84=20f?= =?UTF-8?q?ix=20linter=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../peritext/__tests__/setup.ts | 8 +-- .../peritext/block/Fragment.ts | 2 +- .../peritext/block/LeafBlock.ts | 3 +- .../Fragment-export-markdown.spec.ts | 12 +--- .../block/__tests__/Fragment-export.spec.ts | 10 ++- .../peritext/lazy/export-html.ts | 3 +- .../peritext/overlay/Overlay.ts | 5 +- .../overlay/__tests__/Overlay.markers.spec.ts | 72 ++++++++++++------- .../peritext/overlay/types.ts | 2 +- 9 files changed, 68 insertions(+), 49 deletions(-) diff --git a/src/json-crdt-extensions/peritext/__tests__/setup.ts b/src/json-crdt-extensions/peritext/__tests__/setup.ts index 80e08e1113..f13ae3d407 100644 --- a/src/json-crdt-extensions/peritext/__tests__/setup.ts +++ b/src/json-crdt-extensions/peritext/__tests__/setup.ts @@ -150,19 +150,19 @@ export const runNumbersKitTestSuite = (runTestSuite: (getKit: () => Kit) => void describe('numbers "0123456789", no edits', () => { runTestSuite(setupNumbersKit); }); - + describe('numbers "0123456789", with default schema and tombstones', () => { runTestSuite(setupNumbersWithTombstonesKit); }); - + describe('numbers "0123456789", two RGA chunks', () => { runTestSuite(setupNumbersWithTwoChunksKit); }); - + describe('numbers "0123456789", with RGA split', () => { runTestSuite(setupNumbersWithRgaSplitKit); }); - + describe('numbers "0123456789", with multiple deletes', () => { runTestSuite(setupNumbersWithMultipleChunksAndDeletesKit); }); diff --git a/src/json-crdt-extensions/peritext/block/Fragment.ts b/src/json-crdt-extensions/peritext/block/Fragment.ts index a7ac815ac0..e8e231e53f 100644 --- a/src/json-crdt-extensions/peritext/block/Fragment.ts +++ b/src/json-crdt-extensions/peritext/block/Fragment.ts @@ -78,7 +78,7 @@ export class Fragment extends Range implements Printable, Stateful { const overlay = txt.overlay; const iterator = overlay.markerPairs0(this.start, this.end); let pair: ReturnType; - while (pair = iterator()) { + while ((pair = iterator())) { const [p1, p2] = pair; const type = p1 ? p1.type() : CommonSliceType.p; const path = type instanceof Array ? type : [type]; diff --git a/src/json-crdt-extensions/peritext/block/LeafBlock.ts b/src/json-crdt-extensions/peritext/block/LeafBlock.ts index 7d5eaea34e..1b2ce327d8 100644 --- a/src/json-crdt-extensions/peritext/block/LeafBlock.ts +++ b/src/json-crdt-extensions/peritext/block/LeafBlock.ts @@ -12,8 +12,7 @@ export interface IBlock { export class LeafBlock extends Block { public text(): string { let str = ''; - for (let iterator = this.texts0(), inline = iterator(); inline; inline = iterator()) - str += inline.text(); + for (let iterator = this.texts0(), inline = iterator(); inline; inline = iterator()) str += inline.text(); return str; } diff --git a/src/json-crdt-extensions/peritext/block/__tests__/Fragment-export-markdown.spec.ts b/src/json-crdt-extensions/peritext/block/__tests__/Fragment-export-markdown.spec.ts index 04eec4d673..411f03bb1e 100644 --- a/src/json-crdt-extensions/peritext/block/__tests__/Fragment-export-markdown.spec.ts +++ b/src/json-crdt-extensions/peritext/block/__tests__/Fragment-export-markdown.spec.ts @@ -72,12 +72,8 @@ const runTests = (setup: () => Kit) => { children: [ {type: 'text', value: 'ef'}, {type: 'strong', children: [{type: 'text', value: 'g'}]}, - {type: 'emphasis', children: [ - {type: 'strong', children: [{type: 'text', value: 'h'}]}, - ]}, - {type: 'emphasis', children: [ - {type: 'text', value: 'i'}, - ]}, + {type: 'emphasis', children: [{type: 'strong', children: [{type: 'text', value: 'h'}]}]}, + {type: 'emphasis', children: [{type: 'text', value: 'i'}]}, {type: 'text', value: 'j'}, ], }, @@ -175,9 +171,7 @@ const runTests = (setup: () => Kit) => { fragment.refresh(); const json = fragment.toJson(); const html = toMarkdown(json); - expect(html).toEqual( - 'efghij\n\n> kl__m__', - ); + expect(html).toEqual('efghij\n\n> kl__m__'); }); }); }; diff --git a/src/json-crdt-extensions/peritext/block/__tests__/Fragment-export.spec.ts b/src/json-crdt-extensions/peritext/block/__tests__/Fragment-export.spec.ts index bc8a0a1fdc..09e4e5513a 100644 --- a/src/json-crdt-extensions/peritext/block/__tests__/Fragment-export.spec.ts +++ b/src/json-crdt-extensions/peritext/block/__tests__/Fragment-export.spec.ts @@ -28,7 +28,15 @@ const runTests = (setup: () => Kit) => { expect(node).toEqual([ '', null, - [0, null, 'ef', [-3, {inline: true}, 'g'], [-4, {inline: true}, [-3, {inline: true}, 'h']], [-4, {inline: true}, 'i'], 'j'], + [ + 0, + null, + 'ef', + [-3, {inline: true}, 'g'], + [-4, {inline: true}, [-3, {inline: true}, 'h']], + [-4, {inline: true}, 'i'], + 'j', + ], [0, null, 'klm'], ]); }); diff --git a/src/json-crdt-extensions/peritext/lazy/export-html.ts b/src/json-crdt-extensions/peritext/lazy/export-html.ts index f429c2e92a..c15fb776fd 100644 --- a/src/json-crdt-extensions/peritext/lazy/export-html.ts +++ b/src/json-crdt-extensions/peritext/lazy/export-html.ts @@ -24,4 +24,5 @@ export const toHast = (json: PeritextMlNode): THtmlToken => { return hast; }; -export const toHtml = (json: PeritextMlNode, tab?: string, indent?: string): string => _toHtml(toHast(json), tab, indent); +export const toHtml = (json: PeritextMlNode, tab?: string, indent?: string): string => + _toHtml(toHast(json), tab, indent); diff --git a/src/json-crdt-extensions/peritext/overlay/Overlay.ts b/src/json-crdt-extensions/peritext/overlay/Overlay.ts index bbb8c9a54d..f3cbc79f54 100644 --- a/src/json-crdt-extensions/peritext/overlay/Overlay.ts +++ b/src/json-crdt-extensions/peritext/overlay/Overlay.ts @@ -258,7 +258,7 @@ export class Overlay implements Printable, Stateful { * marker). The very first point in the first pair might be `undefined`, if * the given point is not a marker. Similarly, the very last point in the last * pair might be `undefined`, if the iteration end point is not a marker. - * + * * @param start Start point of the iteration, inclusive. * @param end End point of the iteration. If not provided, the iteration * continues until the end of the overlay. @@ -276,8 +276,7 @@ export class Overlay implements Printable, Stateful { } if (end && p2) { const cmp = end.cmpSpatial(p2); - if (cmp <= 0) - return () => closed ? void 0 : ((closed = true), [p1, cmp ? void 0 : p2]); + if (cmp <= 0) return () => (closed ? void 0 : ((closed = true), [p1, cmp ? void 0 : p2])); } } return () => { diff --git a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.markers.spec.ts b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.markers.spec.ts index ae3a4fa631..13abce5ef4 100644 --- a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.markers.spec.ts +++ b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.markers.spec.ts @@ -1,6 +1,6 @@ import {UndefEndIter} from '../../../../util/iterator'; import {type Kit, runNumbersKitTestSuite} from '../../__tests__/setup'; -import {Point} from '../../rga/Point'; +import type {Point} from '../../rga/Point'; import {MarkerOverlayPoint} from '../MarkerOverlayPoint'; const runMarkersTests = (setup: () => Kit) => { @@ -512,7 +512,7 @@ const runMarkersTests = (setup: () => Kit) => { kit.peritext.overlay.refresh(); const iterator = kit.peritext.overlay.markerPairs0(start(kit), end?.(kit)); const list = [...new UndefEndIter(iterator)]; - const markers = [...kit.peritext.overlay.markers()] + const markers = [...kit.peritext.overlay.markers()]; return {...kit, m1, m2, m3, list, markers}; }; @@ -530,22 +530,22 @@ const runMarkersTests = (setup: () => Kit) => { }; test('start before all markers', () => { - const kit = create(kit => kit.peritext.pointAt(1)); + const kit = create((kit) => kit.peritext.pointAt(1)); assertAllPoints(kit); }); test('start at ABS start', () => { - const kit = create(kit => kit.peritext.pointAbsStart()); + const kit = create((kit) => kit.peritext.pointAbsStart()); assertAllPoints(kit); }); test('start at REL start', () => { - const kit = create(kit => kit.peritext.pointStart()!); + const kit = create((kit) => kit.peritext.pointStart()!); assertAllPoints(kit); }); test('start half-point before first marker', () => { - const kit = create(kit => { + const kit = create((kit) => { const point = kit.peritext.pointAt(3); point.halfstep(-1); return point; @@ -554,41 +554,59 @@ const runMarkersTests = (setup: () => Kit) => { }); test('end after all markers', () => { - const kit = create(kit => kit.peritext.pointAt(1), kit => kit.peritext.pointAt(10)); + const kit = create( + (kit) => kit.peritext.pointAt(1), + (kit) => kit.peritext.pointAt(10), + ); assertAllPoints(kit); }); test('end at ABS end', () => { - const kit = create(kit => kit.peritext.pointAt(1), kit => kit.peritext.pointAbsEnd()); + const kit = create( + (kit) => kit.peritext.pointAt(1), + (kit) => kit.peritext.pointAbsEnd(), + ); assertAllPoints(kit); }); test('end at REL end', () => { - const kit = create(kit => kit.peritext.pointAt(1), kit => kit.peritext.pointEnd()!); + const kit = create( + (kit) => kit.peritext.pointAt(1), + (kit) => kit.peritext.pointEnd()!, + ); assertAllPoints(kit); }); test('end half-point after last marker', () => { - const kit = create(kit => kit.peritext.pointAbsStart(), kit => { - const point = kit.peritext.pointAt(8); - point.halfstep(1); - return point; - }); + const kit = create( + (kit) => kit.peritext.pointAbsStart(), + (kit) => { + const point = kit.peritext.pointAt(8); + point.halfstep(1); + return point; + }, + ); assertAllPoints(kit); }); test('start and end at ABS endpoints', () => { - const kit = create(kit => kit.peritext.pointAbsStart(), kit => kit.peritext.pointAbsEnd()); + const kit = create( + (kit) => kit.peritext.pointAbsStart(), + (kit) => kit.peritext.pointAbsEnd(), + ); assertAllPoints(kit); }); test('start and end at REL endpoints', () => { - const kit = create(kit => kit.peritext.pointStart()!, kit => kit.peritext.pointEnd()!); + const kit = create( + (kit) => kit.peritext.pointStart()!, + (kit) => kit.peritext.pointEnd()!, + ); assertAllPoints(kit); }); test('start point past the first marker', () => { - const {list, markers} = create(kit => kit.peritext.pointAt(4)); + const {list, markers} = create((kit) => kit.peritext.pointAt(4)); expect(list.length).toBe(3); expect(list[0][0]).toBe(undefined); expect(list[0][1]).toBe(markers[1]); @@ -600,8 +618,8 @@ const runMarkersTests = (setup: () => Kit) => { test('start point past the first marker, end point ahead of last marker', () => { const {list, markers} = create( - kit => kit.peritext.pointAt(4), - kit => { + (kit) => kit.peritext.pointAt(4), + (kit) => { const point = kit.peritext.pointAt(7); return point; }, @@ -615,8 +633,8 @@ const runMarkersTests = (setup: () => Kit) => { test('start point past the first marker, end point right on second marker', () => { const {list, markers} = create( - kit => kit.peritext.pointAt(4), - kit => { + (kit) => kit.peritext.pointAt(4), + (kit) => { const end = kit.peritext.pointAt(6); return end; }, @@ -628,8 +646,8 @@ const runMarkersTests = (setup: () => Kit) => { test('start point right on first maker, end point past the first marker', () => { const {list, markers} = create( - kit => kit.peritext.pointAt(3), - kit => kit.peritext.pointAt(4), + (kit) => kit.peritext.pointAt(3), + (kit) => kit.peritext.pointAt(4), ); expect(list.length).toBe(1); expect(list[0][0]).toBe(markers[0]); @@ -638,8 +656,8 @@ const runMarkersTests = (setup: () => Kit) => { test('start point right on first maker, end point past the second marker', () => { const {list, markers} = create( - kit => kit.peritext.pointAt(3), - kit => kit.peritext.pointAt(7), + (kit) => kit.peritext.pointAt(3), + (kit) => kit.peritext.pointAt(7), ); expect(list.length).toBe(2); expect(list[0][0]).toBe(markers[0]); @@ -650,8 +668,8 @@ const runMarkersTests = (setup: () => Kit) => { test('start point right on first maker, at REL end', () => { const {list, markers} = create( - kit => kit.peritext.pointAt(3), - kit => kit.peritext.pointEnd()!, + (kit) => kit.peritext.pointAt(3), + (kit) => kit.peritext.pointEnd()!, ); expect(list.length).toBe(3); expect(list[0][0]).toBe(markers[0]); diff --git a/src/json-crdt-extensions/peritext/overlay/types.ts b/src/json-crdt-extensions/peritext/overlay/types.ts index 5694e3b15a..8e8b42c0ab 100644 --- a/src/json-crdt-extensions/peritext/overlay/types.ts +++ b/src/json-crdt-extensions/peritext/overlay/types.ts @@ -21,7 +21,7 @@ export type OverlayTuple = [p1: OverlayPoint, p2: OverlayPoint]; * Represents a two adjacent marker overlay points. The first point is the point * that is closer to the start of the document, and the second point is the * point that is closer to the end of the document. - * + * * When point is `undefined`, it means the point represents the end of range. * In the complete document it is ABS start or ABS end of the document. */