Skip to content

Commit 762f44c

Browse files
committed
Replaces ARIA.json with aria-query::aria
1 parent 24b9922 commit 762f44c

File tree

8 files changed

+34
-144
lines changed

8 files changed

+34
-144
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
// Requirements
99
// -----------------------------------------------------------------------------
1010

11+
import { aria } from 'aria-query';
1112
import { RuleTester } from 'eslint';
1213
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
1314
import rule from '../../../src/rules/aria-props';
14-
import ariaAttributes from '../../../src/util/attributes/ARIA.json';
1515
import getSuggestion from '../../../src/util/getSuggestion';
1616

1717
// -----------------------------------------------------------------------------
1818
// Tests
1919
// -----------------------------------------------------------------------------
2020

2121
const ruleTester = new RuleTester();
22+
const ariaAttributes = [...aria.keys()];
2223

2324
const errorMessage = (name) => {
24-
const dictionary = Object.keys(ariaAttributes).map(aria => aria.toLowerCase());
25-
const suggestions = getSuggestion(name, dictionary);
25+
const suggestions = getSuggestion(name, ariaAttributes);
2626
const message = `${name}: This attribute is an invalid ARIA attribute.`;
2727

2828
if (suggestions.length > 0) {
@@ -39,7 +39,7 @@ const errorMessage = (name) => {
3939
};
4040

4141
// Create basic test cases using all valid role types.
42-
const basicValidityTests = Object.keys(ariaAttributes).map(prop => ({
42+
const basicValidityTests = ariaAttributes.map(prop => ({
4343
code: `<div ${prop.toLowerCase()}="foobar" />`,
4444
}));
4545

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// Requirements
99
// -----------------------------------------------------------------------------
1010

11+
import { aria } from 'aria-query';
1112
import { RuleTester } from 'eslint';
12-
import ariaAttributes from '../../../src/util/attributes/ARIA.json';
1313
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
1414
import rule, { validityCheck } from '../../../src/rules/aria-proptypes';
1515

@@ -20,7 +20,10 @@ import rule, { validityCheck } from '../../../src/rules/aria-proptypes';
2020
const ruleTester = new RuleTester();
2121

2222
const errorMessage = (name) => {
23-
const { type, values: permittedValues } = ariaAttributes[name.toUpperCase()];
23+
const {
24+
type,
25+
values: permittedValues,
26+
} = aria.get(name.toLowerCase());
2427

2528
switch (type) {
2629
case 'tristate':

__tests__/src/rules/role-supports-aria-props-test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
// Requirements
99
// -----------------------------------------------------------------------------
1010

11-
import { roles } from 'aria-query';
11+
import {
12+
aria,
13+
roles,
14+
} from 'aria-query';
1215
import { RuleTester } from 'eslint';
1316
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
1417
import rule from '../../../src/rules/role-supports-aria-props';
15-
import ARIA from '../../../src/util/attributes/ARIA.json';
1618

1719
// -----------------------------------------------------------------------------
1820
// Tests
@@ -38,7 +40,7 @@ const nonAbstractRoles = [...roles.keys()].filter(role => roles.get(role).abstra
3840

3941
const createTests = rolesNames => rolesNames.reduce((tests, role) => {
4042
const validPropsForRole = roles.get(role.toLowerCase()).props;
41-
const invalidPropsForRole = Object.keys(ARIA)
43+
const invalidPropsForRole = [...aria.keys()]
4244
.map(attribute => attribute.toLowerCase())
4345
.filter(attribute => validPropsForRole.indexOf(attribute) === -1);
4446
const normalRole = role.toLowerCase();

src/rules/aria-props.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
// Rule Definition
88
// ----------------------------------------------------------------------------
99

10+
import { aria } from 'aria-query';
1011
import { propName } from 'jsx-ast-utils';
1112
import { generateObjSchema } from '../util/schemas';
12-
import ariaAttributes from '../util/attributes/ARIA.json';
1313
import getSuggestion from '../util/getSuggestion';
1414

15+
const ariaAttributes = [...aria.keys()];
16+
1517
const errorMessage = (name) => {
16-
const dictionary = Object.keys(ariaAttributes).map(aria => aria.toLowerCase());
17-
const suggestions = getSuggestion(name, dictionary);
18+
const suggestions = getSuggestion(name, ariaAttributes);
1819
const message = `${name}: This attribute is an invalid ARIA attribute.`;
1920

2021
if (suggestions.length > 0) {
@@ -35,14 +36,14 @@ module.exports = {
3536
create: context => ({
3637
JSXAttribute: (attribute) => {
3738
const name = propName(attribute);
38-
const normalizedName = name ? name.toUpperCase() : '';
39+
const normalizedName = name ? name.toLowerCase() : '';
3940

4041
// `aria` needs to be prefix of property.
41-
if (normalizedName.indexOf('ARIA-') !== 0) {
42+
if (normalizedName.indexOf('aria-') !== 0) {
4243
return;
4344
}
4445

45-
const isValid = Object.keys(ariaAttributes).indexOf(normalizedName) > -1;
46+
const isValid = ariaAttributes.indexOf(normalizedName) > -1;
4647

4748
if (isValid === false) {
4849
context.report({

src/rules/aria-proptypes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
// Rule Definition
88
// ----------------------------------------------------------------------------
99

10+
import { aria } from 'aria-query';
1011
import { getLiteralPropValue, propName } from 'jsx-ast-utils';
1112
import { generateObjSchema } from '../util/schemas';
12-
import ariaAttributes from '../util/attributes/ARIA.json';
1313

1414
const errorMessage = (name, type, permittedValues) => {
1515
switch (type) {
@@ -63,10 +63,10 @@ module.exports = {
6363
create: context => ({
6464
JSXAttribute: (attribute) => {
6565
const name = propName(attribute);
66-
const normalizedName = name ? name.toUpperCase() : '';
66+
const normalizedName = name ? name.toLowerCase() : '';
6767

6868
// Not a valid aria-* state or property.
69-
if (normalizedName.indexOf('ARIA-') !== 0 || ariaAttributes[normalizedName] === undefined) {
69+
if (normalizedName.indexOf('aria-') !== 0 || aria.get(normalizedName) === undefined) {
7070
return;
7171
}
7272

@@ -78,7 +78,7 @@ module.exports = {
7878
}
7979

8080
// These are the attributes of the property/state to check against.
81-
const attributes = ariaAttributes[normalizedName];
81+
const attributes = aria.get(normalizedName);
8282
const permittedType = attributes.type;
8383
const allowUndefined = attributes.allowUndefined || false;
8484
const permittedValues = attributes.values || [];

src/rules/aria-unsupported-elements.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
// Rule Definition
99
// ----------------------------------------------------------------------------
1010

11+
import { aria } from 'aria-query';
1112
import { elementType, propName } from 'jsx-ast-utils';
1213
import { generateObjSchema } from '../util/schemas';
1314
import DOM from '../util/attributes/DOM.json';
14-
import ARIA from '../util/attributes/ARIA.json';
1515

1616
const errorMessage = invalidProp =>
1717
`This element does not support ARIA roles, states and properties. \
@@ -33,20 +33,20 @@ module.exports = {
3333
reserved: isReservedNodeType = false,
3434
} = nodeAttrs;
3535

36-
// If it's not reserved, then it can have ARIA-* roles, states, and properties
36+
// If it's not reserved, then it can have aria-* roles, states, and properties
3737
if (isReservedNodeType === false) {
3838
return;
3939
}
4040

41-
const invalidAttributes = Object.keys(ARIA).concat('ROLE');
41+
const invalidAttributes = [...aria.keys()].concat('role');
4242

4343
node.attributes.forEach((prop) => {
4444
if (prop.type === 'JSXSpreadAttribute') {
4545
return;
4646
}
4747

4848
const name = propName(prop);
49-
const normalizedName = name ? name.toUpperCase() : '';
49+
const normalizedName = name ? name.toLowerCase() : '';
5050

5151
if (invalidAttributes.indexOf(normalizedName) > -1) {
5252
context.report({

src/rules/role-supports-aria-props.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
// Rule Definition
99
// ----------------------------------------------------------------------------
1010

11-
import { roles } from 'aria-query';
11+
import {
12+
aria,
13+
roles,
14+
} from 'aria-query';
1215
import { getProp, getLiteralPropValue, elementType, propName } from 'jsx-ast-utils';
1316
import { generateObjSchema } from '../util/schemas';
14-
import ARIA from '../util/attributes/ARIA.json';
1517
import getImplicitRole from '../util/getImplicitRole';
1618

1719
const errorMessage = (attr, role, tag, isImplicit) => {
@@ -51,7 +53,7 @@ module.exports = {
5153

5254
// Make sure it has no aria-* properties defined outside of its property set.
5355
const propertySet = roles.get(roleValue.toLowerCase()).props;
54-
const invalidAriaPropsForRole = Object.keys(ARIA)
56+
const invalidAriaPropsForRole = [...aria.keys()]
5557
.map(attribute => attribute.toLowerCase())
5658
.filter(attribute => propertySet.indexOf(attribute) === -1);
5759

src/util/attributes/ARIA.json

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)