Skip to content

Commit e5b0f97

Browse files
authored
update fixer for has-valid-accessibility-descriptors (#136)
1 parent caa2219 commit e5b0f97

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,24 @@ ruleTester.run('has-valid-accessibility-descriptors', rule, {
7171
<Text>Back</Text>
7272
</TouchableOpacity>`,
7373
},
74+
{
75+
code: `<TouchableBounce {...props} hostRef={hostRef} />`,
76+
},
7477
].map(parserOptionsMapper),
7578
invalid: [
7679
{
7780
code: `<TouchableOpacity>
7881
<Text>Back</Text>
7982
</TouchableOpacity>`,
8083
errors: [expectedError],
81-
output: `<TouchableOpacity accessible={false}>
84+
output: `<TouchableOpacity accessibilityRole="button">
8285
<Text>Back</Text>
8386
</TouchableOpacity>`,
8487
},
8588
{
8689
code: `<TextInput />`,
8790
errors: [expectedError],
88-
output: `<TextInput accessible={false} />`,
91+
output: `<TextInput accessibilityLabel="Text input field" />`,
8992
},
9093
].map(parserOptionsMapper),
9194
});

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const errorMessage =
1919

2020
const schema = generateObjSchema();
2121

22+
const hasSpreadProps = (attributes) =>
23+
attributes.some((attr) => attr.type === 'JSXSpreadAttribute');
24+
2225
module.exports = {
2326
meta: {
2427
docs: {},
@@ -35,7 +38,8 @@ module.exports = {
3538
'accessibilityLabel',
3639
'accessibilityActions',
3740
'accessible',
38-
])
41+
]) &&
42+
!hasSpreadProps(node.attributes)
3943
) {
4044
context.report({
4145
node,
@@ -44,7 +48,9 @@ module.exports = {
4448
return fixer.insertTextAfterRange(
4549
// $FlowFixMe
4650
node.name.range,
47-
' accessible={false}'
51+
isTouchable(node, context)
52+
? ' accessibilityRole="button"'
53+
: ' accessibilityLabel="Text input field"'
4854
);
4955
},
5056
});

0 commit comments

Comments
 (0)