From a1ab32b11bba462a5a5785d06945db43f8e0328e Mon Sep 17 00:00:00 2001 From: Judith Lung Date: Wed, 13 Apr 2022 13:36:49 -0700 Subject: [PATCH] Removes validation of mustache statements in `no-invalid-aria-attributes` rule --- docs/rule/no-invalid-aria-attributes.md | 2 +- lib/rules/no-invalid-aria-attributes.js | 38 +-------- .../rules/no-invalid-aria-attributes-test.js | 81 +------------------ 3 files changed, 6 insertions(+), 115 deletions(-) diff --git a/docs/rule/no-invalid-aria-attributes.md b/docs/rule/no-invalid-aria-attributes.md index 8246503d0..8b0fa5a0b 100644 --- a/docs/rule/no-invalid-aria-attributes.md +++ b/docs/rule/no-invalid-aria-attributes.md @@ -11,7 +11,7 @@ This rule **forbids** the following: ```hbs
Inaccessible live region
', - + ``` This rule **allows** the following: diff --git a/lib/rules/no-invalid-aria-attributes.js b/lib/rules/no-invalid-aria-attributes.js index 88a3bf8c7..0d434f462 100644 --- a/lib/rules/no-invalid-aria-attributes.js +++ b/lib/rules/no-invalid-aria-attributes.js @@ -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 { @@ -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, diff --git a/test/unit/rules/no-invalid-aria-attributes-test.js b/test/unit/rules/no-invalid-aria-attributes-test.js index 2163fc93a..099d1b37f 100644 --- a/test/unit/rules/no-invalid-aria-attributes-test.js +++ b/test/unit/rules/no-invalid-aria-attributes-test.js @@ -22,6 +22,7 @@ generateRuleTests({ '', '
', '
', + '', ], bad: [ { @@ -166,26 +167,6 @@ generateRuleTests({ `); }, }, - { - template: '', - 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": "", - }, - ] - `); - }, - }, { template: '', @@ -207,26 +188,6 @@ generateRuleTests({ `); }, }, - { - template: '', - 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": "", - }, - ] - `); - }, - }, { template: '
Inaccessible heading
', verifyResults(results) { @@ -267,26 +228,6 @@ generateRuleTests({ `); }, }, - { - template: '
Broken heading
', - 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": "
Broken heading
", - }, - ] - `); - }, - }, { template: '
Broken slider
', @@ -349,26 +290,6 @@ generateRuleTests({ `); }, }, - { - template: '', - 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": "", - }, - ] - `); - }, - }, { template: '', verifyResults(results) {