Skip to content

Commit 08c8fca

Browse files
authored
chore: use typescript-eslint to parse all files (#10722)
1 parent 92f74cd commit 08c8fca

14 files changed

Lines changed: 102 additions & 84 deletions

File tree

.eslintrc.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module.exports = {
1818
{
1919
extends: ['plugin:@typescript-eslint/eslint-recommended'],
2020
files: ['*.ts', '*.tsx'],
21-
parser: '@typescript-eslint/parser',
2221
plugins: ['@typescript-eslint/eslint-plugin', 'local'],
2322
rules: {
2423
'@typescript-eslint/array-type': ['error', {default: 'generic'}],
@@ -223,7 +222,7 @@ module.exports = {
223222
},
224223
},
225224
],
226-
parser: 'babel-eslint',
225+
parser: '@typescript-eslint/parser',
227226
plugins: ['markdown', 'import', 'prettier', 'eslint-comments'],
228227
rules: {
229228
'arrow-body-style': 'error',

docs/SnapshotTesting.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A typical snapshot test case renders a UI component, takes a snapshot, then comp
1111

1212
A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/master/examples/snapshot/Link.react.js):
1313

14-
```javascript
14+
```tsx
1515
import React from 'react';
1616
import renderer from 'react-test-renderer';
1717
import Link from '../Link.react';
@@ -51,7 +51,7 @@ It's straightforward to spot when a snapshot test fails after a bug has been int
5151

5252
One such situation can arise if we intentionally change the address the Link component in our example is pointing to.
5353

54-
```javascript
54+
```tsx
5555
// Updated test case with a Link to a different address
5656
it('renders correctly', () => {
5757
const tree = renderer
@@ -107,7 +107,7 @@ Inline snapshots behave identically to external snapshots (`.snap` files), excep
107107

108108
First, you write a test, calling `.toMatchInlineSnapshot()` with no arguments:
109109

110-
```javascript
110+
```tsx
111111
it('renders correctly', () => {
112112
const tree = renderer
113113
.create(<Link page="https://prettier.io">Prettier</Link>)
@@ -118,7 +118,7 @@ it('renders correctly', () => {
118118

119119
The next time you run Jest, `tree` will be evaluated, and a snapshot will be written as an argument to `toMatchInlineSnapshot`:
120120

121-
```javascript
121+
```tsx
122122
it('renders correctly', () => {
123123
const tree = renderer
124124
.create(<Link page="https://prettier.io">Prettier</Link>)

docs/TutorialReact.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = {
6060

6161
Let's create a [snapshot test](SnapshotTesting.md) for a Link component that renders hyperlinks:
6262

63-
```javascript
63+
```tsx
6464
// Link.react.js
6565
import React from 'react';
6666

@@ -106,7 +106,7 @@ export default class Link extends React.Component {
106106

107107
Now let's use React's test renderer and Jest's snapshot feature to interact with the component and capture the rendered output and create a snapshot file:
108108

109-
```javascript
109+
```tsx
110110
// Link.react.test.js
111111
import React from 'react';
112112
import renderer from 'react-test-renderer';
@@ -196,7 +196,7 @@ React 16 triggers these warnings due to how it checks element types, and the moc
196196
jest.mock('./SomeComponent', () => () => 'SomeComponent');
197197
```
198198
2. Render as a custom element. DOM "custom elements" aren't checked for anything and shouldn't fire warnings. They are lowercase and have a dash in the name.
199-
```js
199+
```tsx
200200
jest.mock('./Widget', () => () => <mock-widget />);
201201
```
202202
3. Use `react-test-renderer`. The test renderer doesn't care about element types and will happily accept e.g. `SomeComponent`. You could check snapshots using the test renderer, and check component behavior separately using Enzyme.
@@ -216,7 +216,7 @@ You have to run `yarn add --dev @testing-library/react` to use react-testing-lib
216216

217217
Let's implement a checkbox which swaps between two labels:
218218
219-
```javascript
219+
```tsx
220220
// CheckboxWithLabel.js
221221
222222
import React from 'react';
@@ -250,7 +250,7 @@ export default class CheckboxWithLabel extends React.Component {
250250
}
251251
```
252252
253-
```javascript
253+
```tsx
254254
// __tests__/CheckboxWithLabel-test.js
255255
import React from 'react';
256256
import {cleanup, fireEvent, render} from '@testing-library/react';
@@ -281,7 +281,7 @@ You have to run `yarn add --dev enzyme` to use Enzyme. If you are using a React
281281
282282
Let's rewrite the test from above using Enzyme instead of react-testing-library. We use Enzyme's [shallow renderer](http://airbnb.io/enzyme/docs/api/shallow.html) in this example.
283283
284-
```javascript
284+
```tsx
285285
// __tests__/CheckboxWithLabel-test.js
286286

287287
import React from 'react';

docs/TutorialReactNative.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ Get a deeper insight into testing a working React Native app example by reading
1212
Starting from react-native version 0.38, a Jest setup is included by default when running `react-native init`. The following configuration should be automatically added to your package.json file:
1313

1414
```json
15-
// package.json
15+
{
1616
"scripts": {
1717
"test": "jest"
1818
},
1919
"jest": {
2020
"preset": "react-native"
2121
}
22+
}
2223
```
2324

2425
_Note: If you are upgrading your react-native application and previously used the `jest-react-native` preset, remove the dependency from your `package.json` file and change the preset to `react-native` instead._
@@ -29,7 +30,7 @@ Run `yarn test` to run tests with Jest.
2930

3031
Let's create a [snapshot test](SnapshotTesting.md) for a small intro component with a few views and text components and some styles:
3132

32-
```javascript
33+
```tsx
3334
// Intro.js
3435
import React, {Component} from 'react';
3536
import {StyleSheet, Text, View} from 'react-native';
@@ -69,7 +70,7 @@ export default class Intro extends Component {
6970

7071
Now let's use React's test renderer and Jest's snapshot feature to interact with the component and capture the rendered output and create a snapshot file:
7172

72-
```javascript
73+
```tsx
7374
// __tests__/Intro-test.js
7475
import React from 'react';
7576
import renderer from 'react-test-renderer';
@@ -138,9 +139,11 @@ The [`transformIgnorePatterns`](configuration.html#transformignorepatterns-array
138139
By default the jest-react-native preset only processes the project's own source files and react-native. If you have npm dependencies that have to be transformed you can customize this configuration option by including modules other than react-native:
139140

140141
```json
141-
"transformIgnorePatterns": [
142-
"node_modules/(?!(react-native|my-project|react-native-button)/)"
143-
]
142+
{
143+
"transformIgnorePatterns": [
144+
"node_modules/(?!(react-native|my-project|react-native-button)/)"
145+
]
146+
}
144147
```
145148

146149
### setupFiles
@@ -152,8 +155,10 @@ If you'd like to provide additional configuration for every test file, the [`set
152155
The [`moduleNameMapper`](configuration.html#modulenamemapper-objectstring-string--arraystring) can be used to map a module path to a different module. By default the preset maps all images to an image stub module but if a module cannot be found this configuration option can help:
153156

154157
```json
155-
"moduleNameMapper": {
156-
"my-module.js": "<rootDir>/path/to/my-module.js"
158+
{
159+
"moduleNameMapper": {
160+
"my-module.js": "<rootDir>/path/to/my-module.js"
161+
}
157162
}
158163
```
159164

e2e/babel-plugin-jest-hoist/__tests__/integration.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jest.mock('../__test_modules__/f', () => {
5454
jest.mock(`../__test_modules__/jestBackticks`);
5555
jest.mock('virtual-module', () => 'kiwi', {virtual: true});
5656
// This has types that should be ignored by the out-of-scope variables check.
57-
jest.mock('has-flow-types', () => (props: {children: mixed}) => 3, {
57+
jest.mock('has-flow-types', () => (props: {children: unknown}) => 3, {
5858
virtual: true,
5959
});
6060

fixtures/parser_tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
const fixtures = __dirname;
99

10+
// eslint-disable-next-line no-undef
1011
function parserTests(parse: (file: string) => BabylonParserResult) {
1112
describe('File parsing without throwing', () => {
1213
it('Should not throw', () => {

packages/jest-validate/README.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,48 @@ npm install --save jest-validate
1111
```js
1212
import {validate} from 'jest-validate';
1313

14-
validate((config: Object), (options: ValidationOptions)); // => {hasDeprecationWarnings: boolean, isValid: boolean}
14+
validate(config, validationOptions); // => {hasDeprecationWarnings: boolean, isValid: boolean}
1515
```
1616

1717
Where `ValidationOptions` are:
1818

19-
```js
19+
```ts
2020
type ValidationOptions = {
21-
blacklist?: Array<string>,
22-
comment?: string,
23-
condition?: (option: any, validOption: any) => boolean,
21+
comment?: string;
22+
condition?: (option: unknown, validOption: unknown) => boolean;
2423
deprecate?: (
25-
config: Object,
24+
config: Record<string, unknown>,
2625
option: string,
27-
deprecatedOptions: Object,
26+
deprecatedOptions: DeprecatedOptions,
2827
options: ValidationOptions,
29-
) => true,
30-
deprecatedConfig?: {[key: string]: Function},
28+
) => boolean;
29+
deprecatedConfig?: DeprecatedOptions;
3130
error?: (
3231
option: string,
33-
received: any,
34-
defaultValue: any,
32+
received: unknown,
33+
defaultValue: unknown,
3534
options: ValidationOptions,
36-
) => void,
37-
exampleConfig: Object,
38-
recursive?: boolean,
39-
title?: Title,
35+
path?: Array<string>,
36+
) => void;
37+
exampleConfig: Record<string, unknown>;
38+
recursive?: boolean;
39+
recursiveBlacklist?: Array<string>;
40+
recursiveDenylist?: Array<string>;
41+
title?: Title;
4042
unknown?: (
41-
config: Object,
42-
exampleConfig: Object,
43+
config: Record<string, unknown>,
44+
exampleConfig: Record<string, unknown>,
4345
option: string,
4446
options: ValidationOptions,
45-
) => void,
47+
path?: Array<string>,
48+
) => void;
4649
};
4750

48-
type Title = {|
49-
deprecation?: string,
50-
error?: string,
51-
warning?: string,
52-
|};
51+
type Title = {
52+
deprecation?: string;
53+
error?: string;
54+
warning?: string;
55+
};
5356
```
5457

5558
`exampleConfig` is the only option required.

website/versioned_docs/version-22.x/SnapshotTesting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A typical snapshot test case renders a UI component, takes a snapshot, then comp
1212

1313
A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/master/examples/snapshot/Link.react.js):
1414

15-
```javascript
15+
```tsx
1616
import React from 'react';
1717
import renderer from 'react-test-renderer';
1818
import Link from '../Link.react';
@@ -52,7 +52,7 @@ It's straightforward to spot when a snapshot test fails after a bug has been int
5252

5353
One such situation can arise if we intentionally change the address the Link component in our example is pointing to.
5454

55-
```javascript
55+
```tsx
5656
// Updated test case with a Link to a different address
5757
it('renders correctly', () => {
5858
const tree = renderer

website/versioned_docs/version-22.x/TutorialReact.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Your `package.json` should look something like this (where `<current-version>` i
6161

6262
Let's create a [snapshot test](SnapshotTesting.md) for a Link component that renders hyperlinks:
6363

64-
```javascript
64+
```tsx
6565
// Link.react.js
6666
import React from 'react';
6767

@@ -107,7 +107,7 @@ export default class Link extends React.Component {
107107

108108
Now let's use React's test renderer and Jest's snapshot feature to interact with the component and capture the rendered output and create a snapshot file:
109109

110-
```javascript
110+
```tsx
111111
// Link.react.test.js
112112
import React from 'react';
113113
import renderer from 'react-test-renderer';
@@ -197,7 +197,7 @@ React 16 triggers these warnings due to how it checks element types, and the moc
197197
jest.mock('./SomeComponent', () => () => 'SomeComponent');
198198
```
199199
2. Render as a custom element. DOM "custom elements" aren't checked for anything and shouldn't fire warnings. They are lowercase and have a dash in the name.
200-
```js
200+
```tsx
201201
jest.mock('./Widget', () => () => <mock-widget />);
202202
```
203203
3. Use `react-test-renderer`. The test renderer doesn't care about element types and will happily accept e.g. `SomeComponent`. You could check snapshots using the test renderer, and check component behavior separately using Enzyme.
@@ -217,7 +217,7 @@ You have to run `yarn add --dev @testing-library/react` to use react-testing-lib
217217

218218
Let's implement a checkbox which swaps between two labels:
219219
220-
```javascript
220+
```tsx
221221
// CheckboxWithLabel.js
222222
223223
import React from 'react';
@@ -251,7 +251,7 @@ export default class CheckboxWithLabel extends React.Component {
251251
}
252252
```
253253
254-
```javascript
254+
```tsx
255255
// __tests__/CheckboxWithLabel-test.js
256256
import React from 'react';
257257
import {cleanup, fireEvent, render} from '@testing-library/react';
@@ -282,7 +282,7 @@ You have to run `yarn add --dev enzyme` to use Enzyme. If you are using a React
282282
283283
Let's rewrite the test from above using Enzyme instead of react-testing-library. We use Enzyme's [shallow renderer](http://airbnb.io/enzyme/docs/api/shallow.html) in this example.
284284
285-
```javascript
285+
```tsx
286286
// __tests__/CheckboxWithLabel-test.js
287287

288288
import React from 'react';

website/versioned_docs/version-22.x/TutorialReactNative.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ Get a deeper insight into testing a working React Native app example by reading
1313
Starting from react-native version 0.38, a Jest setup is included by default when running `react-native init`. The following configuration should be automatically added to your package.json file:
1414

1515
```json
16-
// package.json
16+
{
1717
"scripts": {
1818
"test": "jest"
1919
},
2020
"jest": {
2121
"preset": "react-native"
2222
}
23+
}
2324
```
2425

2526
_Note: If you are upgrading your react-native application and previously used the `jest-react-native` preset, remove the dependency from your `package.json` file and change the preset to `react-native` instead._
@@ -30,7 +31,7 @@ Run `yarn test` to run tests with Jest.
3031

3132
Let's create a [snapshot test](SnapshotTesting.md) for a small intro component with a few views and text components and some styles:
3233

33-
```javascript
34+
```tsx
3435
// Intro.js
3536
import React, {Component} from 'react';
3637
import {StyleSheet, Text, View} from 'react-native';
@@ -70,7 +71,7 @@ export default class Intro extends Component {
7071

7172
Now let's use React's test renderer and Jest's snapshot feature to interact with the component and capture the rendered output and create a snapshot file:
7273

73-
```javascript
74+
```tsx
7475
// __tests__/Intro-test.js
7576
import React from 'react';
7677
import renderer from 'react-test-renderer';
@@ -139,9 +140,11 @@ The [`transformIgnorePatterns`](configuration.html#transformignorepatterns-array
139140
By default the jest-react-native preset only processes the project's own source files and react-native. If you have npm dependencies that have to be transformed you can customize this configuration option by including modules other than react-native:
140141

141142
```json
142-
"transformIgnorePatterns": [
143-
"node_modules/(?!(react-native|my-project|react-native-button)/)"
144-
]
143+
{
144+
"transformIgnorePatterns": [
145+
"node_modules/(?!(react-native|my-project|react-native-button)/)"
146+
]
147+
}
145148
```
146149

147150
### setupFiles
@@ -153,8 +156,10 @@ If you'd like to provide additional configuration for every test file, the [`set
153156
The [`moduleNameMapper`](configuration.html#modulenamemapper-objectstring-string) can be used to map a module path to a different module. By default the preset maps all images to an image stub module but if a module cannot be found this configuration option can help:
154157

155158
```json
156-
"moduleNameMapper": {
157-
"my-module.js": "<rootDir>/path/to/my-module.js"
159+
{
160+
"moduleNameMapper": {
161+
"my-module.js": "<rootDir>/path/to/my-module.js"
162+
}
158163
}
159164
```
160165

0 commit comments

Comments
 (0)