"""Accessibility checks: keyboard, visible focus, alt text, field labels.""" import re from collections import namedtuple from checks.common import Rule, blank_markup_comments DOMAIN = "a11y" MARKUP_EXTS = (".html", ".htm", ".jsx", ".tsx", ".vue", ".svelte", ".astro") STYLE_EXTS = (".css", ".scss", ".sass", ".less") SCRIPT_EXTS = (".ts", ".js", ".mjs") FIELD_TAGS = {"input", "select", "textarea"} CLICK_TAGS = {"div", "span", "li", "p", "td", "tr", "section", "article"} SKIP_INPUT_TYPES = {"hidden", "submit", "button", "reset", "image"} INTERACTIVE = {"*", "a", "button", "input", "select", "textarea", "summary"} _BRACES = r"\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}" TAG = re.compile( r"<(?P[A-Za-z][\w.:-]*)(?P(?:[^<>{}]|" + _BRACES + r")*)>") SPREAD = re.compile(r"\{\s*\.\.\.|v-bind\s*=") CLICK = re.compile( r"(?]*>(.*?)", re.I | re.S) CSS_RULE = re.compile(r"(?P[^{}]+)\{(?P[^{}]*)\}") OUTLINE_OFF = re.compile(r"outline(?:-style)?\s*:\s*(?:none|0)\b", re.I) REPLACEMENT = re.compile( r"(?:box-shadow|border(?:-color)?)\s*:\s*(?!none\b|0\b)", re.I) NOT_A_CONTROL = re.compile( r"role\s*=\s*[\"'{]\s*[\"']?(?:presentation|none|dialog|alertdialog)\b" r"|stopPropagation", re.I) TW_STRING = re.compile( r"[\"'`]([^\"'`\n]*\boutline-(?:none|hidden)\b[^\"'`\n]*)[\"'`]") TW_REPLACED = re.compile( r"\bfocus(?:-visible|-within)?:(?:ring|outline\b(?!-none|-hidden)" r"|shadow|border|underline|bg-)") def applies(project): return bool(project.with_ext(*MARKUP_EXTS, *STYLE_EXTS)) def has_attr(attrs, name): pattern = (r"(?") def _field_issue(m, text): attrs = m["attrs"] kind = (attr_value(attrs, "type") or "text").lower() if kind in SKIP_INPUT_TYPES or _is_hidden_field(attrs): return None if _is_labelled(attrs, text, m.start()): return None return ("A11Y-FIELD-LABEL", "FAIL", "form field without a label: add