Skip to content

Commit 34b1c84

Browse files
authored
assume MemberExpressions are valid (#133)
1 parent 184fe27 commit 34b1c84

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

__tests__/src/rules/has-valid-accessibility-actions-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ ruleTester.run('has-valid-accessibility-actions', rule, {
8080
onAccessibilityAction={onAccessibilityAction}
8181
/>`,
8282
},
83+
{
84+
code: `<TouchableOpacity
85+
accessibilityActions={this.props.accessibilityActions}
86+
onAccessibilityAction={this.props.onAccessibilityAction}
87+
/>`,
88+
},
8389
].map(parserOptionsMapper),
8490
invalid: [
8591
{

src/rules/has-valid-accessibility-actions.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import type { JSXOpeningElement } from 'ast-types-flow';
88
import { getProp, getPropValue, hasEveryProp, hasProp } from 'jsx-ast-utils';
9+
import isNodePropExpression from '../util/isNodePropExpression';
910
import { generateObjSchema } from '../util/schemas';
1011
import type { ESLintContext } from '../../flow/eslint';
1112

@@ -43,12 +44,8 @@ module.exports = {
4344
])
4445
) {
4546
const handlerProp = getProp(node.attributes, 'onAccessibilityAction');
46-
const handlerPropType = handlerProp.value.expression.type;
47-
// CallExpressions & Identifiers are always assumed valid
48-
if (
49-
handlerPropType !== 'CallExpression' &&
50-
handlerPropType !== 'Identifier'
51-
) {
47+
const isHandlerExpression = isNodePropExpression(handlerProp);
48+
if (!isHandlerExpression) {
5249
const handlerPropValue = getPropValue(handlerProp);
5350
if (typeof handlerPropValue !== 'function') {
5451
error(
@@ -58,12 +55,8 @@ module.exports = {
5855
}
5956

6057
const actionsProp = getProp(node.attributes, 'accessibilityActions');
61-
const actionsPropType = actionsProp.value.expression.type;
62-
// CallExpressions & Identifiers are always assumed valid
63-
if (
64-
actionsPropType !== 'CallExpression' &&
65-
actionsPropType !== 'Identifier'
66-
) {
58+
const isActionsExpression = isNodePropExpression(actionsProp);
59+
if (!isActionsExpression) {
6760
const attrValue = getPropValue(actionsProp);
6861

6962
if (!Array.isArray(attrValue)) {

src/util/isNodePropExpression.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// @flow
22
import type { JSXAttribute } from 'ast-types-flow';
33

4-
const ALLOWED_TYPES = ['Identifier', 'ConditionalExpression'];
4+
const ALLOWED_TYPES = [
5+
'Identifier',
6+
'CallExpression',
7+
'ConditionalExpression',
8+
'MemberExpression',
9+
];
510

611
export default function isattrPropExpression(attr: JSXAttribute): boolean {
712
// $FlowFixMe

0 commit comments

Comments
 (0)