Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions __tests__/src/rules/has-valid-accessibility-state-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ ruleTester.run('has-valid-accessibility-state', rule, {
<TouchableOpacity accessibilityState={{ selected: active }} />
);`,
},
{
code: `const itemChecked = true;

<>
<TouchableHighlight accessibilityState={{ checked: itemChecked }} />
<TouchableHighlight accessibilityState={{ selected: itemChecked }} />
</>`,
},
].map(parserOptionsMapper),
invalid: [
{
Expand Down
36 changes: 18 additions & 18 deletions src/rules/has-valid-accessibility-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,25 @@ module.exports = {
error('accessibilityState must be an object');
} else {
Object.entries(attrValue).map(([key, value]) => {
if (validKeys.indexOf(key) < 0) {
error(`accessibilityState object: "${key}" is not a valid key`);
} else if (
key === 'checked' &&
!(typeof value === 'boolean' || value === 'mixed')
) {
error(
`accessibilityState object: "checked" value is not either a boolean or 'mixed'`
);
} else if (key !== 'checked' && typeof value !== 'boolean') {
// $FlowFixMe
const astObjectProp = node.value.expression.properties.find(
// $FlowFixMe
const astObjectProp = node.value.expression.properties.find(
// $FlowFixMe
(f) => f.key.name === key
);
// we can't determine the associated value type of an Identifier expression
// treat these cases as though they are valid
// $FlowFixMe
if (astObjectProp && astObjectProp.value.type !== 'Identifier') {
(f) => f.key.name === key
);
// we can't determine the associated value type of an Identifier expression
// treat these cases as though they are valid
// $FlowFixMe
if (astObjectProp && astObjectProp.value.type !== 'Identifier') {
if (validKeys.indexOf(key) < 0) {
error(`accessibilityState object: "${key}" is not a valid key`);
} else if (
key === 'checked' &&
!(typeof value === 'boolean' || value === 'mixed')
) {
error(
`accessibilityState object: "checked" value is not either a boolean or 'mixed'`
);
} else if (key !== 'checked' && typeof value !== 'boolean') {
error(
`accessibilityState object: "${key}" value is not a boolean`
);
Expand Down