Skip to content

only validate Literals in accessibilityState #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2021
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
21 changes: 21 additions & 0 deletions __tests__/src/rules/has-valid-accessibility-state-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ ruleTester.run('has-valid-accessibility-state', rule, {
<TouchableHighlight accessibilityState={{ selected: itemChecked }} />
</>`,
},
{
code: `const isFirst = () => {
return something === "example";
}

<TouchableOpacity
accessible
accessibilityState={{ disabled: isFirst() }}
disabled={isFirst()}
/>`,
},
{
code: `const myObj = {
myBool: true
};

<TouchableOpacity
accessible
accessibilityState={{ checked: myObj.myBool }}
/>`,
},
].map(parserOptionsMapper),
invalid: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/rules/has-valid-accessibility-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ module.exports = {
// $FlowFixMe
(f) => f.key.name === key
);
// we can't determine the associated value type of an Identifier expression
// we can't determine the associated value type of non-Literal expressions
// treat these cases as though they are valid
// $FlowFixMe
if (astObjectProp && astObjectProp.value.type !== 'Identifier') {
if (astObjectProp && astObjectProp.value.type === 'Literal') {
if (validKeys.indexOf(key) < 0) {
error(`accessibilityState object: "${key}" is not a valid key`);
} else if (
Expand Down