Skip to content

Commit 426d4c2

Browse files
jessebeachljharb
authored andcommitted
Fix Flow warnings
1 parent ecec8e4 commit 426d4c2

23 files changed

+144
-79
lines changed

.flowconfig

Lines changed: 2 additions & 0 deletions
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

Lines changed: 10 additions & 1 deletion
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

Lines changed: 14 additions & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 10 additions & 1 deletion
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

Lines changed: 7 additions & 1 deletion
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

Lines changed: 8 additions & 1 deletion
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

Lines changed: 8 additions & 1 deletion
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

Lines changed: 14 additions & 13 deletions
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

Lines changed: 5 additions & 1 deletion
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 {

0 commit comments

Comments
 (0)