Skip to content

Commit 29ce4f2

Browse files
authored
chore: bump eslint config to latest (#308)
* chore: bump eslint config to latest * lint fix * lint pass * use roles directly
1 parent ab34712 commit 29ce4f2

16 files changed

+139
-66
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"import/no-unresolved": [
1010
2,
1111
{ "ignore": ["^@theme", "^@docusaurus", "^@generated"] }
12-
]
12+
],
13+
"react-native-a11y/has-valid-accessibility-ignores-invert-colors": 0
1314
}
1415
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"devDependencies": {
2222
"@babel/cli": "^7.8.4",
2323
"@babel/core": "^7.9.0",
24-
"@callstack/eslint-config": "^9.1.0",
24+
"@callstack/eslint-config": "^10.0.0",
2525
"@release-it/conventional-changelog": "^1.1.0",
2626
"@types/react": "^16.9.34",
2727
"@types/react-native": "^0.62.2",

src/__tests__/a11yAPI.test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import { render } from '..';
55

66
const BUTTON_LABEL = 'cool button';
77
const BUTTON_HINT = 'click this button';
8-
const BUTTON_ROLE = 'button';
98
const TEXT_LABEL = 'cool text';
109
const TEXT_HINT = 'static text';
11-
const TEXT_ROLE = 'link';
1210
// Little hack to make all the methods happy with type
1311
const NO_MATCHES_TEXT: any = 'not-existent-element';
1412
const NO_INSTANCES_FOUND = 'No instances found';
@@ -27,13 +25,13 @@ class Button extends React.Component<any> {
2725
<TouchableOpacity
2826
accessibilityHint={BUTTON_HINT}
2927
accessibilityLabel={BUTTON_LABEL}
30-
accessibilityRole={BUTTON_ROLE}
28+
accessibilityRole="button"
3129
accessibilityStates={['selected']}
3230
>
3331
<Typography
3432
accessibilityHint={TEXT_HINT}
3533
accessibilityLabel={TEXT_LABEL}
36-
accessibilityRole={TEXT_ROLE}
34+
accessibilityRole="link"
3735
accessibilityStates={['selected']}
3836
accessibilityState={{ expanded: false, selected: true }}
3937
accessibilityValue={{ min: 40, max: 60 }}
@@ -51,7 +49,7 @@ function Section() {
5149
<Typography
5250
accessibilityHint={TEXT_HINT}
5351
accessibilityLabel={TEXT_LABEL}
54-
accessibilityRole={TEXT_ROLE}
52+
accessibilityRole="link"
5553
// $FlowFixMe - removed in RN 0.62
5654
accessibilityStates={['selected', 'disabled']}
5755
accessibilityState={{ expanded: false }}

src/__tests__/debug.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Button extends React.Component<any, any> {
3232
}
3333

3434
test('debug', () => {
35-
jest.spyOn(console, 'log').mockImplementation(x => x);
35+
jest.spyOn(console, 'log').mockImplementation((x) => x);
3636
const component = <Button onPress={jest.fn} text="Press me" />;
3737
debug(component);
3838

src/__tests__/questionsBoard.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ function QuestionsBoard({ questions, onSubmit }) {
2020
<Text>{q}</Text>
2121
<TextInput
2222
accessibilityLabel="answer input"
23-
onChangeText={text => {
24-
setData(state => ({
23+
accessibilityHint="input"
24+
onChangeText={(text) => {
25+
setData((state) => ({
2526
...state,
2627
[index + 1]: { q, a: text },
2728
}));

src/__tests__/render.test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Banana extends React.Component<any, any> {
4545
}
4646

4747
changeFresh = () => {
48-
this.setState(state => ({
48+
this.setState((state) => ({
4949
fresh: !state.fresh,
5050
}));
5151
};
@@ -320,7 +320,7 @@ test('toJSON', () => {
320320
});
321321

322322
test('debug', () => {
323-
jest.spyOn(console, 'log').mockImplementation(x => x);
323+
jest.spyOn(console, 'log').mockImplementation((x) => x);
324324

325325
const { debug } = render(<Banana />);
326326

@@ -343,7 +343,7 @@ test('debug', () => {
343343
});
344344

345345
test('debug changing component', () => {
346-
jest.spyOn(console, 'log').mockImplementation(x => x);
346+
jest.spyOn(console, 'log').mockImplementation((x) => x);
347347

348348
const { getByProps, debug } = render(<Banana />);
349349

@@ -390,7 +390,9 @@ test('renders options.wrapper around updated node', () => {
390390
wrapper: WrapperComponent,
391391
});
392392

393-
rerender(<View testID="inner" accessibilityLabel="test" />);
393+
rerender(
394+
<View testID="inner" accessibilityLabel="test" accessibilityHint="test" />
395+
);
394396

395397
expect(getByTestId('wrapper')).toBeTruthy();
396398
expect(toJSON()).toMatchInlineSnapshot(`
@@ -399,6 +401,7 @@ test('renders options.wrapper around updated node', () => {
399401
testID="wrapper"
400402
>
401403
<View
404+
accessibilityHint="test"
402405
accessibilityLabel="test"
403406
testID="inner"
404407
/>

src/__tests__/waitForElement.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class BananaContainer extends React.Component<{}, any> {
2424
state = { fresh: false };
2525

2626
onChangeFresh = async () => {
27-
await new Promise(resolve => setTimeout(resolve, 300));
27+
await new Promise((resolve) => setTimeout(resolve, 300));
2828
this.setState({ fresh: true });
2929
};
3030

src/cleanup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
let cleanupQueue = new Set();
33

44
export default function cleanup() {
5-
cleanupQueue.forEach(fn => fn());
5+
cleanupQueue.forEach((fn) => fn());
66
cleanupQueue.clear();
77
}
88

src/flushMicrotasksQueue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
* Wait for microtasks queue to flush
44
*/
55
export default function flushMicrotasksQueue(): Promise<any> {
6-
return new Promise(resolve => setImmediate(resolve));
6+
return new Promise((resolve) => setImmediate(resolve));
77
}

src/helpers/a11yAPI.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
2-
import makeQuery from './makeQuery';
32
import type { A11yRole, A11yStates, A11yState, A11yValue } from '../types.flow';
43
import type { WaitForOptions } from './findByAPI';
4+
import makeQuery from './makeQuery';
55

66
type GetReturn = ReactTestInstance;
77
type GetAllReturn = Array<ReactTestInstance>;
@@ -44,18 +44,18 @@ type A11yAPI = {|
4444
findAllByA11yStates: (A11yStates, ?WaitForOptions) => FindAllReturn,
4545

4646
// State
47-
getByA11yState: A11yState => GetReturn,
48-
getAllByA11yState: A11yState => GetAllReturn,
49-
queryByA11yState: A11yState => QueryReturn,
50-
queryAllByA11yState: A11yState => QueryAllReturn,
47+
getByA11yState: (A11yState) => GetReturn,
48+
getAllByA11yState: (A11yState) => GetAllReturn,
49+
queryByA11yState: (A11yState) => QueryReturn,
50+
queryAllByA11yState: (A11yState) => QueryAllReturn,
5151
findByA11yState: (A11yState, ?WaitForOptions) => FindReturn,
5252
findAllByA11yState: (A11yState, ?WaitForOptions) => FindAllReturn,
5353

5454
// Value
55-
getByA11yValue: A11yValue => GetReturn,
56-
getAllByA11yValue: A11yValue => GetAllReturn,
57-
queryByA11yValue: A11yValue => QueryReturn,
58-
queryAllByA11yValue: A11yValue => QueryAllReturn,
55+
getByA11yValue: (A11yValue) => GetReturn,
56+
getAllByA11yValue: (A11yValue) => GetAllReturn,
57+
queryByA11yValue: (A11yValue) => QueryReturn,
58+
queryAllByA11yValue: (A11yValue) => QueryAllReturn,
5959
findByA11yValue: (A11yValue, ?WaitForOptions) => FindReturn,
6060
findAllByA11yValue: (A11yValue, ?WaitForOptions) => FindAllReturn,
6161
|};
@@ -87,14 +87,14 @@ export function matchArrayValue(
8787
return prop.includes(matcher);
8888
}
8989

90-
return !matcher.some(e => !prop.includes(e));
90+
return !matcher.some((e) => !prop.includes(e));
9191
}
9292

9393
export function matchObject<T: {}>(prop?: T, matcher: T): boolean {
9494
return prop
9595
? Object.keys(matcher).length !== 0 &&
9696
Object.keys(prop).length !== 0 &&
97-
!Object.keys(matcher).some(key => prop[key] !== matcher[key])
97+
!Object.keys(matcher).some((key) => prop[key] !== matcher[key])
9898
: false;
9999
}
100100

src/helpers/findByAPI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @flow
2+
import waitForElement from '../waitForElement';
23
import {
34
fixedGetByTestId,
45
getAllByTestId,
@@ -9,7 +10,6 @@ import {
910
getByDisplayValue,
1011
getAllByDisplayValue,
1112
} from './getByAPI';
12-
import waitForElement from '../waitForElement';
1313

1414
export type WaitForOptions = {
1515
timeout?: number,

src/helpers/getByAPI.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const getNodeByText = (node, text) => {
3636
};
3737

3838
const getChildrenAsText = (children, TextComponent, textContent = []) => {
39-
React.Children.forEach(children, child => {
39+
React.Children.forEach(children, (child) => {
4040
if (typeof child === 'string') {
4141
textContent.push(child);
4242
return;
@@ -90,7 +90,7 @@ export const getByName = (instance: ReactTestInstance, warnFn?: Function) =>
9090
warnFn && warnFn('getByName');
9191
try {
9292
return typeof name === 'string'
93-
? instance.find(node => filterNodeByName(node, name))
93+
? instance.find((node) => filterNodeByName(node, name))
9494
: instance.findByType(name);
9595
} catch (error) {
9696
throw new ErrorWithStack(prepareErrorMessage(error), getByNameFn);
@@ -110,7 +110,7 @@ export const getByType = (instance: ReactTestInstance, warnFn?: Function) =>
110110
export const getByText = (instance: ReactTestInstance) =>
111111
function getByTextFn(text: string | RegExp) {
112112
try {
113-
return instance.find(node => getNodeByText(node, text));
113+
return instance.find((node) => getNodeByText(node, text));
114114
} catch (error) {
115115
throw new ErrorWithStack(prepareErrorMessage(error), getByTextFn);
116116
}
@@ -119,7 +119,7 @@ export const getByText = (instance: ReactTestInstance) =>
119119
export const getByPlaceholder = (instance: ReactTestInstance) =>
120120
function getByPlaceholderFn(placeholder: string | RegExp) {
121121
try {
122-
return instance.find(node =>
122+
return instance.find((node) =>
123123
getTextInputNodeByPlaceholder(node, placeholder)
124124
);
125125
} catch (error) {
@@ -130,7 +130,7 @@ export const getByPlaceholder = (instance: ReactTestInstance) =>
130130
export const getByDisplayValue = (instance: ReactTestInstance) =>
131131
function getByDisplayValueFn(placeholder: string | RegExp) {
132132
try {
133-
return instance.find(node =>
133+
return instance.find((node) =>
134134
getTextInputNodeByDisplayValue(node, placeholder)
135135
);
136136
} catch (error) {
@@ -181,7 +181,7 @@ export const getAllByName = (instance: ReactTestInstance, warnFn?: Function) =>
181181
warnFn && warnFn('getAllByName');
182182
const results =
183183
typeof name === 'string'
184-
? instance.findAll(node => filterNodeByName(node, name))
184+
? instance.findAll((node) => filterNodeByName(node, name))
185185
: instance.findAllByType(name);
186186
if (results.length === 0) {
187187
throw new ErrorWithStack('No instances found', getAllByNameFn);
@@ -201,7 +201,7 @@ export const getAllByType = (instance: ReactTestInstance, warnFn?: Function) =>
201201

202202
export const getAllByText = (instance: ReactTestInstance) =>
203203
function getAllByTextFn(text: string | RegExp) {
204-
const results = instance.findAll(node => getNodeByText(node, text));
204+
const results = instance.findAll((node) => getNodeByText(node, text));
205205
if (results.length === 0) {
206206
throw new ErrorWithStack(
207207
`No instances found with text: ${String(text)}`,
@@ -213,7 +213,7 @@ export const getAllByText = (instance: ReactTestInstance) =>
213213

214214
export const getAllByPlaceholder = (instance: ReactTestInstance) =>
215215
function getAllByPlaceholderFn(placeholder: string | RegExp) {
216-
const results = instance.findAll(node =>
216+
const results = instance.findAll((node) =>
217217
getTextInputNodeByPlaceholder(node, placeholder)
218218
);
219219
if (results.length === 0) {
@@ -227,7 +227,7 @@ export const getAllByPlaceholder = (instance: ReactTestInstance) =>
227227

228228
export const getAllByDisplayValue = (instance: ReactTestInstance) =>
229229
function getAllByDisplayValueFn(value: string | RegExp) {
230-
const results = instance.findAll(node =>
230+
const results = instance.findAll((node) =>
231231
getTextInputNodeByDisplayValue(node, value)
232232
);
233233
if (results.length === 0) {
@@ -256,7 +256,7 @@ export const getAllByTestId = (instance: ReactTestInstance) =>
256256
function getAllByTestIdFn(testID: string): ReactTestInstance[] {
257257
const results = instance
258258
.findAllByProps({ testID })
259-
.filter(element => typeof element.type === 'string');
259+
.filter((element) => typeof element.type === 'string');
260260

261261
if (results.length === 0) {
262262
throw new ErrorWithStack(

src/helpers/makeQuery.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// @flow
2+
import waitForElement from '../waitForElement';
23
import {
34
ErrorWithStack,
45
prepareErrorMessage,
56
createQueryByError,
67
} from './errors';
7-
import waitForElement from '../waitForElement';
88
import type { WaitForOptions } from './findByAPI';
99

1010
function isNodeValid(node: ReactTestInstance) {
@@ -13,7 +13,7 @@ function isNodeValid(node: ReactTestInstance) {
1313

1414
function makeAliases(aliases: Array<string>, query: Function) {
1515
return aliases
16-
.map(alias => ({ [alias]: query }))
16+
.map((alias) => ({ [alias]: query }))
1717
.reduce((acc, query) => ({ ...acc, ...query }), {});
1818
}
1919

@@ -34,7 +34,7 @@ const makeQuery = <P: mixed, M: mixed>(
3434
const getBy = (matcher: M) => {
3535
try {
3636
return instance.find(
37-
node => isNodeValid(node) && matcherFn(node.props[name], matcher)
37+
(node) => isNodeValid(node) && matcherFn(node.props[name], matcher)
3838
);
3939
} catch (error) {
4040
throw new ErrorWithStack(prepareErrorMessage(error), getBy);
@@ -43,7 +43,7 @@ const makeQuery = <P: mixed, M: mixed>(
4343

4444
const getAllBy = (matcher: M) => {
4545
const results = instance.findAll(
46-
node => isNodeValid(node) && matcherFn(node.props[name], matcher)
46+
(node) => isNodeValid(node) && matcherFn(node.props[name], matcher)
4747
);
4848

4949
if (results.length === 0) {

src/render.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function updateWithAct(
6868
renderer: ReactTestRenderer,
6969
wrap: (innerElement: React.Element<any>) => React.Element<any>
7070
) {
71-
return function(component: React.Element<any>) {
71+
return function (component: React.Element<any>) {
7272
act(() => {
7373
renderer.update(wrap(component));
7474
});
@@ -79,6 +79,6 @@ function debug(instance: ReactTestInstance, renderer) {
7979
function debugImpl(message?: string) {
8080
return debugDeep(renderer.toJSON(), message);
8181
}
82-
debugImpl.shallow = message => debugShallow(instance, message);
82+
debugImpl.shallow = (message) => debugShallow(instance, message);
8383
return debugImpl;
8484
}

src/waitForElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function waitForElement<T>(
66
): Promise<T> {
77
const startTime = Date.now();
88
return new Promise((resolve, reject) => {
9-
const rejectOrRerun = error => {
9+
const rejectOrRerun = (error) => {
1010
if (Date.now() - startTime >= timeout) {
1111
reject(error);
1212
return;

0 commit comments

Comments
 (0)