Skip to content

Commit ed95b36

Browse files
SimenBcpojer
authored andcommitted
chore: add arrow-body-style eslint rule (jestjs#6406)
* chore: add arrow-body-style eslint rule * update snapshots
1 parent 41a3e59 commit ed95b36

File tree

72 files changed

+555
-738
lines changed

Some content is hidden

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

72 files changed

+555
-738
lines changed

.eslintrc.js

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = {
2020
{
2121
files: ['*.md'],
2222
rules: {
23+
'arrow-body-style': 0,
2324
'consistent-return': 0,
2425
'flowtype/require-valid-file-annotation': 0,
2526
'import/no-extraneous-dependencies': 0,
@@ -111,6 +112,7 @@ module.exports = {
111112
parser: 'babel-eslint',
112113
plugins: ['markdown', 'import', 'prettier'],
113114
rules: {
115+
'arrow-body-style': 2,
114116
'flowtype/boolean-style': 2,
115117
'flowtype/no-primitive-constructor-types': 2,
116118
'flowtype/require-valid-file-annotation': 2,

e2e/Utils.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,15 @@ const linkJestPackage = (packageName: string, cwd: Path) => {
4848
fs.symlinkSync(packagePath, destination, 'dir');
4949
};
5050

51-
const makeTemplate = (str: string): ((values?: Array<any>) => string) => {
52-
return (values: ?Array<any>) => {
53-
return str.replace(/\$(\d+)/g, (match, number) => {
54-
if (!Array.isArray(values)) {
55-
throw new Error('Array of values must be passed to the template.');
56-
}
57-
return values[number - 1];
58-
});
59-
};
60-
};
51+
const makeTemplate = (str: string): ((values?: Array<any>) => string) => (
52+
values: ?Array<any>,
53+
) =>
54+
str.replace(/\$(\d+)/g, (match, number) => {
55+
if (!Array.isArray(values)) {
56+
throw new Error('Array of values must be passed to the template.');
57+
}
58+
return values[number - 1];
59+
});
6160

6261
const cleanup = (directory: string) => rimraf.sync(directory);
6362

@@ -93,9 +92,9 @@ const copyDir = (src: string, dest: string) => {
9392
if (!fs.existsSync(dest)) {
9493
fs.mkdirSync(dest);
9594
}
96-
fs.readdirSync(src).map(filePath => {
97-
return copyDir(path.join(src, filePath), path.join(dest, filePath));
98-
});
95+
fs.readdirSync(src).map(filePath =>
96+
copyDir(path.join(src, filePath), path.join(dest, filePath)),
97+
);
9998
} else {
10099
fs.writeFileSync(dest, fs.readFileSync(src));
101100
}
@@ -160,11 +159,10 @@ const extractSummary = (
160159
// different versions of Node print different stack traces. This function
161160
// unifies their output to make it possible to snapshot them.
162161
// TODO: Remove when we drop support for node 4
163-
const cleanupStackTrace = (output: string) => {
164-
return output
162+
const cleanupStackTrace = (output: string) =>
163+
output
165164
.replace(/.*(?=packages)/g, ' at ')
166165
.replace(/^.*at.*[\s][\(]?(\S*\:\d*\:\d*).*$/gm, ' at $1');
167-
};
168166

169167
const normalizeIcons = (str: string) => {
170168
if (!str) {

e2e/__tests__/__snapshots__/coverage_report.test.js.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ exports[`collects coverage only from specified files avoiding dependencies 1`] =
3535
"----------|----------|----------|----------|----------|-------------------|
3636
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
3737
----------|----------|----------|----------|----------|-------------------|
38-
All files | 85.71 | 100 | 50 | 85.71 | |
39-
Sum.js | 85.71 | 100 | 50 | 85.71 | 12 |
38+
All files | 85.71 | 100 | 50 | 100 | |
39+
Sum.js | 85.71 | 100 | 50 | 100 | |
4040
----------|----------|----------|----------|----------|-------------------|"
4141
`;
4242

@@ -53,11 +53,11 @@ exports[`outputs coverage report 1`] = `
5353
"-------------------------------------|----------|----------|----------|----------|-------------------|
5454
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
5555
-------------------------------------|----------|----------|----------|----------|-------------------|
56-
All files | 56.52 | 0 | 50 | 56.52 | |
57-
coverage-report | 41.18 | 0 | 25 | 41.18 | |
56+
All files | 56.52 | 0 | 50 | 55.56 | |
57+
coverage-report | 41.18 | 0 | 25 | 42.86 | |
5858
OtherFile.js | 100 | 100 | 100 | 100 | |
59-
Sum.js | 85.71 | 100 | 50 | 85.71 | 12 |
60-
SumDependency.js | 0 | 0 | 0 | 0 | 8,10,11,14 |
59+
Sum.js | 85.71 | 100 | 50 | 100 | |
60+
SumDependency.js | 0 | 0 | 0 | 0 | 8,10,12 |
6161
notRequiredInTestSuite.js | 0 | 0 | 0 | 0 | 8,15,16,17,19 |
6262
coverage-report/cached-duplicates/a | 100 | 100 | 100 | 100 | |
6363
Identical.js | 100 | 100 | 100 | 100 | |

e2e/__tests__/__snapshots__/error-on-deprecated.test.js.snap

+7-7
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,15 @@ exports[`spyOn.test.js errors in errorOnDeprecated mode 1`] = `
212212
213213
Illegal usage of global \`spyOn\`, prefer \`jest.spyOn\`.
214214
215-
15 |
216-
16 | test('spyOn', () => {
217-
> 17 | spyOn(subject, 'func').and.returnValue('bar');
215+
13 |
216+
14 | test('spyOn', () => {
217+
> 15 | spyOn(subject, 'func').and.returnValue('bar');
218218
| ^
219-
18 | expect(subject.func()).toBe('bar');
220-
19 | });
221-
20 |
219+
16 | expect(subject.func()).toBe('bar');
220+
17 | });
221+
18 |
222222
223-
at __tests__/spyOn.test.js:17:3
223+
at __tests__/spyOn.test.js:15:3
224224
225225
"
226226
`;

e2e/__tests__/__snapshots__/failures.test.js.snap

+40-42
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ exports[`not throwing Error objects 5`] = `
240240
| ^
241241
37 | });
242242
38 |
243-
39 | test('returned promise rejection', () => {
243+
39 | test('returned promise rejection', () => Promise.reject(deepObject));
244244
245245
at __tests__/during_tests.test.js:36:3
246246
@@ -257,11 +257,9 @@ exports[`not throwing Error objects 5`] = `
257257
258258
37 | });
259259
38 |
260-
> 39 | test('returned promise rejection', () => {
260+
> 39 | test('returned promise rejection', () => Promise.reject(deepObject));
261261
| ^
262-
40 | return Promise.reject(deepObject);
263-
41 | });
264-
42 |
262+
40 |
265263
266264
at __tests__/during_tests.test.js:39:1
267265
@@ -322,14 +320,14 @@ exports[`works with async failures 1`] = `
322320
}
323321
324322
10 |
325-
11 | test('resolve, but fail', () => {
326-
> 12 | return expect(Promise.resolve({foo: 'bar'})).resolves.toEqual({baz: 'bar'});
327-
| ^
328-
13 | });
329-
14 |
330-
15 | test('reject, but fail', () => {
323+
11 | test('resolve, but fail', () =>
324+
> 12 | expect(Promise.resolve({foo: 'bar'})).resolves.toEqual({baz: 'bar'}));
325+
| ^
326+
13 |
327+
14 | test('reject, but fail', () =>
328+
15 | expect(Promise.reject({foo: 'bar'})).rejects.toEqual({baz: 'bar'}));
331329
332-
at __tests__/async_failures.test.js:12:57
330+
at __tests__/async_failures.test.js:12:50
333331
334332
● reject, but fail
335333
@@ -350,15 +348,15 @@ exports[`works with async failures 1`] = `
350348
+ \\"foo\\": \\"bar\\",
351349
}
352350
353-
14 |
354-
15 | test('reject, but fail', () => {
355-
> 16 | return expect(Promise.reject({foo: 'bar'})).rejects.toEqual({baz: 'bar'});
356-
| ^
357-
17 | });
358-
18 |
359-
19 | test('expect reject', () => {
351+
13 |
352+
14 | test('reject, but fail', () =>
353+
> 15 | expect(Promise.reject({foo: 'bar'})).rejects.toEqual({baz: 'bar'}));
354+
| ^
355+
16 |
356+
17 | test('expect reject', () =>
357+
18 | expect(Promise.resolve({foo: 'bar'})).rejects.toEqual({foo: 'bar'}));
360358
361-
at __tests__/async_failures.test.js:16:55
359+
at __tests__/async_failures.test.js:15:48
362360
363361
● expect reject
364362
@@ -367,15 +365,15 @@ exports[`works with async failures 1`] = `
367365
Expected received Promise to reject, instead it resolved to value
368366
{\\"foo\\": \\"bar\\"}
369367
370-
18 |
371-
19 | test('expect reject', () => {
372-
> 20 | return expect(Promise.resolve({foo: 'bar'})).rejects.toEqual({foo: 'bar'});
373-
| ^
374-
21 | });
375-
22 |
376-
23 | test('expect resolve', () => {
368+
16 |
369+
17 | test('expect reject', () =>
370+
> 18 | expect(Promise.resolve({foo: 'bar'})).rejects.toEqual({foo: 'bar'}));
371+
| ^
372+
19 |
373+
20 | test('expect resolve', () =>
374+
21 | expect(Promise.reject({foo: 'bar'})).resolves.toEqual({foo: 'bar'}));
377375
378-
at __tests__/async_failures.test.js:20:10
376+
at __tests__/async_failures.test.js:18:3
379377
380378
● expect resolve
381379
@@ -384,29 +382,29 @@ exports[`works with async failures 1`] = `
384382
Expected received Promise to resolve, instead it rejected to value
385383
{\\"foo\\": \\"bar\\"}
386384
385+
19 |
386+
20 | test('expect resolve', () =>
387+
> 21 | expect(Promise.reject({foo: 'bar'})).resolves.toEqual({foo: 'bar'}));
388+
| ^
387389
22 |
388-
23 | test('expect resolve', () => {
389-
> 24 | return expect(Promise.reject({foo: 'bar'})).resolves.toEqual({foo: 'bar'});
390-
| ^
391-
25 | });
392-
26 |
393-
27 | test(
390+
23 | test(
391+
24 | 'timeout',
394392
395-
at __tests__/async_failures.test.js:24:10
393+
at __tests__/async_failures.test.js:21:3
396394
397395
● timeout
398396
399397
<REPLACED>
400398
401-
25 | });
402-
26 |
403-
> 27 | test(
399+
21 | expect(Promise.reject({foo: 'bar'})).resolves.toEqual({foo: 'bar'}));
400+
22 |
401+
> 23 | test(
404402
| ^
405-
28 | 'timeout',
406-
29 | done => {
407-
30 | setTimeout(done, 50);
403+
24 | 'timeout',
404+
25 | done => {
405+
26 | setTimeout(done, 50);
408406
409-
at __tests__/async_failures.test.js:27:1
407+
at __tests__/async_failures.test.js:23:1
410408
411409
"
412410
`;

e2e/__tests__/__snapshots__/transform.test.js.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ exports[`babel-jest instruments only specific files and collects coverage 1`] =
44
"------------|----------|----------|----------|----------|-------------------|
55
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
66
------------|----------|----------|----------|----------|-------------------|
7-
All files | 83.33 | 100 | 50 | 83.33 | |
8-
Covered.js | 83.33 | 100 | 50 | 83.33 | 15 |
7+
All files | 83.33 | 100 | 50 | 80 | |
8+
Covered.js | 83.33 | 100 | 50 | 80 | 13 |
99
------------|----------|----------|----------|----------|-------------------|"
1010
`;
1111

@@ -21,8 +21,8 @@ exports[`no babel-jest instrumentation with no babel-jest 1`] = `
2121
"------------|----------|----------|----------|----------|-------------------|
2222
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
2323
------------|----------|----------|----------|----------|-------------------|
24-
All files | 83.33 | 100 | 50 | 83.33 | |
25-
Covered.js | 83.33 | 100 | 50 | 83.33 | 15 |
24+
All files | 83.33 | 100 | 50 | 80 | |
25+
Covered.js | 83.33 | 100 | 50 | 80 | 13 |
2626
------------|----------|----------|----------|----------|-------------------|
2727
"
2828
`;

e2e/coverage-report/Sum.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
require('./SumDependency.js');
99
require('./OtherFile');
1010

11-
const uncoveredFunction = () => {
12-
return 1 + 'abc';
13-
};
11+
const uncoveredFunction = () => 1 + 'abc';
1412

15-
const sum = (a, b) => {
16-
return a + b;
17-
};
13+
const sum = (a, b) => a + b;
1814

1915
module.exports = {
2016
sum,

e2e/coverage-report/SumDependency.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
require('path');
99

10-
const uncoveredFunction = () => {
11-
return true ? 1 + '5' : '999';
12-
};
10+
const uncoveredFunction = () => (true ? 1 + '5' : '999');
1311

1412
module.exports = {
1513
uncoveredFunction,

e2e/coverage-report/cached-duplicates/a/Identical.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
const sum = (a, b) => {
9-
return a + b;
10-
};
8+
const sum = (a, b) => a + b;
119

1210
module.exports = {sum};

e2e/coverage-report/cached-duplicates/b/Identical.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
const sum = (a, b) => {
9-
return a + b;
10-
};
8+
const sum = (a, b) => a + b;
119

1210
module.exports = {sum};

e2e/error-on-deprecated/__tests__/spyOn.test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
/* globals spyOn */
1010
const subject = {
11-
func: () => {
12-
return 'foo';
13-
},
11+
func: () => 'foo',
1412
};
1513

1614
test('spyOn', () => {

e2e/failures/__tests__/async_failures.test.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@
88
*/
99
'use strict';
1010

11-
test('resolve, but fail', () => {
12-
return expect(Promise.resolve({foo: 'bar'})).resolves.toEqual({baz: 'bar'});
13-
});
11+
test('resolve, but fail', () =>
12+
expect(Promise.resolve({foo: 'bar'})).resolves.toEqual({baz: 'bar'}));
1413

15-
test('reject, but fail', () => {
16-
return expect(Promise.reject({foo: 'bar'})).rejects.toEqual({baz: 'bar'});
17-
});
14+
test('reject, but fail', () =>
15+
expect(Promise.reject({foo: 'bar'})).rejects.toEqual({baz: 'bar'}));
1816

19-
test('expect reject', () => {
20-
return expect(Promise.resolve({foo: 'bar'})).rejects.toEqual({foo: 'bar'});
21-
});
17+
test('expect reject', () =>
18+
expect(Promise.resolve({foo: 'bar'})).rejects.toEqual({foo: 'bar'}));
2219

23-
test('expect resolve', () => {
24-
return expect(Promise.reject({foo: 'bar'})).resolves.toEqual({foo: 'bar'});
25-
});
20+
test('expect resolve', () =>
21+
expect(Promise.reject({foo: 'bar'})).resolves.toEqual({foo: 'bar'}));
2622

2723
test(
2824
'timeout',

e2e/failures/__tests__/during_tests.test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,4 @@ test('done(non-error)', done => {
3636
done(deepObject);
3737
});
3838

39-
test('returned promise rejection', () => {
40-
return Promise.reject(deepObject);
41-
});
39+
test('returned promise rejection', () => Promise.reject(deepObject));

0 commit comments

Comments
 (0)