Skip to content

Commit

Permalink
style(json-crdt-extensions): 💄 fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Dec 21, 2024
1 parent 93b7449 commit 8f5be6c
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 49 deletions.
8 changes: 4 additions & 4 deletions src/json-crdt-extensions/peritext/__tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion src/json-crdt-extensions/peritext/block/Fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof iterator>;
while (pair = iterator()) {
while ((pair = iterator())) {
const [p1, p2] = pair;
const type = p1 ? p1.type() : CommonSliceType.p;
const path = type instanceof Array ? type : [type];
Expand Down
3 changes: 1 addition & 2 deletions src/json-crdt-extensions/peritext/block/LeafBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export interface IBlock<Attr = unknown> {
export class LeafBlock<Attr = unknown> extends Block<Attr> {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
],
},
Expand Down Expand Up @@ -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__');
});
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
]);
});
Expand Down
3 changes: 2 additions & 1 deletion src/json-crdt-extensions/peritext/lazy/export-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
5 changes: 2 additions & 3 deletions src/json-crdt-extensions/peritext/overlay/Overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export class Overlay<T = string> 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.
Expand All @@ -276,8 +276,7 @@ export class Overlay<T = string> 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 () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -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};
};

Expand All @@ -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;
Expand All @@ -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]);
Expand All @@ -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;
},
Expand All @@ -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;
},
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/json-crdt-extensions/peritext/overlay/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type OverlayTuple<T> = [p1: OverlayPoint<T>, p2: OverlayPoint<T>];
* 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.
*/
Expand Down

0 comments on commit 8f5be6c

Please sign in to comment.