Skip to content

Commit c3374d1

Browse files
committed
[new] - Integrate with latest jsx-ast-utils propName API
more robust name extraction
1 parent c7d973d commit c3374d1

7 files changed

+29
-18
lines changed

src/rules/aria-props.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import ariaAttributes from '../util/attributes/ARIA';
1111
import getSuggestion from '../util/getSuggestion';
12+
import { propName } from 'jsx-ast-utils';
1213

1314
const errorMessage = name => {
1415
const dictionary = Object.keys(ariaAttributes).map(aria => aria.toLowerCase());
@@ -24,8 +25,8 @@ const errorMessage = name => {
2425

2526
module.exports = context => ({
2627
JSXAttribute: attribute => {
27-
const name = attribute.name.name;
28-
const normalizedName = name.toUpperCase();
28+
const name = propName(attribute);
29+
const normalizedName = name ? name.toUpperCase() : '';
2930

3031
// `aria` needs to be prefix of property.
3132
if (normalizedName.indexOf('ARIA-') !== 0) {

src/rules/aria-proptypes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// ----------------------------------------------------------------------------
99

1010
import ariaAttributes from '../util/attributes/ARIA';
11-
import { getLiteralPropValue } from 'jsx-ast-utils';
11+
import { getLiteralPropValue, propName } from 'jsx-ast-utils';
1212

1313
const errorMessage = (name, type, permittedValues) => {
1414
switch (type) {
@@ -52,8 +52,8 @@ const validityCheck = (value, expectedType, permittedValues) => {
5252

5353
module.exports = context => ({
5454
JSXAttribute: attribute => {
55-
const name = attribute.name.name;
56-
const normalizedName = name.toUpperCase();
55+
const name = propName(attribute);
56+
const normalizedName = name ? name.toUpperCase() : '';
5757

5858
// Not a valid aria-* state or property.
5959
if (normalizedName.indexOf('ARIA-') !== 0 || ariaAttributes[normalizedName] === undefined) {

src/rules/aria-role.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
// ----------------------------------------------------------------------------
99

1010
import roles from '../util/attributes/role';
11-
import { getLiteralPropValue } from 'jsx-ast-utils';
11+
import { getLiteralPropValue, propName } from 'jsx-ast-utils';
1212

1313
const errorMessage = 'Elements with ARIA roles must use a valid, non-abstract ARIA role.';
1414

1515
module.exports = context => ({
1616
JSXAttribute: attribute => {
17-
const normalizedName = attribute.name.name.toUpperCase();
17+
const name = propName(attribute);
18+
const normalizedName = name ? name.toUpperCase() : '';
19+
1820
if (normalizedName !== 'ROLE') {
1921
return;
2022
}

src/rules/aria-unsupported-elements.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import DOM from '../util/attributes/DOM';
1212
import ARIA from '../util/attributes/ARIA';
13-
import { elementType } from 'jsx-ast-utils';
13+
import { elementType, propName } from 'jsx-ast-utils';
1414

1515
const errorMessage = invalidProp =>
1616
`This element does not support ARIA roles, states and properties. \
@@ -34,10 +34,13 @@ module.exports = context => ({
3434
return;
3535
}
3636

37-
if (invalidAttributes.indexOf(prop.name.name.toUpperCase()) > -1) {
37+
const name = propName(prop);
38+
const normalizedName = name ? name.toUpperCase() : '';
39+
40+
if (invalidAttributes.indexOf(normalizedName) > -1) {
3841
context.report({
3942
node,
40-
message: errorMessage(prop.name.name),
43+
message: errorMessage(name),
4144
});
4245
}
4346
});

src/rules/role-has-required-aria-props.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// ----------------------------------------------------------------------------
1010

1111
import validRoleTypes from '../util/attributes/role';
12-
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
12+
import { getProp, getLiteralPropValue, propName } from 'jsx-ast-utils';
1313

1414

1515
const errorMessage = (role, requiredProps) =>
@@ -18,7 +18,9 @@ const errorMessage = (role, requiredProps) =>
1818

1919
module.exports = context => ({
2020
JSXAttribute: attribute => {
21-
const normalizedName = attribute.name.name.toUpperCase();
21+
const name = propName(attribute);
22+
const normalizedName = name ? name.toUpperCase() : '';
23+
2224
if (normalizedName !== 'ROLE') {
2325
return;
2426
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import ROLES from '../util/attributes/role';
1212
import ARIA from '../util/attributes/ARIA';
1313
import getImplicitRole from '../util/getImplicitRole';
14-
import { getProp, getLiteralPropValue, elementType } from 'jsx-ast-utils';
14+
import { getProp, getLiteralPropValue, elementType, propName } from 'jsx-ast-utils';
1515

1616
const errorMessage = (attr, role, tag, isImplicit) => {
1717
if (isImplicit) {
@@ -47,10 +47,13 @@ module.exports = context => ({
4747
return;
4848
}
4949

50-
if (invalidAriaPropsForRole.indexOf(prop.name.name.toUpperCase()) > -1) {
50+
const name = propName(prop);
51+
const normalizedName = name ? name.toUpperCase() : '';
52+
53+
if (invalidAriaPropsForRole.indexOf(normalizedName) > -1) {
5154
context.report({
5255
node,
53-
message: errorMessage(prop.name.name, roleValue, type, isImplicit),
56+
message: errorMessage(name, roleValue, type, isImplicit),
5457
});
5558
}
5659
});

src/rules/tabindex-no-positive.js

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

10-
import { getLiteralPropValue } from 'jsx-ast-utils';
10+
import { getLiteralPropValue, propName } from 'jsx-ast-utils';
1111

1212
const errorMessage = 'Avoid positive integer values for tabIndex.';
1313

1414
module.exports = context => ({
1515
JSXAttribute: attribute => {
16-
const name = attribute.name.name;
17-
const normalizedName = name.toUpperCase();
16+
const name = propName(attribute);
17+
const normalizedName = name ? name.toUpperCase() : '';
1818

1919
// Check if tabIndex is the attribute
2020
if (normalizedName !== 'TABINDEX') {

0 commit comments

Comments
 (0)