ShtukbaseStandard
包文件→ .shtukbase/packages/std-keep-a-changelog/checks/cl01_format.ts

checks/cl01_format.ts

24 行, 1.4 KB.

文件按包中的原样显示:代码及其注释不做翻译。

  1. // CL-R01: the changelog exists; its first release heading is [Unreleased]; every release heading is
  2. // `## [version] - YYYY-MM-DD` (optionally ` [YANKED]`) with a real ISO 8601 day.
  3. import { config, isoDay, logs, PKG } from './kaclib.ts';
  4. import { finish, norm } from './lib/std.ts';
  5. const n = norm(PKG, 'CL-R01', 'enforce');
  6. const out: string[] = [];
  7. if (n.active) {
  8. const { logs: ls, missing } = logs(config());
  9. for (const f of missing) out.push(`${f}: there is no such file — create a changelog with the section "## [Unreleased]"`);
  10. for (const l of ls) {
  11. for (const b of l.bad) out.push(`${l.file}:${b.line}: the heading "${b.raw}" is not in the form "## [version] - YYYY-MM-DD" or "## [Unreleased]"`);
  12. const first = l.releases[0];
  13. if (!first || !first.unreleased) out.push(`${l.file}:${first?.line ?? 1}: the first section must be "## [Unreleased]"`);
  14. const un = l.releases.filter((r) => r.unreleased);
  15. for (const r of un.slice(1)) out.push(`${l.file}:${r.line}: a second Unreleased section`);
  16. for (const r of l.releases.filter((x) => !x.unreleased)) {
  17. if (!r.date) out.push(`${l.file}:${r.line}: release ${r.version} has no date — "## [${r.version}] - YYYY-MM-DD"`);
  18. else if (!isoDay(r.date)) out.push(`${l.file}:${r.line}: the date "${r.date}" of release ${r.version} is not an ISO 8601 day (YYYY-MM-DD)`);
  19. }
  20. for (const r of un) if (r.date) out.push(`${l.file}:${r.line}: Unreleased has no date`);
  21. }
  22. }
  23. finish(n, out);