Skip to content

Commit 48d1c7b

Browse files
committed
Fix template-require-mandatory-role-attributes: read StringLiteral .value not .original
The mustache branch was dead code due to an incorrect accessor on GlimmerStringLiteral (.original returns undefined). Required-ARIA-property errors on curly invocations like {{foo role="slider"}} were silently dropped. Switch to .value to match the AST and add invalid-case tests.
1 parent 56f913d commit 48d1c7b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/rules/template-require-mandatory-role-attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function getStaticRoleFromMustache(node) {
2222
const rolePair = node.hash?.pairs?.find((pair) => pair.key === 'role');
2323

2424
if (rolePair?.value?.type === 'GlimmerStringLiteral') {
25-
return rolePair.value.original;
25+
return rolePair.value.value;
2626
}
2727

2828
return undefined;

tests/lib/rules/template-require-mandatory-role-attributes.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ ruleTester.run('template-require-mandatory-role-attributes', rule, {
6161
output: null,
6262
errors: [{ message: 'The attribute aria-level is required by the role heading' }],
6363
},
64+
{
65+
code: '<template>{{foo role="slider"}}</template>',
66+
output: null,
67+
errors: [
68+
{
69+
message: 'The attribute aria-valuenow is required by the role slider',
70+
},
71+
],
72+
},
73+
{
74+
code: '<template>{{foo role="checkbox"}}</template>',
75+
output: null,
76+
errors: [{ message: 'The attribute aria-checked is required by the role checkbox' }],
77+
},
6478
],
6579
});
6680

@@ -118,5 +132,19 @@ hbsRuleTester.run('template-require-mandatory-role-attributes', rule, {
118132
output: null,
119133
errors: [{ message: 'The attribute aria-level is required by the role heading' }],
120134
},
135+
{
136+
code: '{{foo role="slider"}}',
137+
output: null,
138+
errors: [
139+
{
140+
message: 'The attribute aria-valuenow is required by the role slider',
141+
},
142+
],
143+
},
144+
{
145+
code: '{{foo role="checkbox"}}',
146+
output: null,
147+
errors: [{ message: 'The attribute aria-checked is required by the role checkbox' }],
148+
},
121149
],
122150
});

0 commit comments

Comments
 (0)