ShtukbaseStandard
package file→ .shtukbase/packages/icons/checks/i03_required.ts

checks/i03_required.ts

24 lines, 1.3 KB.

  1. // ICN-R03: every record of a collection that requires an icon (`icons: {required: true}`) shows one.
  2. // Inherited counts: the record's own icon (as its tier allows), else the collection's icons.item, else the collection page's icon.
  3. import { Icons, finish, isGlyph, isSvgPath, norm, ownIcons } from '../lib/iconlib.ts';
  4. const ic = new Icons();
  5. const n = norm(ic.root, 'ICN-R03');
  6. const out: string[] = [];
  7. if (n.active) {
  8. const colls = ic.collections();
  9. const inherited: Record<string, string> = {};
  10. for (const c of Object.values(colls)) {
  11. const own = typeof c.fm.icon === 'string' ? c.fm.icon.trim() : '';
  12. inherited[c.coll] = c.item || (own && (isGlyph(own) || isSvgPath(own)) ? own : '');
  13. if (c.required && c.tier === 'none') out.push(`${c.coll}.md: icons.required with tier none → drop required or choose another tier`);
  14. }
  15. for (const p of ic.pages()) {
  16. if (!p.coll || !colls[p.coll].required || p.tier === 'none') continue;
  17. const { icon } = ownIcons(p);
  18. const ownOk = p.tier !== 'kind' && icon && (isGlyph(icon) || isSvgPath(icon));
  19. if (!ownOk && !inherited[p.coll]) out.push(`${p.id}: no icon, and ${p.coll}.md gives none to inherit → ${p.tier === 'kind' ? 'set icons.item on the collection' : 'set icon (an emoji; run shtuk run icons prompt ' + p.id.slice(1) + ') or icons.item on the collection'}`);
  20. }
  21. }
  22. finish(n, out);