Skip to content

Commit 5b12b64

Browse files
committed
fix: trim static attr value, remove dead code (Copilot review)
- getStaticAttrValue() now trims chars so callers don't handle whitespace. - Lowercase the node value when comparing against aria-query's attrSpec.value (HTML enumerated attribute values are ASCII case-insensitive per HTML common-microsyntaxes §2.3.3). - Remove unused createUnsupportedAttributeErrorMessage() dead code; the rule uses messageId/data exclusively.
1 parent ffa45d0 commit 5b12b64

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

lib/rules/template-no-unsupported-role-attributes.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
const { roles, elementRoles } = require('aria-query');
22

3-
function createUnsupportedAttributeErrorMessage(attribute, role, element) {
4-
if (element) {
5-
return `The attribute ${attribute} is not supported by the element ${element} with the implicit role of ${role}`;
6-
}
7-
8-
return `The attribute ${attribute} is not supported by the role ${role}`;
9-
}
10-
113
function getStaticAttrValue(node, name) {
124
const attr = node.attributes?.find((a) => a.name === name);
135
if (!attr) {
@@ -17,7 +9,7 @@ function getStaticAttrValue(node, name) {
179
// Presence with dynamic value — treat as "set" but unknown string.
1810
return '';
1911
}
20-
return attr.value.chars;
12+
return attr.value.chars.trim();
2113
}
2214

2315
function nodeSatisfiesAttributeConstraint(node, attrSpec) {
@@ -31,7 +23,10 @@ function nodeSatisfiesAttributeConstraint(node, attrSpec) {
3123
return !isSet;
3224
}
3325
if (attrSpec.value !== undefined) {
34-
return isSet && value === attrSpec.value;
26+
// HTML enumerated attribute values are ASCII case-insensitive
27+
// (HTML common-microsyntaxes §2.3.3). aria-query's attrSpec.value is
28+
// already lowercase, so lowercase the node's value for comparison.
29+
return isSet && value.toLowerCase() === attrSpec.value;
3530
}
3631
// No constraint listed — just require presence.
3732
return isSet;

0 commit comments

Comments
 (0)