Skip to content

Commit afe7b91

Browse files
authored
only validate Literals in accessibilityState (#112)
1 parent 25020c1 commit afe7b91

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@ ruleTester.run('has-valid-accessibility-state', rule, {
6262
<TouchableHighlight accessibilityState={{ selected: itemChecked }} />
6363
</>`,
6464
},
65+
{
66+
code: `const isFirst = () => {
67+
return something === "example";
68+
}
69+
70+
<TouchableOpacity
71+
accessible
72+
accessibilityState={{ disabled: isFirst() }}
73+
disabled={isFirst()}
74+
/>`,
75+
},
76+
{
77+
code: `const myObj = {
78+
myBool: true
79+
};
80+
81+
<TouchableOpacity
82+
accessible
83+
accessibilityState={{ checked: myObj.myBool }}
84+
/>`,
85+
},
6586
].map(parserOptionsMapper),
6687
invalid: [
6788
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ module.exports = {
4242
// $FlowFixMe
4343
(f) => f.key.name === key
4444
);
45-
// we can't determine the associated value type of an Identifier expression
45+
// we can't determine the associated value type of non-Literal expressions
4646
// treat these cases as though they are valid
4747
// $FlowFixMe
48-
if (astObjectProp && astObjectProp.value.type !== 'Identifier') {
48+
if (astObjectProp && astObjectProp.value.type === 'Literal') {
4949
if (validKeys.indexOf(key) < 0) {
5050
error(`accessibilityState object: "${key}" is not a valid key`);
5151
} else if (

0 commit comments

Comments
 (0)