From bd07f9817198fd056ffd292cc3a491358ec4bbf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3is=C3=ADn=20Grannell?= Date: Sat, 1 Jul 2023 02:01:47 +0100 Subject: [PATCH] linting fixes --- src/prism.ts | 6 +++--- src/traversal.test.ts | 36 ++++++++++++++++++++++-------------- src/traversal.ts | 20 ++++++++++---------- src/types.ts | 22 +++++++++++----------- 4 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/prism.ts b/src/prism.ts index cf390e5..1b75302 100644 --- a/src/prism.ts +++ b/src/prism.ts @@ -1,6 +1,6 @@ import { RegExpMatchArrayIndexed, StringPrism } from "./types.ts"; -/* +/** * A prism that matches a regular expression (at most once) against a string. * * - view: returns the matched string, or null if no match @@ -48,7 +48,7 @@ export function MaybeMatch(pattern: RegExp) { }(); } -/* +/** * A prism that matches a regular expression with capture groups (at most once) against a string. ` * * - view: returns the matched capture-group, or null if no match @@ -122,7 +122,7 @@ export function MaybeGroupMatch(pattern: RegExp, index: number) { return whole; } - let [groupStart, groupEnd] = matches.indices[index]; + const [groupStart, groupEnd] = matches.indices[index]; return whole.slice(0, groupStart) + newPart + diff --git a/src/traversal.test.ts b/src/traversal.test.ts index b52d4d9..a46303b 100644 --- a/src/traversal.test.ts +++ b/src/traversal.test.ts @@ -21,7 +21,6 @@ Deno.test({ }, }); - Deno.test({ name: "EachMatch.view: if the pattern never matches, .view returns no parts", fn() { @@ -34,35 +33,41 @@ Deno.test({ }); Deno.test({ - name: "EachMatch.view: if the pattern matches each character, .view acts as split", + name: + "EachMatch.view: if the pattern matches each character, .view acts as split", fn() { const traversal = SubEdit.EachMatch(/[0-9]/gd); for (const whole of Peach.Array.from(sampleNumbers, 100)()) { - assertEquals(traversal.view(whole), whole.split('')); + assertEquals(traversal.view(whole), whole.split("")); } }, }); Deno.test({ - name: "EachMatch.modify: if the input is empty, .modify acts as an identity function", + name: + "EachMatch.modify: if the input is empty, .modify acts as an identity function", fn() { const traversal = SubEdit.EachMatch(/[a-z]+/gd); - assertEquals(traversal.modify(() => { - throw Error('bang') - }, ""), ""); + assertEquals( + traversal.modify(() => { + throw Error("bang"); + }, ""), + "", + ); }, }); Deno.test({ - name: "EachMatch.modify: if the pattern never matches, .modify acts as an identity function", + name: + "EachMatch.modify: if the pattern never matches, .modify acts as an identity function", fn() { const traversal = SubEdit.EachMatch(/[a-z]+/gd); for (const whole of Peach.Array.from(sampleNumbers, 100)()) { const updated = traversal.modify(() => { - throw Error('bang') + throw Error("bang"); }, whole); assertEquals(updated, whole); @@ -71,7 +76,8 @@ Deno.test({ }); Deno.test({ - name: "EachMatch.modify: elementwise uppercasing is the same as String.toUpperCase", + name: + "EachMatch.modify: elementwise uppercasing is the same as String.toUpperCase", fn() { const traversal = SubEdit.EachMatch(/[a-z]+/gd); @@ -86,19 +92,21 @@ Deno.test({ }); Deno.test({ - name: "EachMatch.modify: elementwise uppercasing is the same as String.toUpperCase", + name: + "EachMatch.modify: elementwise uppercasing is the same as String.toUpperCase", fn() { const traversal = SubEdit.EachMatch(/polo/gd); const dialogue = Peach.String.from( - Peach.Logic.oneOf(Peach.Number.uniform, ['marco', 'polo']), - Peach.Number.uniform(1, 10)) + Peach.Logic.oneOf(Peach.Number.uniform, ["marco", "polo"]), + Peach.Number.uniform(1, 10), + ); for (const whole of Peach.Array.from(dialogue, 100)()) { const updated = traversal.modify((polo: string) => { return polo.toUpperCase(); }, whole); - const replaced = whole.replace(/polo/g, 'POLO') + const replaced = whole.replace(/polo/g, "POLO"); assertEquals(updated, replaced); } }, diff --git a/src/traversal.ts b/src/traversal.ts index 66355cf..224faba 100644 --- a/src/traversal.ts +++ b/src/traversal.ts @@ -4,7 +4,7 @@ import { Traversal, } from "./types.ts"; -/* +/** * A traversal that matches a regular expression against a string. * * - view: returns an array of all matched strings @@ -25,7 +25,7 @@ export function EachMatch(pattern: RegExp): StringTraversal { return new class extends StringTraversal { view(whole: string) { - let parts: string[] = []; + const parts: string[] = []; for (const match of whole.matchAll(pattern)) { parts.push(match[0]); @@ -34,7 +34,7 @@ export function EachMatch(pattern: RegExp): StringTraversal { return parts; } indices(whole: string): number[][] { - let slices: number[][] = []; + const slices: number[][] = []; for (const match of whole.matchAll(pattern)) { const matchIndices = (match as RegExpMatchArrayIndexed).indices[0]; @@ -45,12 +45,12 @@ export function EachMatch(pattern: RegExp): StringTraversal { } modify(modifier: (part: string) => string, whole: string) { - let parts: string[] = []; + const parts: string[] = []; let start = 0; for (const match of whole.matchAll(pattern)) { const text = match[0]; - const boundaries = (match as any).indices[0]; + const boundaries = (match as RegExpMatchArrayIndexed).indices[0]; // push text from the previous match up to this match parts.push(whole.slice(start, boundaries[0])); @@ -69,7 +69,7 @@ export function EachMatch(pattern: RegExp): StringTraversal { }(); } -/* +/** * A traversal that matches a regular expression's capture-group against a string. * * - view: returns an array of all matched strings @@ -93,7 +93,7 @@ export function EachGroupMatch( return new class extends StringTraversal { view(whole: string) { - let parts: string[] = []; + const parts: string[] = []; for (const match of whole.matchAll(pattern)) { parts.push(match[index]); @@ -102,7 +102,7 @@ export function EachGroupMatch( return parts; } indices(whole: string): number[][] { - let slices: number[][] = []; + const slices: number[][] = []; for (const match of whole.matchAll(pattern)) { const matchIndices = (match as RegExpMatchArrayIndexed).indices[index]; @@ -112,12 +112,12 @@ export function EachGroupMatch( return slices; } modify(modifier: (part: string) => string, whole: string) { - let parts: string[] = []; + const parts: string[] = []; let start = 0; for (const match of whole.matchAll(pattern)) { const text = match[index]; - const boundaries = (match as any).indices[index]; + const boundaries = (match as RegExpMatchArrayIndexed).indices[index]; // push text from the previous match up to this match parts.push(whole.slice(start, boundaries[0])); diff --git a/src/types.ts b/src/types.ts index 5815c24..1a33912 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -/* +/** * A prism is an optic that: * - may or may not return a part * - may or may not update a whole, depending if the part was found @@ -12,7 +12,7 @@ export interface Prism { ): Prism; } -/* +/** * Partial implementation of the prism interface, leaving view and set abstract */ export abstract class AbstractPrism implements Prism { @@ -32,11 +32,11 @@ export abstract class AbstractPrism implements Prism { composePrism( secondPrism: Prism, ): Prism { - let self = this; + const self = this; return new class extends AbstractPrism implements Prism { - /* + /** * Retrieve the part from the first, then from the second. Account for nulls. */ view(whole: Whole): SubPart | null { @@ -49,7 +49,7 @@ export abstract class AbstractPrism implements Prism { return secondPrism.view(firstPart as Part); } - /* + /** * Retrieve the part from the first. Update it with a second prism, * and update with the newly updated part */ @@ -69,7 +69,7 @@ export abstract class AbstractPrism implements Prism { } } -/* +/** * A traversal is an optic (sorry if this is misnamed!) that: * - views 0...n parts * - modifies the whole at the site of 0...n parts @@ -80,7 +80,7 @@ export interface Traversal { composePrism(prism: Prism): Traversal; } -/* +/** * Partial implementation of the traversal interface, leaving view and modify abstract */ export abstract class AbstractTraversal @@ -91,7 +91,7 @@ export abstract class AbstractTraversal composePrism( prism: Prism, ): Traversal { - let self = this; + const self = this; return new class extends AbstractTraversal implements Traversal { @@ -101,7 +101,7 @@ export abstract class AbstractTraversal const subparts: SubPart[] = []; - for (let part of parts) { + for (const part of parts) { const subpart = prism.view(part); // prisms can return null; do not preserve it @@ -131,7 +131,7 @@ export abstract class AbstractTraversal composeTraversal( secondTraversal: Traversal, ): Traversal { - let self = this; + const self = this; return new class extends AbstractTraversal implements Traversal { @@ -141,7 +141,7 @@ export abstract class AbstractTraversal let subparts: SubPart[] = []; - for (let part of parts) { + for (const part of parts) { subparts = subparts.concat(secondTraversal.view(part)); }