3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-15 21:10:25 +01:00

Answer principles round 1: 0 🔴, 2 🟡; drop the source-scanning test and file the lint question

This commit is contained in:
2026-10-22 00:01:46 +02:00
committed by Lillem4n
parent 3f7b3a386e
commit d36c99cd55
5 changed files with 45 additions and 51 deletions
-42
View File
@@ -1,42 +0,0 @@
import assert from 'node:assert/strict'
import { dirname, join, relative } from 'node:path'
import { fileURLToPath } from 'node:url'
import { readdirSync, readFileSync, statSync } from 'node:fs'
import test from 'node:test'
const markdown = join(dirname(fileURLToPath(import.meta.url)), '..', 'markdown')
const importSpecifier = /\bfrom '([^']+)'/g
function importsOf(directory: string): { file: string; target: string }[] {
const imports: { file: string; target: string }[] = []
for (const name of readdirSync(join(markdown, directory))) {
const path = join(directory, name)
if (statSync(join(markdown, path)).isDirectory()) {
imports.push(...importsOf(path))
} else if (name.endsWith('.ts') && !name.endsWith('.test.ts')) {
for (const match of readFileSync(join(markdown, path), 'utf8').matchAll(importSpecifier)) {
imports.push({ file: path, target: relative(markdown, join(markdown, directory, match[1] ?? '')) })
}
}
}
return imports
}
// docs/decisions.md §The source parts by ADF and format
test('parse/ asks emit/ only through the module that names its questions', () => {
const reached = importsOf('parse').filter(({ target }) => target.startsWith('emit/'))
assert.ok(reached.length > 0)
assert.deepEqual(
reached.filter(({ target }) => target !== 'emit/spelling-questions.ts'),
[],
)
})
test('directive/ imports nothing from emit/ or parse/', () => {
const imports = importsOf('directive')
assert.ok(imports.length > 0)
assert.deepEqual(
imports.filter(({ target }) => target.startsWith('emit/') || target.startsWith('parse/')),
[],
)
})
+1 -1
View File
@@ -6,8 +6,8 @@ import type { JsonValue } from '../../json-value.ts'
import { backslashEscape, holdsNullCharacter } from '../commonmark/grammar.ts'
import { backtickRun } from '../commonmark/backtick-runs.ts'
import { isNumberList } from '../../adf/attribute-vocabulary.ts'
import { overNested } from '../../json-value.ts'
import { largestNesting } from '../../nesting.ts'
import { overNested } from '../../json-value.ts'
import { parseJsonText } from '../../json-text.ts'
import { serializeCanonicalJson } from '../../canonical-json.ts'
+1 -1
View File
@@ -13,6 +13,7 @@ import { flavourClaims } from '../flavour.ts'
import { highlightDelimiter } from '../portable/conventions.ts'
import { identicalMarks, mergeAdjacentText, nodeAttrs, nodeMarks } from '../../adf/document.ts'
import { inlineNodeModel, takesMark } from '../../adf/inline-nodes.ts'
import { inlineSource, readInlineToken } from '../inline-tokens.ts'
import { joinsWhenRead, textBreakName, textBreakSpelling } from '../adjacent-text.ts'
import { matchEmphasis } from '../commonmark/emphasis-matching.ts'
import { normalizeLabel, readInlineTarget, readLabel } from '../commonmark/link-syntax.ts'
@@ -21,7 +22,6 @@ import { openingLinkTakesDirective } from '../emit/spelling-questions.ts'
import { readCarriedInline } from '../opaque-carry.ts'
import { readDirectiveMark } from '../directive/mark-reading.ts'
import { readInlineDirectiveNode } from '../directive/node-reading.ts'
import { inlineSource, readInlineToken } from '../inline-tokens.ts'
import { readTextDirective } from '../directive/text.ts'
// Only a `paragraph` block takes `image`, the `mediaSingle` a lone image builds; every other container takes `nodes`, where the image is its linked alt text.