Skip to content

Commit 99c69be

Browse files
committed
Just run flow-to-ts command
1 parent 68c3c3e commit 99c69be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1591
-1287
lines changed

.eslintrc.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
module.exports = {
2-
extends: ['algolia', 'algolia/jest', 'algolia/react'],
2+
extends: ['airbnb-typescript', 'prettier'],
3+
4+
parserOptions: {
5+
project: './tsconfig.eslint.json',
6+
},
7+
8+
// ecmaFeatures: {
9+
// jsx: true,
10+
// },
311

412
env: {
513
es6: true,
@@ -11,12 +19,12 @@ module.exports = {
1119
},
1220
},
1321

14-
rules: {
15-
'max-params': ['error', 10],
16-
'no-warning-comments': 'error',
22+
// rules: {
23+
// 'max-params': ['error', 10],
24+
// 'no-warning-comments': 'error',
1725

18-
'import/no-commonjs': 'off',
19-
},
26+
// 'import/no-commonjs': 'off',
27+
// },
2028

2129
overrides: [
2230
{

.flowconfig

-18
This file was deleted.

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
**/dist/**/*
22
**/node_modules/**/*
3+
src/**/*.js

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"parser": "flow",
2+
"parser": "babel-ts",
33
"singleQuote": true,
44
"trailingComma": "es5",
55
"overrides": [

index.d.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
declare module 'react-element-to-jsx-string' {
22
import { ReactNode } from 'react';
33

4-
type FilterPropsFunction = (value: any, key: string) => boolean
4+
type FilterPropsFunction = (value: any, key: string) => boolean;
55

66
interface ReactElementToJSXStringOptions {
77
displayName?: (element: ReactNode) => string;
@@ -16,7 +16,10 @@ declare module 'react-element-to-jsx-string' {
1616
useFragmentShortSyntax?: boolean;
1717
}
1818

19-
const reactElementToJSXString: (element: ReactNode, options?: ReactElementToJSXStringOptions) => string;
19+
const reactElementToJSXString: (
20+
element: ReactNode,
21+
options?: ReactElementToJSXStringOptions
22+
) => string;
2023

2124
export { ReactElementToJSXStringOptions as Options };
2225

package.json

+24-22
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,15 @@
88
"types": "index.d.ts",
99
"scripts": {
1010
"build": "rollup -c",
11-
"build:flow": "flow-copy-source -v --ignore=*.spec.js src/ dist/cjs",
1211
"prebuild": "rm -rf dist/",
13-
"postbuild": "npm run build:flow",
14-
"prepare": "npm run build",
15-
"lint": "eslint .",
16-
"lint:fix": "npm run lint -- --fix",
17-
"flow": "flow",
18-
"precommit": "lint-staged",
19-
"prepublishOnly": "npm run build",
20-
"prettier:fix": "prettier --write \"**/*.{js,json}\"",
12+
"lint": "eslint --ext ts --ext tsx src/",
13+
"lint:fix": "yarn run lint -- --fix",
14+
"prettier:fix": "prettier --write \"**/*.{ts,tsx,js}\"",
2115
"test": "jest",
2216
"test:watch": "jest --watch",
2317
"release": "./release.sh",
24-
"smoke": "node tests/smoke/run"
25-
},
26-
"lint-staged": {
27-
"*.js": ["prettier --write \"**/*.{js,json}\"", "git add"]
18+
"smoke": "node tests/smoke/run",
19+
"ts:progress": "tsc > tserrors.txt"
2820
},
2921
"author": {
3022
"name": "Algolia, Inc.",
@@ -40,20 +32,27 @@
4032
"@babel/preset-react": "7.14.5",
4133
"@commitlint/cli": "8.3.5",
4234
"@commitlint/config-angular": "8.3.4",
35+
"@khanacademy/flow-to-ts": "^0.5.2",
36+
"@types/enzyme": "^3.10.9",
37+
"@types/enzyme-adapter-react-16": "^1.0.6",
38+
"@types/react": "^17.0.26",
39+
"@types/react-is": "^17.0.2",
4340
"babel-eslint": "10.1.0",
4441
"babel-jest": "24.9.0",
4542
"babel-register": "6.26.0",
4643
"conventional-changelog-cli": "2.1.1",
4744
"doctoc": "1.4.0",
4845
"enzyme": "3.11.0",
4946
"enzyme-adapter-react-16": "1.15.6",
50-
"eslint": "6.8.0",
47+
"eslint": "7.25.0",
48+
"eslint-config-airbnb-typescript": "12.3.1",
5149
"eslint-config-algolia": "14.0.1",
52-
"eslint-config-prettier": "6.15.0",
53-
"eslint-plugin-import": "2.24.2",
50+
"eslint-config-prettier": "8.3.0",
51+
"eslint-plugin-import": "2.22.1",
5452
"eslint-plugin-jest": "22.21.0",
55-
"eslint-plugin-prettier": "3.4.1",
56-
"eslint-plugin-react": "7.22.0",
53+
"eslint-plugin-jsx-a11y": "6.4.1",
54+
"eslint-plugin-react": "7.23.2",
55+
"eslint-plugin-react-hooks": "4.2.0",
5756
"esm": "3.2.25",
5857
"expect": "27.2.3",
5958
"flow-bin": "0.119.1",
@@ -63,7 +62,7 @@
6362
"json": "10.0.0",
6463
"lint-staged": "10.5.4",
6564
"mversion": "2.0.1",
66-
"prettier": "1.19.1",
65+
"prettier": "2.4.1",
6766
"react": "16.14.0",
6867
"react-dom": "16.14.0",
6968
"react-test-renderer": "16.14.0",
@@ -72,7 +71,8 @@
7271
"rollup-plugin-node-builtins": "2.1.2",
7372
"rollup-plugin-node-globals": "1.4.0",
7473
"rollup-plugin-node-resolve": "5.2.0",
75-
"rollup-plugin-sourcemaps": "0.6.3"
74+
"rollup-plugin-sourcemaps": "0.6.3",
75+
"typescript": "4.2.4"
7676
},
7777
"peerDependencies": {
7878
"react": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1",
@@ -81,9 +81,11 @@
8181
"dependencies": {
8282
"@base2/pretty-print-object": "1.0.1",
8383
"is-plain-object": "5.0.0",
84-
"react-is": "^17.0.2"
84+
"react-is": "17.0.2"
8585
},
8686
"jest": {
87-
"setupFilesAfterEnv": ["<rootDir>tests/setupTests.js"]
87+
"setupFilesAfterEnv": [
88+
"<rootDir>tests/setupTests.js"
89+
]
8890
}
8991
}

src/AnonymousStatelessComponent.js

-7
This file was deleted.

src/AnonymousStatelessComponent.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react'; // eslint-disable-next-line react/display-name
2+
3+
export default function (props) {
4+
const { children } = props; // eslint-disable-line react/prop-types
5+
6+
return <div>{children}</div>;
7+
}

src/formatter/createPropFilter.spec.js renamed to src/formatter/createPropFilter.spec.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
/* @flow */
2-
31
import createPropFilter from './createPropFilter';
42

53
describe('createPropFilter', () => {
64
it('should filter based on an array of keys', () => {
7-
const props = { a: 1, b: 2, c: 3 };
8-
const filter = createPropFilter(props, ['b']);
5+
const props = {
6+
a: 1,
7+
b: 2,
8+
c: 3,
9+
};
910

11+
const filter = createPropFilter(props, ['b']);
1012
const filteredPropKeys = Object.keys(props).filter(filter);
1113

1214
expect(filteredPropKeys).toEqual(['a', 'c']);
1315
});
1416

1517
it('should filter based on a callback', () => {
16-
const props = { a: 1, b: 2, c: 3 };
18+
const props = {
19+
a: 1,
20+
b: 2,
21+
c: 3,
22+
};
23+
1724
const filter = createPropFilter(
1825
props,
1926
(val, key) => key !== 'b' && val < 3
2027
);
21-
2228
const filteredPropKeys = Object.keys(props).filter(filter);
2329

2430
expect(filteredPropKeys).toEqual(['a']);

src/formatter/createPropFilter.js renamed to src/formatter/createPropFilter.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
/* @flow */
2-
31
export default function createPropFilter(
42
props: {},
5-
filter: string[] | ((any, string) => boolean)
3+
filter: string[] | ((propValue: any, key: string) => boolean)
64
) {
75
if (Array.isArray(filter)) {
86
return (key: string) => filter.indexOf(key) === -1;

src/formatter/formatComplexDataStructure.spec.js renamed to src/formatter/formatComplexDataStructure.spec.ts

+43-28
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
1-
/* @flow */
2-
31
import React from 'react';
42
import formatComplexDataStructure from './formatComplexDataStructure';
53

6-
jest.mock('./formatReactElementNode.js', () => node =>
7-
`<${node.displayName} />`
4+
jest.mock(
5+
'./formatReactElementNode',
6+
() => (node) => `<${node.displayName} />`
87
);
98

109
const createFakeReactElement = (tagName = 'Foo') =>
1110
React.createElement(tagName, {}, null);
12-
const options = { tabStop: 2 };
11+
12+
const options = {
13+
tabStop: 2,
14+
};
1315

1416
describe('formatComplexDataStructure', () => {
1517
it('should format an object', () => {
16-
const fixture = { a: 1, b: { c: 'ccc' } };
17-
18-
expect(formatComplexDataStructure(fixture, false, 0, options)).toEqual(
19-
`{
18+
const fixture = {
19+
a: 1,
20+
b: {
21+
c: 'ccc',
22+
},
23+
};
24+
expect(formatComplexDataStructure(fixture, false, 0, options)).toEqual(`{
2025
a: 1,
2126
b: {
2227
c: 'ccc'
2328
}
24-
}`
25-
);
29+
}`);
2630
});
2731

2832
it('should format inline an object', () => {
29-
const fixture = { a: 1, b: { c: 'ccc' } };
33+
const fixture = {
34+
a: 1,
35+
b: {
36+
c: 'ccc',
37+
},
38+
};
3039

3140
expect(formatComplexDataStructure(fixture, true, 0, options)).toEqual(
3241
"{a: 1, b: {c: 'ccc'}}"
@@ -38,31 +47,33 @@ describe('formatComplexDataStructure', () => {
3847
});
3948

4049
it('should order the object keys', () => {
41-
const fixture = { b: { d: 'ddd', c: 'ccc' }, a: 1 };
50+
const fixture = {
51+
b: {
52+
d: 'ddd',
53+
c: 'ccc',
54+
},
55+
a: 1,
56+
};
4257

43-
expect(formatComplexDataStructure(fixture, false, 0, options)).toEqual(
44-
`{
58+
expect(formatComplexDataStructure(fixture, false, 0, options)).toEqual(`{
4559
a: 1,
4660
b: {
4761
c: 'ccc',
4862
d: 'ddd'
4963
}
50-
}`
51-
);
64+
}`);
5265
});
5366

5467
it('should format an array', () => {
5568
const fixture = [1, '2', true, false, null];
5669

57-
expect(formatComplexDataStructure(fixture, false, 0, options)).toEqual(
58-
`[
70+
expect(formatComplexDataStructure(fixture, false, 0, options)).toEqual(`[
5971
1,
6072
'2',
6173
true,
6274
false,
6375
null
64-
]`
65-
);
76+
]`);
6677
});
6778

6879
it('should format inline an array ', () => {
@@ -74,29 +85,33 @@ describe('formatComplexDataStructure', () => {
7485
});
7586

7687
it('should format an object that contains a react element', () => {
77-
const fixture = { a: createFakeReactElement('BarBar') };
88+
const fixture = {
89+
a: createFakeReactElement('BarBar'),
90+
};
7891

79-
expect(formatComplexDataStructure(fixture, false, 0, options)).toEqual(
80-
`{
92+
expect(formatComplexDataStructure(fixture, false, 0, options)).toEqual(`{
8193
a: <BarBar />
82-
}`
83-
);
94+
}`);
8495
});
8596

8697
it('should format an empty array', () => {
8798
expect(formatComplexDataStructure([], false, 0, options)).toEqual('[]');
8899
});
89100

90101
it('should format an object that contains a date', () => {
91-
const fixture = { a: new Date('2017-11-13T00:00:00.000Z') };
102+
const fixture = {
103+
a: new Date('2017-11-13T00:00:00.000Z'),
104+
};
92105

93106
expect(formatComplexDataStructure(fixture, true, 0, options)).toEqual(
94107
`{a: new Date('2017-11-13T00:00:00.000Z')}`
95108
);
96109
});
97110

98111
it('should format an object that contains a regexp', () => {
99-
const fixture = { a: /test/g };
112+
const fixture = {
113+
a: /test/g,
114+
};
100115

101116
expect(formatComplexDataStructure(fixture, true, 0, options)).toEqual(
102117
`{a: /test/g}`

0 commit comments

Comments
 (0)