Skip to content

Commit

Permalink
Merge pull request #2466 from judithhinlung/no-invalid-aria-attribute…
Browse files Browse the repository at this point in the history
…s-remove-mustache-validation

Remove validation of mustache statements in `no-invalid-aria-attributes` rule
  • Loading branch information
bmish committed Apr 14, 2022
2 parents d501792 + a1ab32b commit 714250d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 115 deletions.
2 changes: 1 addition & 1 deletion docs/rule/no-invalid-aria-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This rule **forbids** the following:
```hbs
<input type="text" aria-not-real="true" />
<div role="region" aria-live="bogus">Inaccessible live region</div>',
<button type="submit" aria-invalid={{if this.foo "true" "woosh"}}>Submit</button>
<button type="submit" disabled="true" aria-disabled="123">Submit</button>
```

This rule **allows** the following:
Expand Down
38 changes: 4 additions & 34 deletions lib/rules/no-invalid-aria-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,6 @@ function validityCheck(expectedType, permittedValues, allowUndefined, value) {
}
}

function getValuesFromMustache(mustacheNode) {
let valuesList = [];
if (['BooleanLiteral', 'NumberLiteral', 'StringLiteral'].includes(mustacheNode.path.type)) {
valuesList.push(mustacheNode.path.original);
} else if (mustacheNode.path.type === 'PathExpression') {
if (mustacheNode.path.original === 'if' || mustacheNode.path.original === 'unless') {
if (mustacheNode.params.length === 2 || mustacheNode.params.length === 3) {
valuesList.push(mustacheNode.params[1].value);
}
if (mustacheNode.params.length === 3) {
valuesList.push(mustacheNode.params[2].value);
}
}
}
return valuesList;
}

export default class NoInvalidAriaAttributes extends Rule {
visitor() {
return {
Expand All @@ -126,24 +109,11 @@ export default class NoInvalidAriaAttributes extends Rule {
let allowUndefined = validAriaAttribute.allowundefined || false;
let isValidValue;
// Skip validation for interpolated string values
if (attribute.value.type === 'ConcatStatement') {
if (
attribute.value.type === 'MustacheStatement' ||
attribute.value.type === 'ConcatStatement'
) {
return;
} else if (attribute.value.type === 'MustacheStatement') {
if (attribute.value.path) {
let valuesList = getValuesFromMustache(attribute.value);
if (valuesList.length === 0) {
isValidValue = true;
} else {
for (let value of valuesList) {
isValidValue = validityCheck(
expectedType,
permittedValues,
allowUndefined,
value
);
}
}
}
} else {
isValidValue = validityCheck(
expectedType,
Expand Down
81 changes: 1 addition & 80 deletions test/unit/rules/no-invalid-aria-attributes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ generateRuleTests({
'<button type="submit" aria-disabled={{this.isDisabled}}>Submit</button>',
'<div role="textbox" aria-sort={{if this.hasCustomSort "other" "ascending"}}></div>',
'<div role="combobox" aria-expanded="undefined"></div>',
'<button aria-label={{if @isNew (t "actions.add") (t "actions.edit")}}></button>',
],
bad: [
{
Expand Down Expand Up @@ -166,26 +167,6 @@ generateRuleTests({
`);
},
},
{
template: '<input type="password" required="true" aria-errormessage={{0}} />',
verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
[
{
"column": 0,
"endColumn": 65,
"endLine": 1,
"filePath": "layout.hbs",
"line": 1,
"message": "The value for aria-errormessage must be a string that represents a DOM element ID",
"rule": "no-invalid-aria-attributes",
"severity": 2,
"source": "<input type=\\"password\\" required=\\"true\\" aria-errormessage={{0}} />",
},
]
`);
},
},
{
template:
'<button type="submit" aria-describedby="blah false">Continue at your own risk</button>',
Expand All @@ -207,26 +188,6 @@ generateRuleTests({
`);
},
},
{
template: '<button type="submit" aria-describedby={{false}} >broken button</button>',
verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
[
{
"column": 0,
"endColumn": 72,
"endLine": 1,
"filePath": "layout.hbs",
"line": 1,
"message": "The value for aria-describedby must be a list of strings that represent DOM element IDs (idlist)",
"rule": "no-invalid-aria-attributes",
"severity": 2,
"source": "<button type=\\"submit\\" aria-describedby={{false}} >broken button</button>",
},
]
`);
},
},
{
template: '<div role="heading" aria-level="bogus">Inaccessible heading</div>',
verifyResults(results) {
Expand Down Expand Up @@ -267,26 +228,6 @@ generateRuleTests({
`);
},
},
{
template: '<div role="heading" aria-level={{"blah"}}>Broken heading</div>',
verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
[
{
"column": 0,
"endColumn": 62,
"endLine": 1,
"filePath": "layout.hbs",
"line": 1,
"message": "The value for aria-level must be an integer.",
"rule": "no-invalid-aria-attributes",
"severity": 2,
"source": "<div role=\\"heading\\" aria-level={{\\"blah\\"}}>Broken heading</div>",
},
]
`);
},
},
{
template:
'<div role="slider" aria-valuenow=(2*2) aria-valuemax="100" aria-valuemin="30">Broken slider</div>',
Expand Down Expand Up @@ -349,26 +290,6 @@ generateRuleTests({
`);
},
},
{
template: '<input type="text" aria-required={{if this.foo "true" "woosh"}} />',
verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
[
{
"column": 0,
"endColumn": 66,
"endLine": 1,
"filePath": "layout.hbs",
"line": 1,
"message": "The value for aria-required must be a boolean.",
"rule": "no-invalid-aria-attributes",
"severity": 2,
"source": "<input type=\\"text\\" aria-required={{if this.foo \\"true\\" \\"woosh\\"}} />",
},
]
`);
},
},
{
template: '<input type="text" aria-required="undefined" />',
verifyResults(results) {
Expand Down

0 comments on commit 714250d

Please sign in to comment.