Skip to content

Commit 8fa7d4a

Browse files
authored
Merge pull request #456 from jessebeach/fix-aria-proptypes-rule
[#454] Fix for aria-proptypes rule failure
2 parents b800f40 + f22711e commit 8fa7d4a

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
6.1.1 / 2018-07-03
2+
3+
- [fix] aria-proptypes support for idlist, #454
4+
15
6.1.0 / 2018-06-26
26
==================
37
- [new] Support for eslint v5, #451

__tests__/src/rules/aria-proptypes-test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ const errorMessage = (name) => {
3535
case 'tokenlist':
3636
return `The value for ${name} must be a list of one or more \
3737
tokens from the following: ${permittedValues}.`;
38+
case 'idlist':
39+
return `The value for ${name} must be a list of strings that represent DOM element IDs (idlist)`;
40+
case 'id':
41+
return `The value for ${name} must be a string that represents a DOM element ID`;
3842
case 'boolean':
3943
case 'string':
4044
case 'integer':
@@ -155,6 +159,40 @@ ruleTester.run('aria-proptypes', rule, {
155159
{ code: '<div aria-relevant={`removals additions text all`} />' },
156160
{ code: '<div aria-relevant={foo} />' },
157161
{ code: '<div aria-relevant={foo.bar} />' },
162+
163+
// ID
164+
{ code: '<div aria-activedescendant="ascending" />' },
165+
{ code: '<div aria-activedescendant="ASCENDING" />' },
166+
{ code: '<div aria-activedescendant={"ascending"} />' },
167+
{ code: '<div aria-activedescendant={`ascending`} />' },
168+
{ code: '<div aria-activedescendant="descending" />' },
169+
{ code: '<div aria-activedescendant={"descending"} />' },
170+
{ code: '<div aria-activedescendant={`descending`} />' },
171+
{ code: '<div aria-activedescendant="none" />' },
172+
{ code: '<div aria-activedescendant={"none"} />' },
173+
{ code: '<div aria-activedescendant={`none`} />' },
174+
{ code: '<div aria-activedescendant="other" />' },
175+
{ code: '<div aria-activedescendant={"other"} />' },
176+
{ code: '<div aria-activedescendant={`other`} />' },
177+
{ code: '<div aria-activedescendant={foo} />' },
178+
{ code: '<div aria-activedescendant={foo.bar} />' },
179+
180+
// IDLIST
181+
{ code: '<div aria-labelledby="additions" />' },
182+
{ code: '<div aria-labelledby={"additions"} />' },
183+
{ code: '<div aria-labelledby={`additions`} />' },
184+
{ code: '<div aria-labelledby="additions removals" />' },
185+
{ code: '<div aria-labelledby="additions additions" />' },
186+
{ code: '<div aria-labelledby={"additions removals"} />' },
187+
{ code: '<div aria-labelledby={`additions removals`} />' },
188+
{ code: '<div aria-labelledby="additions removals text" />' },
189+
{ code: '<div aria-labelledby={"additions removals text"} />' },
190+
{ code: '<div aria-labelledby={`additions removals text`} />' },
191+
{ code: '<div aria-labelledby="additions removals text all" />' },
192+
{ code: '<div aria-labelledby={"additions removals text all"} />' },
193+
{ code: '<div aria-labelledby={`removals additions text all`} />' },
194+
{ code: '<div aria-labelledby={foo} />' },
195+
{ code: '<div aria-labelledby={foo.bar} />' },
158196
].map(parserOptionsMapper),
159197
invalid: [
160198
// BOOLEAN

src/rules/aria-proptypes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const errorMessage = (name, type, permittedValues) => {
2020
case 'tokenlist':
2121
return `The value for ${name} must be a list of one or more \
2222
tokens from the following: ${permittedValues}.`;
23+
case 'idlist':
24+
return `The value for ${name} must be a list of strings that represent DOM element IDs (idlist)`;
25+
case 'id':
26+
return `The value for ${name} must be a string that represents a DOM element ID`;
2327
case 'boolean':
2428
case 'string':
2529
case 'integer':
@@ -34,6 +38,7 @@ const validityCheck = (value, expectedType, permittedValues) => {
3438
case 'boolean':
3539
return typeof value === 'boolean';
3640
case 'string':
41+
case 'id':
3742
return typeof value === 'string';
3843
case 'tristate':
3944
return typeof value === 'boolean' || value === 'mixed';
@@ -44,6 +49,9 @@ const validityCheck = (value, expectedType, permittedValues) => {
4449
return typeof value !== 'boolean' && isNaN(Number(value)) === false;
4550
case 'token':
4651
return permittedValues.indexOf(typeof value === 'string' ? value.toLowerCase() : value) > -1;
52+
case 'idlist':
53+
return typeof value === 'string'
54+
&& value.split(' ').every(token => validityCheck(token, 'id', []));
4755
case 'tokenlist':
4856
return typeof value === 'string'
4957
&& value.split(' ').every(token => permittedValues.indexOf(token.toLowerCase()) > -1);

0 commit comments

Comments
 (0)