verify-rfc-classification.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Enforce RFC lifecycle/class paths, dated filenames, and titles; verify the
  3. * generated index and reject index rows in the curated README. Structural rules
  4. * and rendering are shared with `rfc-index.ts`; the closed classification
  5. * contract lives in `docs/rfc/README.md`.
  6. */
  7. import { readFileSync } from 'node:fs'
  8. import { resolve } from 'node:path'
  9. import { INDEX_ROW, renderIndex, rfcRoot, walkRfcTree } from './rfc-index.ts'
  10. const { rfcs, errors } = walkRfcTree()
  11. if (errors.length === 0) {
  12. let index: string | undefined
  13. try {
  14. index = readFileSync(resolve(rfcRoot, 'INDEX.md'), 'utf8')
  15. } catch {
  16. // A missing INDEX.md is reported below as staleness, exactly like a drifted one.
  17. }
  18. if (renderIndex(rfcs) !== index) {
  19. errors.push('index: docs/rfc/INDEX.md is stale or missing — run `pnpm run gen-rfc-index` and commit the result')
  20. }
  21. const readme = readFileSync(resolve(rfcRoot, 'README.md'), 'utf8')
  22. for (const line of readme.split('\n')) {
  23. if (INDEX_ROW.test(line)) {
  24. errors.push(`readme: index-shaped row in the curated README (the list lives in INDEX.md): ${JSON.stringify(line.slice(0, 80))}`)
  25. }
  26. }
  27. }
  28. if (errors.length === 0) {
  29. console.log(`verify-rfc-classification: ${rfcs.length} RFC(s) checked, structure and index consistent.`)
  30. process.exit(0)
  31. }
  32. console.error('verify-rfc-classification: violations found:')
  33. for (const e of errors) console.error(` ${e}`)
  34. process.exit(1)