файл пакета→ .shtukbase/packages/design-a11y/checks/lang.ts
checks/lang.ts
25 строк, 1.1 КБ.
Файл как есть в пакете: код и комментарии в нём не переводятся.
- // A11Y-R06. The page says its language: every <html> (in HTML files, and in TSX/JSX layouts such as Next.js
- // app/layout.tsx) has a non-empty lang. An HTML page without an <html> tag at all is a page too: it lacks lang.
- import { attr, elements } 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-r06', title: 'The page has a language' };
- export function check(root = process.cwd()): string[] {
- const out: string[] = [];
- for (const f of markupFiles(root)) {
- const html = elements(f.text, /html/);
- if (!html.length) {
- if (f.html && /<body[\s>]/i.test(f.text)) out.push(`${f.rel}:1: no <html lang="…"> — set the page language`);
- continue;
- }
- for (const el of html) {
- const lang = attr(el, 'lang');
- if (lang === null || lang.trim() === '') out.push(`${f.rel}:${lineAt(f.text, el.start)}: <html> without lang — set the page language (lang="en")`);
- }
- }
- return out;
- }
- if (import.meta.main) report(check());