Sprint: regril (#170)

* ST-cmowjelb1: Parser: bestand-relatieve regel + hint-detectie in YAMLParseError-tak

- Voeg `hint?: string` toe aan PlanParseError type
- Bereken bestand-relatief regelnummer (yamlLine + 1 voor de openings-`---`)
- Detecteer markdown-patronen (numbered/bullet lijst) op de offending regel
- Zet Nederlandstalige hint bij markdown-match
- Render hint als "Tip: …" onder het foutbericht in IdeaMdEditor

* ST-cmowjeq3q: UI: render hint apart onder error-message in IdeaMdEditor

Vervang <span block mt-0.5 text-status-blocked/80> door <div mt-1 text-foreground/80>
voor de Tip-hint per plan-spec (MD3-token, geen status-kleur).

* ST-cmowjewfg: Test: parser geeft hint bij markdown-in-frontmatter

Voeg twee Vitest-cases toe:
- hints when markdown sneaks into frontmatter: fixture met [unclosed op
  een genummerde markdown-regel triggert YAMLParseError op die regel
  (plain lijst zonder unclosed flow parset als geldig YAML)
- omits hint for non-markdown yaml errors: unclosed bracket zonder
  markdown-patroon geeft geen hint
This commit is contained in:
Janpeter Visser 2026-05-08 13:22:10 +02:00 committed by GitHub
parent 8c63ba377d
commit 79005dc777
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 54 additions and 7 deletions

View file

@ -62,6 +62,41 @@ body
}
})
it('hints when markdown sneaks into frontmatter', () => {
// "1. **...**: [unclosed" triggers a YAMLParseError at the markdown line
// (plain-list-with-bold parses as valid YAML without an unclosed flow)
const broken = `---
pbi:
title: Test
priority: 2
stories:
1. **Toggle zichtbaar in productie**: [unclosed
---
body
`
const r = parsePlanMd(broken)
expect(r.ok).toBe(false)
if (!r.ok) {
expect(r.errors[0].hint).toMatch(/markdown/i)
expect(r.errors[0].line).toBeGreaterThan(1)
}
})
it('omits hint for non-markdown yaml errors', () => {
const broken = `---
pbi:
title: Test
priority: [unclosed
stories:
- foo
---
`
const r = parsePlanMd(broken)
expect(r.ok).toBe(false)
if (!r.ok) expect(r.errors[0].hint).toBeUndefined()
})
it('reports schema-validation error when pbi-section missing', () => {
const noPbi = `---
stories:

View file

@ -123,6 +123,9 @@ export function IdeaMdEditor({ ideaId, kind, initialValue, onCancel }: Props) {
<li key={i}>
{err.line ? `Regel ${err.line}: ` : ''}
{err.message}
{err.hint && (
<div className="mt-1 text-foreground/80">Tip: {err.hint}</div>
)}
</li>
))}
</ul>

View file

@ -13,7 +13,7 @@ import {
type IdeaPlanFrontmatter,
} from '@/lib/schemas/idea'
export type PlanParseError = { line?: number; message: string }
export type PlanParseError = { line?: number; message: string; hint?: string }
export type PlanParseResult =
| { ok: true; plan: IdeaPlanFrontmatter; body: string }
@ -43,14 +43,23 @@ export function parsePlanMd(md: string): PlanParseResult {
parsed = parseYaml(frontmatterRaw)
} catch (err) {
if (err instanceof YAMLParseError) {
const yamlLine = err.linePos?.[0]?.line
const fileLine = yamlLine != null ? yamlLine + 1 : undefined
const offendingLine =
yamlLine != null
? frontmatterRaw.split(/\r?\n/)[(yamlLine ?? 1) - 1]
: undefined
const isMarkdown =
offendingLine != null &&
(/^\s*\d+\.\s+\*\*/.test(offendingLine) ||
/^\s*[-*]\s+\*\*/.test(offendingLine) ||
/^\s*\d+\..*:/.test(offendingLine))
const hint = isMarkdown
? 'Lijkt op markdown-content (genummerde of opsommingslijst) binnen YAML-frontmatter. Verplaats deze regels naar na de afsluitende `---`, of zet ze in een `description: |` blok.'
: undefined
return {
ok: false,
errors: [
{
line: err.linePos?.[0]?.line,
message: err.message,
},
],
errors: [{ line: fileLine, message: err.message, hint }],
}
}
return {