Skip to content

Commit 3cd9dcc

Browse files
committed
fix: resolve lint and typecheck issues
- Remove unused lineBreak import from heading.test.ts - Remove unused measureDepth from skip-flags-regression.spec.ts - Fix prettier formatting in fuzz.test.ts - Update compact.ts Heading serialization to use inline children - Update compact tests and CBlock type for new heading format
1 parent 278d60c commit 3cd9dcc

6 files changed

Lines changed: 36 additions & 60 deletions

File tree

packages/message-parser/src/compact.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export type CInlineNode =
6868

6969
export type CBlock =
7070
| { t: 'p'; c: CInline[] }
71-
| { t: 'h'; l: 1 | 2 | 3 | 4; r: Span }
71+
| { t: 'h'; l: 1 | 2 | 3 | 4; c: CInline[]; r?: Span }
7272
| { t: '```'; l?: string; r: Span }
7373
| { t: '>'; c: CBlock[] }
7474
| { t: 'q'; c: CBlock[] }
@@ -182,7 +182,7 @@ function expandBlock(
182182
case 'p':
183183
return { type: 'PARAGRAPH', value: block.c.map((c) => expandInline(msg, c)) } as Paragraph;
184184
case 'h':
185-
return { type: 'HEADING', level: block.l, value: [makePlain(msg, block.r)] } as Heading;
185+
return { type: 'HEADING', level: block.l, value: block.c.map((c) => expandInline(msg, c)) } as Heading;
186186
case '```': {
187187
const content = msg.slice(block.r[0], block.r[1]);
188188
const lines: CodeLine[] = content.split('\n').map((line) => ({
@@ -446,9 +446,8 @@ function compactBlock(ctx: Ctx, node: Paragraph | Root[number]): CBlock {
446446
const heading = node as Heading;
447447
advance(ctx, heading.level); // #, ##, ###, ####
448448
advance(ctx, 1); // space
449-
const text = heading.value.map(textOf).join('');
450-
const r = spanFor(ctx, text);
451-
return { t: 'h', l: heading.level, r };
449+
const c = heading.value.map((ch) => compactInline(ctx, ch));
450+
return { t: 'h', l: heading.level, c };
452451
}
453452

454453
case 'CODE': {

packages/message-parser/tests/compact.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe('expand (compact → verbose)', () => {
129129
});
130130

131131
it('heading', () => {
132-
expectExpand('## Title', [{ t: 'h', l: 2, r: [3, 8] }], [
132+
expectExpand('## Title', [{ t: 'h', l: 2, c: [[3, 8]] }], [
133133
{ type: 'HEADING', level: 2, value: [{ type: 'PLAIN_TEXT', value: 'Title' }] },
134134
] as unknown as Root);
135135
});
@@ -202,7 +202,7 @@ describe('compactify (verbose → compact)', () => {
202202
it('heading', () => {
203203
const msg = '## Title';
204204
const compact = compactify(parse(msg), msg);
205-
expect(compact).toEqual([{ t: 'h', l: 2, r: [3, 8] }]);
205+
expect(compact).toEqual([{ t: 'h', l: 2, c: [[3, 8]] }]);
206206
});
207207
});
208208

packages/message-parser/tests/fuzz.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@ import fc from 'fast-check';
22

33
import { parse } from '../src';
44

5-
const plainTextArbitrary = fc
6-
.stringMatching(/[a-zA-Z0-9 ]{1,20}/)
7-
.filter((value) => value.length > 0);
5+
const plainTextArbitrary = fc.stringMatching(/[a-zA-Z0-9 ]{1,20}/).filter((value) => value.length > 0);
86

9-
const timestampArbitrary = fc
10-
.integer({ min: 1_000_000_000, max: 2_000_000_000 })
11-
.map((value) => `<t:${value}>`);
7+
const timestampArbitrary = fc.integer({ min: 1_000_000_000, max: 2_000_000_000 }).map((value) => `<t:${value}>`);
128

13-
const relativeTimestampArbitrary = fc
14-
.integer({ min: 1_000_000_000, max: 2_000_000_000 })
15-
.map((value) => `<t:${value}:R>`);
9+
const relativeTimestampArbitrary = fc.integer({ min: 1_000_000_000, max: 2_000_000_000 }).map((value) => `<t:${value}:R>`);
1610

17-
const mentionArbitrary = fc
18-
.stringMatching(/[a-z0-9._-]{1,12}/)
19-
.map((value) => `@${value}`);
11+
const mentionArbitrary = fc.stringMatching(/[a-z0-9._-]{1,12}/).map((value) => `@${value}`);
2012

2113
const boldArbitrary = plainTextArbitrary.map((value) => `*${value}*`);
2214

packages/message-parser/tests/heading.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parse } from '../src';
2-
import { emoji, heading, lineBreak, link, mentionChannel, paragraph, plain } from './helpers';
2+
import { emoji, heading, link, mentionChannel, paragraph, plain } from './helpers';
33

44
test.each([
55
['# h1', [heading([plain('h1')], 1)]],
@@ -47,7 +47,6 @@ test.each([
4747
['# :newspaper: Headline', [heading([emoji('newspaper'), plain(' Headline')], 1)]],
4848
['## Hello :smile:', [heading([plain('Hello '), emoji('smile')], 2)]],
4949
['### :smile: text :newspaper:', [heading([emoji('smile'), plain(' text '), emoji('newspaper')], 3)]],
50-
5150
])('parses %p', (input, output) => {
5251
expect(parse(input)).toEqual(output);
5352
});
Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
1-
import { plain, emoji, reducePlainTexts } from '../src/utils';
2-
3-
describe('joinEmoji behavior through reducePlainTexts', () => {
4-
it('keeps emoji when alone', () => {
5-
const result = reducePlainTexts([emoji('smile')]);
6-
expect(result[0].type).toBe('EMOJI');
7-
});
8-
9-
it('merges consecutive plain texts', () => {
10-
const result = reducePlainTexts([
11-
plain('hello '),
12-
plain('world'),
13-
]);
14-
15-
expect(result).toHaveLength(1);
16-
expect(result[0]).toMatchObject({ type: 'PLAIN_TEXT', value: 'hello world' });
17-
});
18-
19-
it('converts emoji with plain text neighbors to shortCode and merges', () => {
20-
const result = reducePlainTexts([
21-
plain('hello'),
22-
emoji('smile'),
23-
plain('world'),
24-
]);
25-
26-
expect(result).toHaveLength(1);
27-
expect(result[0]).toMatchObject({
28-
type: 'PLAIN_TEXT',
29-
value: 'hello:smile:world',
30-
});
31-
});
32-
});
1+
import { plain, emoji, reducePlainTexts } from '../src/utils';
2+
3+
describe('joinEmoji behavior through reducePlainTexts', () => {
4+
it('keeps emoji when alone', () => {
5+
const result = reducePlainTexts([emoji('smile')]);
6+
expect(result[0].type).toBe('EMOJI');
7+
});
8+
9+
it('merges consecutive plain texts', () => {
10+
const result = reducePlainTexts([plain('hello '), plain('world')]);
11+
12+
expect(result).toHaveLength(1);
13+
expect(result[0]).toMatchObject({ type: 'PLAIN_TEXT', value: 'hello world' });
14+
});
15+
16+
it('converts emoji with plain text neighbors to shortCode and merges', () => {
17+
const result = reducePlainTexts([plain('hello'), emoji('smile'), plain('world')]);
18+
19+
expect(result).toHaveLength(1);
20+
expect(result[0]).toMatchObject({
21+
type: 'PLAIN_TEXT',
22+
value: 'hello:smile:world',
23+
});
24+
});
25+
});

packages/message-parser/tests/skip-flags-regression.spec.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { parse } from '../src';
22

33
describe('Skip Flags Regression (Complexity Audit)', () => {
4-
const measureDepth = (depth: number) => {
5-
const input = `${'*'.repeat(depth)}text${'*'.repeat(depth)}`;
6-
const start = performance.now();
7-
parse(input);
8-
return performance.now() - start;
9-
};
10-
114
it('should parse nested formatting across multiple depths without throwing', () => {
125
for (let d = 1; d <= 50; d++) {
136
const input = `${'*'.repeat(d)}text${'*'.repeat(d)}`;

0 commit comments

Comments
 (0)