Skip to content

Commit b5ad699

Browse files
authored
make has-a11y-descriptors fixable (#131)
* make has-a11y-descriptors fixable * fix Flow error * update tests to account for fixed output
1 parent 01ff05a commit b5ad699

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

__tests__/__util__/parserOptionsMapper.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ export default function parserOptionsMapper({
99
code,
1010
errors,
1111
options = [],
12+
output = null,
1213
parserOptions = {},
1314
}) {
1415
return {
1516
code,
1617
errors,
1718
options,
19+
output,
1820
parserOptions: {
1921
...defaultParserOptions,
2022
...parserOptions,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ ruleTester.run('has-valid-accessibility-descriptors', rule, {
7878
<Text>Back</Text>
7979
</TouchableOpacity>`,
8080
errors: [expectedError],
81+
output: `<TouchableOpacity accessible={false}>
82+
<Text>Back</Text>
83+
</TouchableOpacity>`,
8184
},
8285
{
8386
code: `<TextInput />`,
8487
errors: [expectedError],
88+
output: `<TextInput accessible={false} />`,
8589
},
8690
].map(parserOptionsMapper),
8791
});

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = {
2323
meta: {
2424
docs: {},
2525
schema: [schema],
26+
fixable: 'code',
2627
},
2728

2829
create: (context: ESLintContext) => ({
@@ -39,6 +40,13 @@ module.exports = {
3940
context.report({
4041
node,
4142
message: errorMessage,
43+
fix: (fixer) => {
44+
return fixer.insertTextAfterRange(
45+
// $FlowFixMe
46+
node.name.range,
47+
' accessible={false}'
48+
);
49+
},
4250
});
4351
}
4452
}

0 commit comments

Comments
 (0)