Skip to content

Commit 77165a1

Browse files
committed
Fix template-no-invalid-aria-attributes: add type-specific error messages
1 parent e20ba32 commit 77165a1

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

lib/rules/template-no-invalid-aria-attributes.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,38 @@ function isValidAriaValue(attrName, value) {
6262
}
6363
}
6464

65+
function getExpectedTypeDescription(attrName) {
66+
const attrDef = aria.get(attrName);
67+
if (!attrDef) {
68+
return 'a valid value';
69+
}
70+
switch (attrDef.type) {
71+
case 'boolean':
72+
return 'a boolean (true or false)';
73+
case 'tristate':
74+
return "a boolean or the string 'mixed'";
75+
case 'integer':
76+
return 'an integer';
77+
case 'number':
78+
return 'a number';
79+
case 'token': {
80+
const vals = attrDef.values.map((v) => (typeof v === 'boolean' ? v.toString() : v));
81+
return `a single token from: ${vals.join(', ')}`;
82+
}
83+
case 'tokenlist': {
84+
return `a list of tokens from: ${attrDef.values.join(', ')}`;
85+
}
86+
case 'id':
87+
return 'a non-boolean string ID';
88+
case 'idlist':
89+
return 'a space-separated list of string IDs';
90+
case 'string':
91+
return 'a string';
92+
default:
93+
return 'a valid value';
94+
}
95+
}
96+
6597
/** @type {import('eslint').Rule.RuleModule} */
6698
module.exports = {
6799
meta: {
@@ -75,7 +107,7 @@ module.exports = {
75107
schema: [],
76108
messages: {
77109
noInvalidAriaAttribute: 'Invalid ARIA attribute: {{attribute}}',
78-
invalidAriaAttributeValue: 'Invalid value for ARIA attribute {{attribute}}.',
110+
invalidAriaAttributeValue: 'The value for {{attribute}} must be {{expectedType}}.',
79111
},
80112
originallyFrom: {
81113
name: 'ember-template-lint',
@@ -118,7 +150,10 @@ module.exports = {
118150
context.report({
119151
node,
120152
messageId: 'invalidAriaAttributeValue',
121-
data: { attribute: node.name },
153+
data: {
154+
attribute: node.name,
155+
expectedType: getExpectedTypeDescription(node.name),
156+
},
122157
});
123158
}
124159
}

0 commit comments

Comments
 (0)