Skip to content

Commit 426d4c2

Browse files
jessebeachljharb
authored andcommittedApr 6, 2021
Fix Flow warnings
1 parent ecec8e4 commit 426d4c2

23 files changed

+144
-79
lines changed
 

‎.flowconfig

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
<PROJECT_ROOT>/lib/.*
33
<PROJECT_ROOT>/docs/.*
44
<PROJECT_ROOT>/reports/.*
5+
[options]
6+
suppress_type=$FlowFixMe

‎__mocks__/IdentifierMock.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
export default function IdentifierMock(ident) {
1+
/**
2+
* @flow
3+
*/
4+
5+
export type IdentifierMockType = {|
6+
type: 'Identifier',
7+
name: string,
8+
|};
9+
10+
export default function IdentifierMock(ident: string): IdentifierMockType {
211
return {
312
type: 'Identifier',
413
name: ident,

‎__mocks__/JSXAttributeMock.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
/**
2+
* @flow
3+
*/
4+
15
import toAST from 'to-ast'; // eslint-disable-line import/no-extraneous-dependencies
26
import JSXExpressionContainerMock from './JSXExpressionContainerMock';
37

4-
export default function JSXAttributeMock(prop, value, isExpressionContainer = false) {
8+
export type JSXAttributeMockType = {
9+
type: 'JSXAttribute',
10+
name: {
11+
type: 'JSXIdentifier',
12+
name: string,
13+
},
14+
value: mixed,
15+
};
16+
17+
export default function JSXAttributeMock(prop: string, value: mixed, isExpressionContainer?: boolean = false): JSXAttributeMockType {
518
let astValue;
619
if (value && value.type !== undefined) {
720
astValue = value;

‎__mocks__/JSXElementMock.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22
* @flow
33
*/
44

5-
import JSXAttributeMock from './JSXAttributeMock';
5+
import type { JSXAttributeMockType } from './JSXAttributeMock';
66

7-
export type TJSXElementMock = {
7+
export type JSXElementMockType = {
88
type: 'JSXElement',
99
openingElement: {
1010
type: 'JSXOpeningElement',
1111
name: {
1212
type: 'JSXIdentifier',
1313
name: string,
1414
},
15-
attributes: Array<JSXAttributeMock>,
15+
attributes: Array<JSXAttributeMockType>,
1616
},
1717
children: Array<Node>,
1818
};
1919

2020
export default function JSXElementMock(
2121
tagName: string,
22-
attributes: Array<JSXAttributeMock> = [],
23-
children: Array<Node> = [],
24-
): TJSXElementMock {
22+
attributes: Array<JSXAttributeMockType> = [],
23+
children?: Array<Node> = [],
24+
): JSXElementMockType {
2525
return {
2626
type: 'JSXElement',
2727
openingElement: {

‎__mocks__/JSXExpressionContainerMock.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
export default function JSXExpressionContainerMock(exp) {
1+
/**
2+
* @flow
3+
*/
4+
5+
export type JSXExpressionContainerMockType = {
6+
type: 'JSXExpressionContainer',
7+
expression: mixed,
8+
}
9+
10+
export default function JSXExpressionContainerMock(exp: mixed): JSXExpressionContainerMockType {
211
return {
312
type: 'JSXExpressionContainer',
413
expression: exp,

‎__mocks__/JSXSpreadAttributeMock.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
*/
44

55
import IdentifierMock from './IdentifierMock';
6+
import type { IdentifierMockType } from './IdentifierMock';
67

7-
export default function JSXSpreadAttributeMock(identifier: string) {
8+
export type JSXSpreadAttributeMockType = {
9+
type: 'JSXSpreadAttribute',
10+
argument: IdentifierMockType,
11+
};
12+
13+
export default function JSXSpreadAttributeMock(identifier: string): JSXSpreadAttributeMockType {
814
return {
915
type: 'JSXSpreadAttribute',
1016
argument: IdentifierMock(identifier),

‎__mocks__/JSXTextMock.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
/**
22
* @flow
33
*/
4-
export default function JSXTextMock(value: string) {
4+
5+
export type JSXTextMockType = {|
6+
type: 'JSXText',
7+
value: string,
8+
raw: string,
9+
|};
10+
11+
export default function JSXTextMock(value: string): JSXTextMockType {
512
return {
613
type: 'JSXText',
714
value,

‎__mocks__/LiteralMock.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
/**
22
* @flow
33
*/
4-
export default function LiteralMock(value: string) {
4+
5+
export type LiteralMockType = {|
6+
type: 'Literal',
7+
value: string,
8+
raw: string,
9+
|};
10+
11+
export default function LiteralMock(value: string): LiteralMockType {
512
return {
613
type: 'Literal',
714
value,

‎__mocks__/genInteractives.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import includes from 'array-includes';
77
import JSXAttributeMock from './JSXAttributeMock';
88
import JSXElementMock from './JSXElementMock';
99

10-
import type { TJSXElementMock } from './JSXElementMock';
10+
import type { JSXElementMockType } from './JSXElementMock';
11+
import type { JSXAttributeMockType } from './JSXAttributeMock';
1112

1213
const domElements = [...dom.keys()];
1314
const roleNames = [...roles.keys()];
@@ -147,7 +148,7 @@ const nonInteractiveRoles = roleNames
147148
// aria-activedescendant, thus in practice we treat it as a widget.
148149
.filter((role) => !includes(['toolbar'], role));
149150

150-
export function genElementSymbol(openingElement: Object) {
151+
export function genElementSymbol(openingElement: Object): string {
151152
return (
152153
openingElement.name.name + (openingElement.attributes.length > 0
153154
? `${openingElement.attributes
@@ -158,8 +159,8 @@ export function genElementSymbol(openingElement: Object) {
158159
);
159160
}
160161

161-
export function genInteractiveElements(): Array<TJSXElementMock> {
162-
return Object.keys(interactiveElementsMap).map((elementSymbol: string): TJSXElementMock => {
162+
export function genInteractiveElements(): Array<JSXElementMockType> {
163+
return Object.keys(interactiveElementsMap).map((elementSymbol: string): JSXElementMockType => {
163164
const bracketIndex = elementSymbol.indexOf('[');
164165
let name = elementSymbol;
165166
if (bracketIndex > -1) {
@@ -170,15 +171,15 @@ export function genInteractiveElements(): Array<TJSXElementMock> {
170171
});
171172
}
172173

173-
export function genInteractiveRoleElements(): Array<TJSXElementMock> {
174-
return [...interactiveRoles, 'button article', 'fakerole button article'].map((value): TJSXElementMock => JSXElementMock(
174+
export function genInteractiveRoleElements(): Array<JSXElementMockType> {
175+
return [...interactiveRoles, 'button article', 'fakerole button article'].map((value): JSXElementMockType => JSXElementMock(
175176
'div',
176177
[JSXAttributeMock('role', value)],
177178
));
178179
}
179180

180-
export function genNonInteractiveElements(): Array<TJSXElementMock> {
181-
return Object.keys(nonInteractiveElementsMap).map((elementSymbol): TJSXElementMock => {
181+
export function genNonInteractiveElements(): Array<JSXElementMockType> {
182+
return Object.keys(nonInteractiveElementsMap).map((elementSymbol): JSXElementMockType => {
182183
const bracketIndex = elementSymbol.indexOf('[');
183184
let name = elementSymbol;
184185
if (bracketIndex > -1) {
@@ -189,25 +190,25 @@ export function genNonInteractiveElements(): Array<TJSXElementMock> {
189190
});
190191
}
191192

192-
export function genNonInteractiveRoleElements() {
193+
export function genNonInteractiveRoleElements(): Array<JSXElementMockType> {
193194
return [
194195
...nonInteractiveRoles,
195196
'article button',
196197
'fakerole article button',
197198
].map((value) => JSXElementMock('div', [JSXAttributeMock('role', value)]));
198199
}
199200

200-
export function genAbstractRoleElements() {
201+
export function genAbstractRoleElements(): Array<JSXElementMockType> {
201202
return abstractRoles.map((value) => JSXElementMock('div', [JSXAttributeMock('role', value)]));
202203
}
203204

204-
export function genNonAbstractRoleElements() {
205+
export function genNonAbstractRoleElements(): Array<JSXElementMockType> {
205206
return nonAbstractRoles.map((value) => JSXElementMock('div', [JSXAttributeMock('role', value)]));
206207
}
207208

208-
export function genIndeterminantInteractiveElements(): Array<TJSXElementMock> {
209+
export function genIndeterminantInteractiveElements(): Array<JSXElementMockType> {
209210
return Object.keys(indeterminantInteractiveElementsMap).map((name) => {
210-
const attributes = indeterminantInteractiveElementsMap[name].map(({ prop, value }): TJSXElementMock => JSXAttributeMock(prop, value));
211+
const attributes = indeterminantInteractiveElementsMap[name].map(({ prop, value }): JSXAttributeMockType => JSXAttributeMock(prop, value));
211212
return JSXElementMock(name, attributes);
212213
});
213214
}

‎__tests__/__util__/ruleOptionsMapperFactory.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ type ESLintTestRunnerTestCase = {
99
parserOptions: ?Array<mixed>
1010
};
1111

12-
export default function ruleOptionsMapperFactory(ruleOptions: Array<mixed> = []) {
12+
type RuleOptionsMapperFactoryType = (
13+
params: ESLintTestRunnerTestCase
14+
) => ESLintTestRunnerTestCase;
15+
16+
export default function ruleOptionsMapperFactory(ruleOptions: Array<mixed> = []): RuleOptionsMapperFactoryType {
1317
// eslint-disable-next-line
1418
return ({ code, errors, options, parserOptions }: ESLintTestRunnerTestCase): ESLintTestRunnerTestCase => {
1519
return {

‎flow/eslint.js

+9
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ export type ESLintContext = {
1010
options: Array<Object>,
1111
report: (ESLintReport) => void,
1212
};
13+
14+
export type ESLintConfig = {
15+
meta?: {[string]: mixed},
16+
create: (context: ESLintContext) => mixed,
17+
}
18+
19+
export type ESLintVisitorSelectorConfig = {
20+
[string]: mixed,
21+
};

‎src/rules/anchor-is-valid.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import { elementType, getProp, getPropValue } from 'jsx-ast-utils';
1212
import type { JSXOpeningElement } from 'ast-types-flow';
13-
import type { ESLintContext } from '../../flow/eslint';
13+
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
1414
import { generateObjSchema, arraySchema, enumArraySchema } from '../util/schemas';
1515

1616
const allAspects = ['noHref', 'invalidHref', 'preferButton'];
@@ -27,16 +27,16 @@ const schema = generateObjSchema({
2727
aspects: enumArraySchema(allAspects, 1),
2828
});
2929

30-
module.exports = {
30+
module.exports = ({
3131
meta: {
3232
docs: {
3333
url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/anchor-is-valid.md',
3434
},
3535
schema: [schema],
3636
},
3737

38-
create: (context: ESLintContext) => ({
39-
JSXOpeningElement: (node: JSXOpeningElement) => {
38+
create: (context: ESLintContext): ESLintVisitorSelectorConfig => ({
39+
JSXOpeningElement: (node: JSXOpeningElement): void => {
4040
const { attributes } = node;
4141
const options = context.options[0] || {};
4242
const componentOptions = options.components || [];
@@ -115,4 +115,4 @@ module.exports = {
115115
}
116116
},
117117
}),
118-
};
118+
}: ESLintConfig);

‎src/rules/control-has-associated-label.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { elementType, getProp, getLiteralPropValue } from 'jsx-ast-utils';
1313
import type { JSXElement } from 'ast-types-flow';
1414
import includes from 'array-includes';
1515
import { generateObjSchema, arraySchema } from '../util/schemas';
16-
import type { ESLintContext } from '../../flow/eslint';
16+
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
1717
import isDOMElement from '../util/isDOMElement';
1818
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
1919
import isInteractiveElement from '../util/isInteractiveElement';
@@ -36,13 +36,13 @@ const schema = generateObjSchema({
3636
},
3737
});
3838

39-
module.exports = {
39+
module.exports = ({
4040
meta: {
4141
docs: {},
4242
schema: [schema],
4343
},
4444

45-
create: (context: ESLintContext) => {
45+
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {
4646
const options = context.options[0] || {};
4747
const {
4848
labelAttributes = [],
@@ -53,7 +53,7 @@ module.exports = {
5353

5454
const newIgnoreElements = new Set([...ignoreElements, ...ignoreList]);
5555

56-
const rule = (node: JSXElement) => {
56+
const rule = (node: JSXElement): void => {
5757
const tag = elementType(node.openingElement);
5858
const role = getLiteralPropValue(getProp(node.openingElement.attributes, 'role'));
5959
// Ignore interactive elements that might get their label from a source
@@ -112,4 +112,4 @@ module.exports = {
112112
JSXElement: rule,
113113
};
114114
},
115-
};
115+
}: ESLintConfig);

‎src/rules/interactive-supports-focus.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from 'jsx-ast-utils';
1818
import type { JSXOpeningElement } from 'ast-types-flow';
1919
import includes from 'array-includes';
20-
import type { ESLintContext } from '../../flow/eslint';
20+
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2121
import {
2222
enumArraySchema,
2323
generateObjSchema,
@@ -47,19 +47,15 @@ const interactiveProps = [
4747
...eventHandlersByType.keyboard,
4848
];
4949

50-
module.exports = {
50+
module.exports = ({
5151
meta: {
5252
docs: {
5353
url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/interactive-supports-focus.md',
5454
},
5555
schema: [schema],
5656
},
5757

58-
create: (context: ESLintContext & {
59-
options: {
60-
tabbable: Array<string>
61-
}
62-
}) => ({
58+
create: (context: ESLintContext): ESLintVisitorSelectorConfig => ({
6359
JSXOpeningElement: (node: JSXOpeningElement) => {
6460
const tabbable = (
6561
context.options && context.options[0] && context.options[0].tabbable
@@ -111,4 +107,4 @@ module.exports = {
111107
}
112108
},
113109
}),
114-
};
110+
}: ESLintConfig);

‎src/rules/label-has-associated-control.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import { getProp, getPropValue, elementType } from 'jsx-ast-utils';
1313
import type { JSXElement } from 'ast-types-flow';
1414
import { generateObjSchema, arraySchema } from '../util/schemas';
15-
import type { ESLintContext } from '../../flow/eslint';
15+
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
1616
import mayContainChildComponent from '../util/mayContainChildComponent';
1717
import mayHaveAccessibleLabel from '../util/mayHaveAccessibleLabel';
1818

@@ -41,13 +41,13 @@ const validateId = (node) => {
4141
return htmlForAttr !== false && !!htmlForValue;
4242
};
4343

44-
module.exports = {
44+
module.exports = ({
4545
meta: {
4646
docs: {},
4747
schema: [schema],
4848
},
4949

50-
create: (context: ESLintContext) => {
50+
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {
5151
const options = context.options[0] || {};
5252
const labelComponents = options.labelComponents || [];
5353
const assertType = options.assert || 'either';
@@ -122,4 +122,4 @@ module.exports = {
122122
JSXElement: rule,
123123
};
124124
},
125-
};
125+
}: ESLintConfig);

‎src/rules/media-has-caption.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// Rule Definition
99
// ----------------------------------------------------------------------------
1010

11-
import type { JSXElement, JSXOpeningElement } from 'ast-types-flow';
11+
import type { JSXElement, JSXOpeningElement, Node } from 'ast-types-flow';
1212
import { elementType, getProp, getLiteralPropValue } from 'jsx-ast-utils';
13-
import type { ESLintContext } from '../../flow/eslint';
13+
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
1414
import { generateObjSchema, arraySchema } from '../util/schemas';
1515

1616
const errorMessage = 'Media elements such as <audio> and <video> must have a <track> for captions.';
@@ -35,15 +35,15 @@ const isTrackType = (context, type) => {
3535
return ['track'].concat(options.track || []).some((typeToCheck) => typeToCheck === type);
3636
};
3737

38-
module.exports = {
38+
module.exports = ({
3939
meta: {
4040
docs: {
4141
url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/media-has-caption.md',
4242
},
4343
schema: [schema],
4444
},
4545

46-
create: (context: ESLintContext) => ({
46+
create: (context: ESLintContext): ESLintVisitorSelectorConfig => ({
4747
JSXElement: (node: JSXElement) => {
4848
const element: JSXOpeningElement = node.openingElement;
4949
const type = elementType(element);
@@ -87,4 +87,4 @@ module.exports = {
8787
}
8888
},
8989
}),
90-
};
90+
}: ESLintConfig);

‎src/rules/no-interactive-element-to-noninteractive-role.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import type { JSXIdentifier } from 'ast-types-flow';
2020
import includes from 'array-includes';
2121
import has from 'has';
22-
import type { ESLintContext } from '../../flow/eslint';
22+
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2323
import type { ESLintJSXAttribute } from '../../flow/eslint-jsx';
2424
import isInteractiveElement from '../util/isInteractiveElement';
2525
import isNonInteractiveRole from '../util/isNonInteractiveRole';
@@ -29,7 +29,7 @@ const errorMessage = 'Interactive elements should not be assigned non-interactiv
2929

3030
const domElements = [...dom.keys()];
3131

32-
module.exports = {
32+
module.exports = ({
3333
meta: {
3434
docs: {
3535
url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/no-interactive-element-to-noninteractive-role.md',
@@ -46,7 +46,7 @@ module.exports = {
4646
}],
4747
},
4848

49-
create: (context: ESLintContext) => {
49+
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {
5050
const { options } = context;
5151
return {
5252
JSXAttribute: (attribute: ESLintJSXAttribute) => {
@@ -87,4 +87,4 @@ module.exports = {
8787
},
8888
};
8989
},
90-
};
90+
}: ESLintConfig);

‎src/rules/no-noninteractive-element-interactions.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import type { JSXOpeningElement } from 'ast-types-flow';
2020
import includes from 'array-includes';
2121
import has from 'has';
22-
import type { ESLintContext } from '../../flow/eslint';
22+
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2323
import { arraySchema, generateObjSchema } from '../util/schemas';
2424
import isAbstractRole from '../util/isAbstractRole';
2525
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
@@ -42,15 +42,15 @@ const schema = generateObjSchema({
4242
handlers: arraySchema,
4343
});
4444

45-
module.exports = {
45+
module.exports = ({
4646
meta: {
4747
docs: {
4848
url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/no-noninteractive-element-interactions.md',
4949
},
5050
schema: [schema],
5151
},
5252

53-
create: (context: ESLintContext) => {
53+
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {
5454
const { options } = context;
5555
return {
5656
JSXOpeningElement: (node: JSXOpeningElement) => {
@@ -105,4 +105,4 @@ module.exports = {
105105
},
106106
};
107107
},
108-
};
108+
}: ESLintConfig);

‎src/rules/no-noninteractive-element-to-interactive-role.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import type { JSXIdentifier } from 'ast-types-flow';
1818
import includes from 'array-includes';
1919
import has from 'has';
20-
import type { ESLintContext } from '../../flow/eslint';
20+
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2121
import type { ESLintJSXAttribute } from '../../flow/eslint-jsx';
2222
import getExplicitRole from '../util/getExplicitRole';
2323
import isNonInteractiveElement from '../util/isNonInteractiveElement';
@@ -27,7 +27,7 @@ const errorMessage = 'Non-interactive elements should not be assigned interactiv
2727

2828
const domElements = [...dom.keys()];
2929

30-
module.exports = {
30+
module.exports = ({
3131
meta: {
3232
docs: {
3333
url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/no-noninteractive-element-to-interactive-role.md',
@@ -44,7 +44,7 @@ module.exports = {
4444
}],
4545
},
4646

47-
create: (context: ESLintContext) => {
47+
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {
4848
const { options } = context;
4949
return {
5050
JSXAttribute: (attribute: ESLintJSXAttribute) => {
@@ -81,4 +81,4 @@ module.exports = {
8181
},
8282
};
8383
},
84-
};
84+
}: ESLintConfig);

‎src/rules/no-noninteractive-tabindex.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
getLiteralPropValue,
1717
} from 'jsx-ast-utils';
1818
import includes from 'array-includes';
19-
import type { ESLintContext } from '../../flow/eslint';
19+
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2020
import isInteractiveElement from '../util/isInteractiveElement';
2121
import isInteractiveRole from '../util/isInteractiveRole';
2222
import isNonLiteralProperty from '../util/isNonLiteralProperty';
@@ -36,15 +36,15 @@ const schema = generateObjSchema({
3636
},
3737
});
3838

39-
module.exports = {
39+
module.exports = ({
4040
meta: {
4141
docs: {
4242
url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/no-noninteractive-tabindex.md',
4343
},
4444
schema: [schema],
4545
},
4646

47-
create: (context: ESLintContext) => {
47+
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {
4848
const { options } = context;
4949
return {
5050
JSXOpeningElement: (node: JSXOpeningElement) => {
@@ -98,4 +98,4 @@ module.exports = {
9898
},
9999
};
100100
},
101-
};
101+
}: ESLintConfig);

‎src/rules/no-redundant-roles.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { elementType } from 'jsx-ast-utils';
1313
import includes from 'array-includes';
1414
import has from 'has';
1515
import type { JSXOpeningElement } from 'ast-types-flow';
16-
import type { ESLintContext } from '../../flow/eslint';
16+
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
1717
import getExplicitRole from '../util/getExplicitRole';
1818
import getImplicitRole from '../util/getImplicitRole';
1919

@@ -23,7 +23,7 @@ const errorMessage = (element, implicitRole) => (
2323

2424
const DEFAULT_ROLE_EXCEPTIONS = { nav: ['navigation'] };
2525

26-
module.exports = {
26+
module.exports = ({
2727
meta: {
2828
docs: {
2929
url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/no-redundant-roles.md',
@@ -40,7 +40,7 @@ module.exports = {
4040
}],
4141
},
4242

43-
create: (context: ESLintContext) => {
43+
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {
4444
const { options } = context;
4545
return {
4646
JSXOpeningElement: (node: JSXOpeningElement) => {
@@ -74,4 +74,4 @@ module.exports = {
7474
},
7575
};
7676
},
77-
};
77+
}: ESLintConfig);

‎src/rules/no-static-element-interactions.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from 'jsx-ast-utils';
1919
import type { JSXOpeningElement } from 'ast-types-flow';
2020
import includes from 'array-includes';
21-
import type { ESLintContext } from '../../flow/eslint';
21+
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2222
import { arraySchema, generateObjSchema } from '../util/schemas';
2323
import isAbstractRole from '../util/isAbstractRole';
2424
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
@@ -41,15 +41,15 @@ const schema = generateObjSchema({
4141
handlers: arraySchema,
4242
});
4343

44-
module.exports = {
44+
module.exports = ({
4545
meta: {
4646
docs: {
4747
url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/no-static-element-interactions.md',
4848
},
4949
schema: [schema],
5050
},
5151

52-
create: (context: ESLintContext) => {
52+
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {
5353
const { options } = context;
5454
return {
5555
JSXOpeningElement: (node: JSXOpeningElement) => {
@@ -108,4 +108,4 @@ module.exports = {
108108
},
109109
};
110110
},
111-
};
111+
}: ESLintConfig);

‎src/util/hasAccessibleChild.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// @flow
22

33
import { elementType, hasAnyProp } from 'jsx-ast-utils';
4-
import type { JSXElement } from 'ast-types-flow';
4+
import type { JSXElement, Node } from 'ast-types-flow';
55
import isHiddenFromScreenReader from './isHiddenFromScreenReader';
66

77
export default function hasAccessibleChild(node: JSXElement): boolean {
8-
return node.children.some((child) => {
8+
return node.children.some((child: Node) => {
99
switch (child.type) {
1010
case 'Literal':
11+
return Boolean(child.value);
12+
// $FlowFixMe JSXText is missing in ast-types-flow
1113
case 'JSXText':
1214
return Boolean(child.value);
1315
case 'JSXElement':

0 commit comments

Comments
 (0)
Please sign in to comment.