tailwind-a11y 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -17,6 +17,31 @@ function lastSizeToken(tokens, prefix) {
|
|
|
17
17
|
}
|
|
18
18
|
return found;
|
|
19
19
|
}
|
|
20
|
+
function isMeaningfulText(node) {
|
|
21
|
+
// Pure JSX-formatting whitespace (indentation/newlines between elements)
|
|
22
|
+
// doesn't count as text.
|
|
23
|
+
return !!node && t.isJSXText(node) && node.value.trim().length > 0;
|
|
24
|
+
}
|
|
25
|
+
// WCAG 2.5.8's "Inline" exception: a target inside a sentence or block of
|
|
26
|
+
// text is exempt from the minimum size, since its size is constrained by
|
|
27
|
+
// surrounding text flow rather than a deliberate layout choice. Checked via
|
|
28
|
+
// the element's *immediate* siblings only (not "any text anywhere in the
|
|
29
|
+
// parent") — a parent-wide check would exempt every sibling in something
|
|
30
|
+
// like `<p>Choose: <button/><button/></p>` just because the first button
|
|
31
|
+
// happens to sit next to text, even though the second one doesn't. That's
|
|
32
|
+
// the same "shape, not meaning" failure mode as the bg-opacity-50/ring-0
|
|
33
|
+
// false negatives documented in CLAUDE.md, just at the sibling level instead
|
|
34
|
+
// of the token level.
|
|
35
|
+
function isInlineInText(path) {
|
|
36
|
+
const parentNode = path.parentPath?.node;
|
|
37
|
+
if (!parentNode || (!t.isJSXElement(parentNode) && !t.isJSXFragment(parentNode)))
|
|
38
|
+
return false;
|
|
39
|
+
const siblings = parentNode.children;
|
|
40
|
+
const index = siblings.indexOf(path.node);
|
|
41
|
+
if (index === -1)
|
|
42
|
+
return false;
|
|
43
|
+
return isMeaningfulText(siblings[index - 1]) || isMeaningfulText(siblings[index + 1]);
|
|
44
|
+
}
|
|
20
45
|
export function extractTouchTargetChecks(code, filePath) {
|
|
21
46
|
const ast = parseJSX(code, filePath);
|
|
22
47
|
if (!ast)
|
|
@@ -39,6 +64,8 @@ export function extractTouchTargetChecks(code, filePath) {
|
|
|
39
64
|
const heightPx = spacingScale[height.value];
|
|
40
65
|
if (widthPx === undefined || heightPx === undefined)
|
|
41
66
|
return; // arbitrary/keyword/fraction — skip
|
|
67
|
+
if (isInlineInText(path))
|
|
68
|
+
return; // WCAG 2.5.8 inline exception — exempt, not a violation
|
|
42
69
|
checks.push({
|
|
43
70
|
file: filePath,
|
|
44
71
|
line: opening.loc?.start.line ?? 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwind-a11y",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Static analysis CLI that catches WCAG accessibility violations — color contrast, touch target size, and focus indicator removal — in Tailwind CSS class combinations before they ship.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|