Skip to content

Commit 07ed619

Browse files
authored
Fix x-has-content rules to check for children prop (#92)
* [fix] - check for children prop in x-has-content rules. * Fix lint. * Fix tests.
1 parent 05b119c commit 07ed619

34 files changed

+47
-45
lines changed

src/rules/anchor-has-content.js

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

10-
import { elementType, hasProp } from 'jsx-ast-utils';
10+
import { elementType, hasAnyProp } from 'jsx-ast-utils';
1111
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
1212

1313
const errorMessage =
@@ -40,15 +40,15 @@ module.exports = {
4040
},
4141

4242
create: context => ({
43-
JSXOpeningElement: node => {
43+
JSXOpeningElement: (node) => {
4444
const typeCheck = anchors.concat(context.options[0]);
4545
const nodeType = elementType(node);
4646

4747
// Only check anchor elements and custom types.
4848
if (typeCheck.indexOf(nodeType) === -1) {
4949
return;
5050
}
51-
const isAccessible = node.parent.children.some(child => {
51+
const isAccessible = node.parent.children.some((child) => {
5252
switch (child.type) {
5353
case 'Literal':
5454
return Boolean(child.value);
@@ -65,7 +65,7 @@ module.exports = {
6565
default:
6666
return false;
6767
}
68-
}) || hasProp(node.attributes, 'dangerouslySetInnerHTML');
68+
}) || hasAnyProp(node.attributes, ['dangerouslySetInnerHTML', 'children']);
6969

7070

7171
if (isAccessible) {

src/rules/aria-props.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { propName } from 'jsx-ast-utils';
1111
import ariaAttributes from '../util/attributes/ARIA';
1212
import getSuggestion from '../util/getSuggestion';
1313

14-
const errorMessage = name => {
14+
const errorMessage = (name) => {
1515
const dictionary = Object.keys(ariaAttributes).map(aria => aria.toLowerCase());
1616
const suggestions = getSuggestion(name, dictionary);
1717
const message = `${name}: This attribute is an invalid ARIA attribute.`;
@@ -33,7 +33,7 @@ module.exports = {
3333
},
3434

3535
create: context => ({
36-
JSXAttribute: attribute => {
36+
JSXAttribute: (attribute) => {
3737
const name = propName(attribute);
3838
const normalizedName = name ? name.toUpperCase() : '';
3939

src/rules/aria-proptypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = {
6060
},
6161

6262
create: context => ({
63-
JSXAttribute: attribute => {
63+
JSXAttribute: (attribute) => {
6464
const name = propName(attribute);
6565
const normalizedName = name ? name.toUpperCase() : '';
6666

src/rules/aria-role.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
},
2323

2424
create: context => ({
25-
JSXAttribute: attribute => {
25+
JSXAttribute: (attribute) => {
2626
const name = propName(attribute);
2727
const normalizedName = name ? name.toUpperCase() : '';
2828

src/rules/aria-unsupported-elements.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
},
2727

2828
create: context => ({
29-
JSXOpeningElement: node => {
29+
JSXOpeningElement: (node) => {
3030
const nodeType = elementType(node);
3131
const nodeAttrs = DOM[nodeType] || {};
3232
const {
@@ -40,7 +40,7 @@ module.exports = {
4040

4141
const invalidAttributes = Object.keys(ARIA).concat('ROLE');
4242

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

src/rules/click-events-have-key-events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
},
2525

2626
create: context => ({
27-
JSXOpeningElement: node => {
27+
JSXOpeningElement: (node) => {
2828
const props = node.attributes;
2929
if (getProp(props, 'onclick') === undefined) {
3030
return;

src/rules/heading-has-content.js

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

10-
import { elementType, hasProp } from 'jsx-ast-utils';
10+
import { elementType, hasAnyProp } from 'jsx-ast-utils';
1111
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
1212

1313
const errorMessage =
@@ -44,7 +44,7 @@ module.exports = {
4444
},
4545

4646
create: context => ({
47-
JSXOpeningElement: node => {
47+
JSXOpeningElement: (node) => {
4848
const typeCheck = headings.concat(context.options[0]);
4949
const nodeType = elementType(node);
5050

@@ -53,7 +53,7 @@ module.exports = {
5353
return;
5454
}
5555

56-
const isAccessible = node.parent.children.some(child => {
56+
const isAccessible = node.parent.children.some((child) => {
5757
switch (child.type) {
5858
case 'Literal':
5959
return Boolean(child.value);
@@ -70,7 +70,7 @@ module.exports = {
7070
default:
7171
return false;
7272
}
73-
}) || hasProp(node.attributes, 'dangerouslySetInnerHTML');
73+
}) || hasAnyProp(node.attributes, ['dangerouslySetInnerHTML', 'children']);
7474

7575

7676
if (isAccessible) {

src/rules/href-no-hash.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434
},
3535

3636
create: context => ({
37-
JSXOpeningElement: node => {
37+
JSXOpeningElement: (node) => {
3838
const typeCheck = ['a'].concat(context.options[0]);
3939
const nodeType = elementType(node);
4040

src/rules/html-has-lang.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
},
2222

2323
create: context => ({
24-
JSXOpeningElement: node => {
24+
JSXOpeningElement: (node) => {
2525
const type = elementType(node);
2626

2727
if (type && type !== 'html') {

src/rules/img-has-alt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
},
3232

3333
create: context => ({
34-
JSXOpeningElement: node => {
34+
JSXOpeningElement: (node) => {
3535
const typeCheck = ['img'].concat(context.options[0]);
3636
const nodeType = elementType(node);
3737

0 commit comments

Comments
 (0)