@wireweave/ux-rules 1.4.1-beta.0 → 1.5.0-beta.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.
package/dist/index.cjs CHANGED
@@ -80,7 +80,7 @@ __export(src_exports, {
80
80
  validateUX: () => validateUX
81
81
  });
82
82
  module.exports = __toCommonJS(src_exports);
83
- var import_core2 = require("@wireweave/core");
83
+ var import_core3 = require("@wireweave/core");
84
84
 
85
85
  // src/constants.ts
86
86
  var MAX_NAV_ITEMS = 7;
@@ -330,24 +330,33 @@ var imageRequiresAlt = {
330
330
  return null;
331
331
  }
332
332
  };
333
+ function getAccessibleNameAttr(node) {
334
+ const record = node;
335
+ const candidates = [record.aria, record["aria-label"], record.title];
336
+ for (const value of candidates) {
337
+ if (typeof value === "string" && value.trim()) return value.trim();
338
+ }
339
+ return "";
340
+ }
333
341
  var iconButtonRequiresLabel = {
334
342
  id: "a11y-icon-button-label",
335
343
  category: "accessibility",
336
- severity: "error",
337
- name: "Icon-only button requires label",
338
- description: "Buttons with only an icon must have an accessible label",
344
+ severity: "warning",
345
+ name: "Icon-only button should have an accessible name",
346
+ description: "Buttons with only an icon should have an accessible name (aria-label or title)",
339
347
  appliesTo: ["Button"],
340
348
  check: (node, context) => {
341
349
  const hasIcon = "icon" in node && node.icon;
342
350
  const hasContent = getNodeText(node).trim();
343
- if (hasIcon && !hasContent) {
351
+ const hasAccessibleName = getAccessibleNameAttr(node);
352
+ if (hasIcon && !hasContent && !hasAccessibleName) {
344
353
  return {
345
354
  ruleId: "a11y-icon-button-label",
346
355
  category: "accessibility",
347
- severity: "error",
348
- message: "Icon-only button is missing accessible text",
349
- description: "Screen readers cannot describe icon-only buttons without text",
350
- suggestion: "Add text content or aria-label to describe the button action",
356
+ severity: "warning",
357
+ message: "Icon-only button is missing an accessible name",
358
+ description: "Screen readers cannot describe icon-only buttons without an accessible name",
359
+ suggestion: 'Add an aria attribute (e.g. button "" icon="search" aria="Search") or text content',
351
360
  path: context.path,
352
361
  nodeType: node.type,
353
362
  location: getNodeLocation(node)
@@ -1368,6 +1377,7 @@ var navigationRules = [
1368
1377
  ];
1369
1378
 
1370
1379
  // src/rules/content.ts
1380
+ var import_core2 = require("@wireweave/core");
1371
1381
  var emptyTextContent = {
1372
1382
  id: "content-empty-text",
1373
1383
  category: "content",
@@ -1524,13 +1534,117 @@ var noPlaceholderContent = {
1524
1534
  return null;
1525
1535
  }
1526
1536
  };
1537
+ var unknownIcon = {
1538
+ id: "content-unknown-icon",
1539
+ category: "content",
1540
+ severity: "warning",
1541
+ name: "Icon name should resolve to a known icon",
1542
+ description: "Icon names must reference a valid Lucide icon so they render as a real glyph",
1543
+ appliesTo: ["Button", "Input", "Icon"],
1544
+ check: (node, context) => {
1545
+ const iconName = node.type === "Icon" ? "name" in node && typeof node.name === "string" ? node.name : void 0 : "icon" in node && typeof node.icon === "string" ? node.icon : void 0;
1546
+ if (!iconName || !iconName.trim()) {
1547
+ return null;
1548
+ }
1549
+ if ((0, import_core2.getIconData)(iconName) === void 0) {
1550
+ return {
1551
+ ruleId: "content-unknown-icon",
1552
+ category: "content",
1553
+ severity: "warning",
1554
+ message: `Unknown icon name "${iconName}"`,
1555
+ description: 'The icon name does not resolve to a known Lucide icon and will render as a "?" placeholder',
1556
+ suggestion: `Use a valid lucide kebab-case icon name (e.g. the overflow menu is "ellipsis-vertical", not "${iconName}")`,
1557
+ path: context.path,
1558
+ nodeType: node.type,
1559
+ location: getNodeLocation(node)
1560
+ };
1561
+ }
1562
+ return null;
1563
+ }
1564
+ };
1565
+ var controlValueRange = {
1566
+ id: "content-control-value-range",
1567
+ category: "content",
1568
+ severity: "warning",
1569
+ name: "Control value should lie within its range",
1570
+ description: "Slider/Progress values must fall within their declared min..max",
1571
+ appliesTo: ["Slider", "Progress"],
1572
+ check: (node, context) => {
1573
+ let min;
1574
+ let max;
1575
+ let value;
1576
+ if (node.type === "Slider") {
1577
+ if (typeof node.value !== "number") return null;
1578
+ min = typeof node.min === "number" ? node.min : 0;
1579
+ max = typeof node.max === "number" ? node.max : 100;
1580
+ value = node.value;
1581
+ } else if (node.type === "Progress") {
1582
+ if (typeof node.value !== "number") return null;
1583
+ min = 0;
1584
+ max = typeof node.max === "number" ? node.max : 100;
1585
+ value = node.value;
1586
+ } else {
1587
+ return null;
1588
+ }
1589
+ if (value < min || value > max) {
1590
+ const label = "label" in node && typeof node.label === "string" && node.label.trim() ? node.label : node.type;
1591
+ return {
1592
+ ruleId: "content-control-value-range",
1593
+ category: "content",
1594
+ severity: "warning",
1595
+ message: `${node.type} "${label}" value ${value} is outside its range [${min}, ${max}]`,
1596
+ description: "A value outside the declared range renders a misleading control position and announces an impossible value",
1597
+ suggestion: `Set value within [${min}, ${max}], or widen min/max to include ${value}`,
1598
+ path: context.path,
1599
+ nodeType: node.type,
1600
+ location: getNodeLocation(node)
1601
+ };
1602
+ }
1603
+ return null;
1604
+ }
1605
+ };
1606
+ var duplicateControlLabel = {
1607
+ id: "content-duplicate-control-label",
1608
+ category: "content",
1609
+ severity: "warning",
1610
+ name: "Control label should not duplicate an adjacent text",
1611
+ description: "A control's own label should not be repeated by an adjacent sibling text node",
1612
+ appliesTo: ["Slider", "Input"],
1613
+ check: (node, context) => {
1614
+ const ownLabel = "label" in node && typeof node.label === "string" ? node.label.trim().toLowerCase() : "";
1615
+ if (!ownLabel) return null;
1616
+ const { siblings, index } = context;
1617
+ const adjacent = [siblings[index - 1], siblings[index + 1]];
1618
+ for (const sib of adjacent) {
1619
+ if (!sib || sib.type !== "Text") continue;
1620
+ const sibText = getNodeText(sib).trim().toLowerCase();
1621
+ if (sibText && sibText === ownLabel) {
1622
+ return {
1623
+ ruleId: "content-duplicate-control-label",
1624
+ category: "content",
1625
+ severity: "warning",
1626
+ message: `${node.type} label duplicates an adjacent text "${getNodeText(sib).trim()}"`,
1627
+ description: "The control already renders this label, so the adjacent text node repeats it verbatim",
1628
+ suggestion: "Remove the standalone text and rely on the control label, or differentiate the two strings",
1629
+ path: context.path,
1630
+ nodeType: node.type,
1631
+ location: getNodeLocation(node)
1632
+ };
1633
+ }
1634
+ }
1635
+ return null;
1636
+ }
1637
+ };
1527
1638
  var contentRules = [
1528
1639
  emptyTextContent,
1529
1640
  buttonTextLength,
1530
1641
  titleLength,
1531
1642
  pageHasTitle,
1532
1643
  linkHasText,
1533
- noPlaceholderContent
1644
+ noPlaceholderContent,
1645
+ unknownIcon,
1646
+ controlValueRange,
1647
+ duplicateControlLabel
1534
1648
  ];
1535
1649
 
1536
1650
  // src/rules/data-display.ts
@@ -2222,7 +2336,7 @@ var SEVERITY_ORDER = {
2222
2336
  };
2223
2337
  function resolveComplexity(ast) {
2224
2338
  try {
2225
- const result = (0, import_core2.analyze)(ast);
2339
+ const result = (0, import_core3.analyze)(ast);
2226
2340
  if (result.success && typeof result.complexity?.score === "number" && Number.isFinite(result.complexity.score) && result.complexity.score > 0) {
2227
2341
  return { score: result.complexity.score, level: result.complexity.level };
2228
2342
  }
package/dist/index.js CHANGED
@@ -249,24 +249,33 @@ var imageRequiresAlt = {
249
249
  return null;
250
250
  }
251
251
  };
252
+ function getAccessibleNameAttr(node) {
253
+ const record = node;
254
+ const candidates = [record.aria, record["aria-label"], record.title];
255
+ for (const value of candidates) {
256
+ if (typeof value === "string" && value.trim()) return value.trim();
257
+ }
258
+ return "";
259
+ }
252
260
  var iconButtonRequiresLabel = {
253
261
  id: "a11y-icon-button-label",
254
262
  category: "accessibility",
255
- severity: "error",
256
- name: "Icon-only button requires label",
257
- description: "Buttons with only an icon must have an accessible label",
263
+ severity: "warning",
264
+ name: "Icon-only button should have an accessible name",
265
+ description: "Buttons with only an icon should have an accessible name (aria-label or title)",
258
266
  appliesTo: ["Button"],
259
267
  check: (node, context) => {
260
268
  const hasIcon = "icon" in node && node.icon;
261
269
  const hasContent = getNodeText(node).trim();
262
- if (hasIcon && !hasContent) {
270
+ const hasAccessibleName = getAccessibleNameAttr(node);
271
+ if (hasIcon && !hasContent && !hasAccessibleName) {
263
272
  return {
264
273
  ruleId: "a11y-icon-button-label",
265
274
  category: "accessibility",
266
- severity: "error",
267
- message: "Icon-only button is missing accessible text",
268
- description: "Screen readers cannot describe icon-only buttons without text",
269
- suggestion: "Add text content or aria-label to describe the button action",
275
+ severity: "warning",
276
+ message: "Icon-only button is missing an accessible name",
277
+ description: "Screen readers cannot describe icon-only buttons without an accessible name",
278
+ suggestion: 'Add an aria attribute (e.g. button "" icon="search" aria="Search") or text content',
270
279
  path: context.path,
271
280
  nodeType: node.type,
272
281
  location: getNodeLocation(node)
@@ -1287,6 +1296,7 @@ var navigationRules = [
1287
1296
  ];
1288
1297
 
1289
1298
  // src/rules/content.ts
1299
+ import { getIconData } from "@wireweave/core";
1290
1300
  var emptyTextContent = {
1291
1301
  id: "content-empty-text",
1292
1302
  category: "content",
@@ -1443,13 +1453,117 @@ var noPlaceholderContent = {
1443
1453
  return null;
1444
1454
  }
1445
1455
  };
1456
+ var unknownIcon = {
1457
+ id: "content-unknown-icon",
1458
+ category: "content",
1459
+ severity: "warning",
1460
+ name: "Icon name should resolve to a known icon",
1461
+ description: "Icon names must reference a valid Lucide icon so they render as a real glyph",
1462
+ appliesTo: ["Button", "Input", "Icon"],
1463
+ check: (node, context) => {
1464
+ const iconName = node.type === "Icon" ? "name" in node && typeof node.name === "string" ? node.name : void 0 : "icon" in node && typeof node.icon === "string" ? node.icon : void 0;
1465
+ if (!iconName || !iconName.trim()) {
1466
+ return null;
1467
+ }
1468
+ if (getIconData(iconName) === void 0) {
1469
+ return {
1470
+ ruleId: "content-unknown-icon",
1471
+ category: "content",
1472
+ severity: "warning",
1473
+ message: `Unknown icon name "${iconName}"`,
1474
+ description: 'The icon name does not resolve to a known Lucide icon and will render as a "?" placeholder',
1475
+ suggestion: `Use a valid lucide kebab-case icon name (e.g. the overflow menu is "ellipsis-vertical", not "${iconName}")`,
1476
+ path: context.path,
1477
+ nodeType: node.type,
1478
+ location: getNodeLocation(node)
1479
+ };
1480
+ }
1481
+ return null;
1482
+ }
1483
+ };
1484
+ var controlValueRange = {
1485
+ id: "content-control-value-range",
1486
+ category: "content",
1487
+ severity: "warning",
1488
+ name: "Control value should lie within its range",
1489
+ description: "Slider/Progress values must fall within their declared min..max",
1490
+ appliesTo: ["Slider", "Progress"],
1491
+ check: (node, context) => {
1492
+ let min;
1493
+ let max;
1494
+ let value;
1495
+ if (node.type === "Slider") {
1496
+ if (typeof node.value !== "number") return null;
1497
+ min = typeof node.min === "number" ? node.min : 0;
1498
+ max = typeof node.max === "number" ? node.max : 100;
1499
+ value = node.value;
1500
+ } else if (node.type === "Progress") {
1501
+ if (typeof node.value !== "number") return null;
1502
+ min = 0;
1503
+ max = typeof node.max === "number" ? node.max : 100;
1504
+ value = node.value;
1505
+ } else {
1506
+ return null;
1507
+ }
1508
+ if (value < min || value > max) {
1509
+ const label = "label" in node && typeof node.label === "string" && node.label.trim() ? node.label : node.type;
1510
+ return {
1511
+ ruleId: "content-control-value-range",
1512
+ category: "content",
1513
+ severity: "warning",
1514
+ message: `${node.type} "${label}" value ${value} is outside its range [${min}, ${max}]`,
1515
+ description: "A value outside the declared range renders a misleading control position and announces an impossible value",
1516
+ suggestion: `Set value within [${min}, ${max}], or widen min/max to include ${value}`,
1517
+ path: context.path,
1518
+ nodeType: node.type,
1519
+ location: getNodeLocation(node)
1520
+ };
1521
+ }
1522
+ return null;
1523
+ }
1524
+ };
1525
+ var duplicateControlLabel = {
1526
+ id: "content-duplicate-control-label",
1527
+ category: "content",
1528
+ severity: "warning",
1529
+ name: "Control label should not duplicate an adjacent text",
1530
+ description: "A control's own label should not be repeated by an adjacent sibling text node",
1531
+ appliesTo: ["Slider", "Input"],
1532
+ check: (node, context) => {
1533
+ const ownLabel = "label" in node && typeof node.label === "string" ? node.label.trim().toLowerCase() : "";
1534
+ if (!ownLabel) return null;
1535
+ const { siblings, index } = context;
1536
+ const adjacent = [siblings[index - 1], siblings[index + 1]];
1537
+ for (const sib of adjacent) {
1538
+ if (!sib || sib.type !== "Text") continue;
1539
+ const sibText = getNodeText(sib).trim().toLowerCase();
1540
+ if (sibText && sibText === ownLabel) {
1541
+ return {
1542
+ ruleId: "content-duplicate-control-label",
1543
+ category: "content",
1544
+ severity: "warning",
1545
+ message: `${node.type} label duplicates an adjacent text "${getNodeText(sib).trim()}"`,
1546
+ description: "The control already renders this label, so the adjacent text node repeats it verbatim",
1547
+ suggestion: "Remove the standalone text and rely on the control label, or differentiate the two strings",
1548
+ path: context.path,
1549
+ nodeType: node.type,
1550
+ location: getNodeLocation(node)
1551
+ };
1552
+ }
1553
+ }
1554
+ return null;
1555
+ }
1556
+ };
1446
1557
  var contentRules = [
1447
1558
  emptyTextContent,
1448
1559
  buttonTextLength,
1449
1560
  titleLength,
1450
1561
  pageHasTitle,
1451
1562
  linkHasText,
1452
- noPlaceholderContent
1563
+ noPlaceholderContent,
1564
+ unknownIcon,
1565
+ controlValueRange,
1566
+ duplicateControlLabel
1453
1567
  ];
1454
1568
 
1455
1569
  // src/rules/data-display.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wireweave/ux-rules",
3
- "version": "1.4.1-beta.0",
3
+ "version": "1.5.0-beta.1",
4
4
  "description": "UX validation rules for wireweave",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -17,7 +17,7 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
- "@wireweave/core": "3.1.0-beta.0"
20
+ "@wireweave/core": "3.1.0-beta.1"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@commitlint/cli": "^21.0.2",