Skip to content

Commit cc2c51a

Browse files
committed
fix: replace for...of with Array.from().forEach() to satisfy no-restricted-syntax
1 parent 5ddb05e commit cc2c51a

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

src/app/components/message/RenderBody.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ export function buildAbbrReplaceTextNode(
7575
<>
7676
{segments.map((seg) =>
7777
seg.termKey !== undefined ? (
78-
<AbbreviationTerm key={seg.id} text={seg.text} definition={abbrMap.get(seg.termKey) ?? ''} />
78+
<AbbreviationTerm
79+
key={seg.id}
80+
text={seg.text}
81+
definition={abbrMap.get(seg.termKey) ?? ''}
82+
/>
7983
) : (
8084
seg.text
8185
)
@@ -116,9 +120,7 @@ export function RenderBody({
116120
{segments.map((seg) => {
117121
if (seg.termKey !== undefined) {
118122
const definition = abbrMap.get(seg.termKey) ?? '';
119-
return (
120-
<AbbreviationTerm key={seg.id} text={seg.text} definition={definition} />
121-
);
123+
return <AbbreviationTerm key={seg.id} text={seg.text} definition={definition} />;
122124
}
123125
return (
124126
<Linkify key={seg.id} options={linkifyOpts}>

src/app/utils/abbreviations.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ describe('splitByAbbreviations', () => {
6565
});
6666

6767
it('returns a single plain segment when there are no matches', () => {
68-
expect(splitByAbbreviations('hello world', map)).toEqual([{ id: 'txt-0', text: 'hello world' }]);
68+
expect(splitByAbbreviations('hello world', map)).toEqual([
69+
{ id: 'txt-0', text: 'hello world' },
70+
]);
6971
});
7072

7173
it('returns a single plain segment for an empty string', () => {
@@ -114,7 +116,9 @@ describe('splitByAbbreviations', () => {
114116
it('does not match a term that is a prefix of a longer word (word boundary)', () => {
115117
// OSS is in the map, but should not match inside FOSS because the F provides no boundary
116118
const ossOnlyMap = buildAbbreviationsMap([{ term: 'OSS', definition: 'Open Source Software' }]);
117-
expect(splitByAbbreviations('FOSS rocks', ossOnlyMap)).toEqual([{ id: 'txt-0', text: 'FOSS rocks' }]);
119+
expect(splitByAbbreviations('FOSS rocks', ossOnlyMap)).toEqual([
120+
{ id: 'txt-0', text: 'FOSS rocks' },
121+
]);
118122
});
119123

120124
it('does not match a term embedded inside a longer word', () => {

src/app/utils/abbreviations.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ export const splitByAbbreviations = (text: string, abbrMap: Map<string, string>)
4444
const segments: TextSegment[] = [];
4545
let lastIndex = 0;
4646

47-
for (const match of text.matchAll(pattern)) {
48-
const matchIndex = match.index!;
47+
Array.from(text.matchAll(pattern)).forEach((match) => {
48+
const matchIndex = match.index;
4949
if (matchIndex > lastIndex) {
5050
segments.push({ id: `txt-${segments.length}`, text: text.slice(lastIndex, matchIndex) });
5151
}
52-
segments.push({ id: `txt-${segments.length}`, text: match[0], termKey: match[0].toLowerCase() });
52+
segments.push({
53+
id: `txt-${segments.length}`,
54+
text: match[0],
55+
termKey: match[0].toLowerCase(),
56+
});
5357
lastIndex = matchIndex + match[0].length;
54-
}
58+
});
5559

5660
if (lastIndex < text.length) {
5761
segments.push({ id: `txt-${segments.length}`, text: text.slice(lastIndex) });

0 commit comments

Comments
 (0)