Lint: fix all ESLint errors (391 -> 0), lint and typecheck tests
Mostly perfectionist import/key sorting and curly braces from --fix, plus: - spread instead of .apply() in the Meta Pixel stub - non-capturing group in the locale-code pattern - React 19 use(Context) / <Context value> in TurnstileProvider - email regex rewritten without super-linear backtracking (covered by a test) - console.warn/error allowed (deliberate server diagnostics) - test/tsconfig.json so the project service and tsc see test files Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -20,7 +20,7 @@ import { lexicalToMarkdown } from '../richtext/lexicalToMarkdown.js'
|
||||
* })
|
||||
*/
|
||||
|
||||
type Block = Record<string, unknown> & { blockType?: string }
|
||||
type Block = { blockType?: string } & Record<string, unknown>
|
||||
type BlockToMarkdown = (block: Block) => string
|
||||
|
||||
type BlocksToMarkdownArgs = {
|
||||
@@ -32,30 +32,30 @@ const HEADING_KEYS = new Set(['heading', 'title'])
|
||||
const SUBHEADING_KEYS = new Set(['subheading', 'subtitle'])
|
||||
const QUESTION_KEYS = new Set(['question'])
|
||||
const TEXT_KEYS = new Set([
|
||||
'answer',
|
||||
'body',
|
||||
'text',
|
||||
'caption',
|
||||
'content',
|
||||
'description',
|
||||
'excerpt',
|
||||
'summary',
|
||||
'answer',
|
||||
'caption',
|
||||
'label',
|
||||
'content',
|
||||
'summary',
|
||||
'text',
|
||||
])
|
||||
const ARRAY_KEYS = new Set([
|
||||
'items',
|
||||
'features',
|
||||
'faq',
|
||||
'faqs',
|
||||
'benefits',
|
||||
'cards',
|
||||
'columns',
|
||||
'rows',
|
||||
'faq',
|
||||
'faqs',
|
||||
'features',
|
||||
'items',
|
||||
'list',
|
||||
'points',
|
||||
'questions',
|
||||
'rows',
|
||||
'services',
|
||||
'steps',
|
||||
'points',
|
||||
'benefits',
|
||||
'list',
|
||||
])
|
||||
|
||||
/** A populated richText value is an object with a `root`. */
|
||||
@@ -65,7 +65,7 @@ function isRichText(v: unknown): boolean {
|
||||
|
||||
/** A populated upload (image) is an object with a `url`. */
|
||||
function imageMarkdown(v: unknown): string {
|
||||
if (!v || typeof v !== 'object') return ''
|
||||
if (!v || typeof v !== 'object') {return ''}
|
||||
const o = v as Record<string, unknown>
|
||||
const url = typeof o.url === 'string' ? o.url : ''
|
||||
const alt = typeof o.alt === 'string' ? o.alt : ''
|
||||
@@ -77,7 +77,7 @@ function extractBlock(block: Block, depth: number): string {
|
||||
const lines: string[] = []
|
||||
|
||||
for (const [key, value] of Object.entries(block)) {
|
||||
if (value == null) continue
|
||||
if (value == null) {continue}
|
||||
|
||||
if (HEADING_KEYS.has(key) && typeof value === 'string' && value.trim()) {
|
||||
lines.push(`## ${value.trim()}`)
|
||||
@@ -87,17 +87,17 @@ function extractBlock(block: Block, depth: number): string {
|
||||
lines.push(`**${value.trim()}**`)
|
||||
} else if (key === 'image') {
|
||||
const img = imageMarkdown(value)
|
||||
if (img) lines.push(img)
|
||||
if (img) {lines.push(img)}
|
||||
} else if (isRichText(value)) {
|
||||
const md = lexicalToMarkdown(value as never)
|
||||
if (md) lines.push(md)
|
||||
if (md) {lines.push(md)}
|
||||
} else if (TEXT_KEYS.has(key) && typeof value === 'string' && value.trim()) {
|
||||
lines.push(value.trim())
|
||||
} else if (ARRAY_KEYS.has(key) && Array.isArray(value) && depth < 4) {
|
||||
for (const item of value) {
|
||||
if (item && typeof item === 'object') {
|
||||
const sub = extractBlock(item as Block, depth + 1)
|
||||
if (sub.trim()) lines.push(sub)
|
||||
if (sub.trim()) {lines.push(sub)}
|
||||
} else if (typeof item === 'string' && item.trim()) {
|
||||
lines.push(`- ${item.trim()}`)
|
||||
}
|
||||
@@ -109,23 +109,23 @@ function extractBlock(block: Block, depth: number): string {
|
||||
}
|
||||
|
||||
export function blocksToMarkdown(layout: unknown, args: BlocksToMarkdownArgs = {}): string {
|
||||
if (!Array.isArray(layout)) return ''
|
||||
if (!Array.isArray(layout)) {return ''}
|
||||
const { overrides = {} } = args
|
||||
const out: string[] = []
|
||||
|
||||
for (const block of layout) {
|
||||
if (!block || typeof block !== 'object') continue
|
||||
if (!block || typeof block !== 'object') {continue}
|
||||
const b = block as Block
|
||||
const type = typeof b.blockType === 'string' ? b.blockType : ''
|
||||
|
||||
if (type && overrides[type]) {
|
||||
const md = overrides[type](b)
|
||||
if (md.trim()) out.push(md.trim())
|
||||
if (md.trim()) {out.push(md.trim())}
|
||||
continue
|
||||
}
|
||||
|
||||
const md = extractBlock(b, 0)
|
||||
if (md.trim()) out.push(md.trim())
|
||||
if (md.trim()) {out.push(md.trim())}
|
||||
}
|
||||
|
||||
return out.join('\n\n').trim()
|
||||
|
||||
Reference in New Issue
Block a user