archivo del paquete→ .shtukbase/packages/design-a11y/checks/alt.ts
checks/alt.ts
21 líneas, 997 B.
El archivo tal como está en el paquete: el código y sus comentarios no se traducen.
- // A11Y-R02. Every <img> in HTML, TSX and JSX has an alt attribute (alt="" for a decorative picture).
- // Skipped: an <img> with {...props} (alt may come from outside) and one hidden from assistive tech (aria-hidden="true").
- import { elements, attr } from '../../design-base/lib/markup.ts';
- import { lineAt, report } from '../../design-base/lib/files.ts';
- import { markupFiles } from './a11ylib.ts';
- export const RULE = { id: 'a11y-r02', title: 'An image has alt' };
- export function check(root = process.cwd()): string[] {
- const out: string[] = [];
- for (const f of markupFiles(root)) {
- for (const el of elements(f.text, /img/)) {
- if (attr(el, 'alt') !== null || el.spread) continue;
- if (attr(el, 'aria-hidden') === 'true' || attr(el, 'role') === 'presentation') continue;
- out.push(`${f.rel}:${lineAt(f.text, el.start)}: <img> without alt — describe the picture in words or use alt="" for decoration`);
- }
- }
- return out;
- }
- if (import.meta.main) report(check());