Skip to content

Commit 9b157c3

Browse files
mpontuscpojer
authored andcommitted
Audit @flow and "use strict" (jestjs#3451)
* Remove 'use strict' from all files * 'use strict' removed from pacakges' sources * Strict mode is now enabled automatically by babel * 'use strict' check removed from dangerfile * Updated contributing guidelines * Enable @flow for most files * Commit yarn.lock * Revert removal of "use strict" in test and mock files * Improve annotations for ReportDispatcher * Replace "void 0" with "undefined" * Update babel-plugin-transform-strict-mode to match transitive deps
1 parent 6a12116 commit 9b157c3

File tree

296 files changed

+48
-536
lines changed

Some content is hidden

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

296 files changed

+48
-536
lines changed

.babelrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"transform-flow-strip-types",
55
"transform-es2015-destructuring",
66
"transform-es2015-parameters",
7-
"transform-async-to-generator"
7+
"transform-async-to-generator",
8+
"transform-strict-mode"
89
],
910
"retainLines": true
1011
}

CONTRIBUTING.md

-1

dangerfile.js

-14
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// Want to make changes? Check out the README in /danger/README.md for advice
1212

13-
'use strict';
14-
1513
const fs = require('fs');
1614
const {danger, fail, warn} = require('danger');
1715
// As danger's deps are inside a sub-folder, need to resolve via relative paths
@@ -88,18 +86,6 @@ const noFlowFiles = newJsFiles.filter(isSourceFile).filter(filepath => {
8886

8987
raiseIssueAboutPaths(warn, noFlowFiles, '@flow');
9088

91-
// detects the presence of ES module import/export syntax, while ignoring the
92-
// variant introduced by flowtype; examples here: http://regexr.com/3f64p
93-
const esModuleRegex = /^(import|export)\s(?!type(of\s|\s)(?!from)).*?$/gm;
94-
95-
// Ensure the use of 'use strict' on all non-ES module files
96-
const noStrictFiles = newJsFiles.filter(filepath => {
97-
const content = fs.readFileSync(filepath, 'utf8');
98-
return !content.match(esModuleRegex) && !includes(content, 'use strict');
99-
});
100-
101-
raiseIssueAboutPaths(fail, noStrictFiles, "'use strict'");
102-
10389
// No merge from master commmits
10490
// TODO: blocked by https://github.com/danger/danger-js/issues/81
10591

examples/async/request.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Copyright 2004-present Facebook. All Rights Reserved.
22

3-
'use strict';
4-
53
const http = require('http');
64

75
export default function request(url) {

examples/async/user.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Copyright 2004-present Facebook. All Rights Reserved.
22

3-
'use strict';
4-
53
import request from './request';
64

75
export function getUserName(userID) {

examples/getting_started/sum.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Copyright 2004-present Facebook. All Rights Reserved.
22

3-
'use strict';
4-
53
function sum(a, b) {
64
return a + b;
75
}

examples/getting_started/sum.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Copyright 2004-present Facebook. All Rights Reserved.
22

3-
'use strict';
4-
53
test('adds 1 + 2 to equal 3', () => {
64
const sum = require('./sum');
75
expect(sum(1, 2)).toBe(3);

examples/jquery/fetchCurrentUser.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Copyright 2004-present Facebook. All Rights Reserved.
22

3-
'use strict';
4-
53
const $ = require('jquery');
64

75
function parseJSON(user) {

examples/manual_mocks/FileSummarizer.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Copyright 2004-present Facebook. All Rights Reserved.
22

3-
'use strict';
4-
53
const fs = require('fs');
64

75
function summarizeFilesInDirectorySync(directory) {

examples/react-native/Intro.js

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* https://github.com/facebook/react-native
44
* @flow
55
*/
6-
'use strict';
76

87
import React, {Component} from 'react';
98
import {StyleSheet, Text, View} from 'react-native';

examples/timer/infiniteTimerGame.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Copyright 2004-present Facebook. All Rights Reserved.
22

3-
'use strict';
4-
53
function infiniteTimerGame(callback) {
64
console.log('Ready....go!');
75

examples/timer/timerGame.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Copyright 2004-present Facebook. All Rights Reserved.
22

3-
'use strict';
4-
53
function timerGame(callback) {
64
console.log('Ready....go!');
75
setTimeout(() => {

fixtures/parserTests.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
const fixtures = __dirname;
1210

1311
function parserTests(parse: (file: string) => any) {

flow-typed/console.js

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*
88
* @flow
99
*/
10-
'use strict';
1110

1211
declare module "console" {
1312
declare export class Console {

flow-typed/graceful-fs.js

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*
88
* @flow
99
*/
10-
'use strict';
1110

1211
declare module "graceful-fs" {
1312
declare class Stats {

flow-typed/resolve.js

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*
88
* @flow
99
*/
10-
'use strict';
1110

1211
declare module "resolve" {
1312
declare function isCore(moduleName: string): boolean;

integration_tests/__tests__/__snapshots__/coverage_report-test.js.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exports[`collects coverage only from specified files avoiding dependencies 1`] =
1515
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
1616
----------|----------|----------|----------|----------|----------------|
1717
All files | 85.71 | 100 | 50 | 85.71 | |
18-
sum.js | 85.71 | 100 | 50 | 85.71 | 14 |
18+
sum.js | 85.71 | 100 | 50 | 85.71 | 13 |
1919
----------|----------|----------|----------|----------|----------------|
2020
"
2121
`;
@@ -34,10 +34,10 @@ exports[`outputs coverage report 1`] = `
3434
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
3535
-------------------------------|----------|----------|----------|----------|----------------|
3636
All files | 41.18 | 0 | 25 | 41.18 | |
37-
not-required-in-test-suite.js | 0 | 0 | 0 | 0 | 10,17,18,19,21 |
37+
not-required-in-test-suite.js | 0 | 0 | 0 | 0 | 9,16,17,18,20 |
3838
other-file.js | 100 | 100 | 100 | 100 | |
39-
sum.js | 85.71 | 100 | 50 | 85.71 | 14 |
40-
sum_dependency.js | 0 | 0 | 0 | 0 | 10,12,13,16 |
39+
sum.js | 85.71 | 100 | 50 | 85.71 | 13 |
40+
sum_dependency.js | 0 | 0 | 0 | 0 | 9,11,12,15 |
4141
-------------------------------|----------|----------|----------|----------|----------------|
4242
"
4343
`;

integration_tests/__tests__/__snapshots__/transform-test.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`babel-jest instruments only specific files and collects coverage 1`] =
55
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
66
------------|----------|----------|----------|----------|----------------|
77
All files | 83.33 | 100 | 50 | 83.33 | |
8-
covered.js | 83.33 | 100 | 50 | 83.33 | 18 |
8+
covered.js | 83.33 | 100 | 50 | 83.33 | 16 |
99
------------|----------|----------|----------|----------|----------------|
1010
"
1111
`;
@@ -24,7 +24,7 @@ exports[`no babel-jest instrumentation with no babel-jest 1`] = `
2424
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
2525
------------|----------|----------|----------|----------|----------------|
2626
All files | 83.33 | 100 | 50 | 83.33 | |
27-
covered.js | 83.33 | 100 | 50 | 83.33 | 18 |
27+
covered.js | 83.33 | 100 | 50 | 83.33 | 16 |
2828
------------|----------|----------|----------|----------|----------------|
2929
"
3030
`;

integration_tests/__tests__/debug-test.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
const path = require('path');
1210
const skipOnWindows = require('skipOnWindows');
1311
const {linkJestPackage} = require('../utils');

integration_tests/__tests__/failures-test.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
const path = require('path');
1210
const skipOnWindows = require('skipOnWindows');
1311
const {extractSummary} = require('../utils');

integration_tests/__tests__/toMatchSnapshot-test.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
const path = require('path');
1210
const {makeTemplate, writeFiles, cleanup} = require('../utils');
1311
const runJest = require('../runJest');

integration_tests/__tests__/toThrowErrorMatchingSnapshot-test.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
const path = require('path');
1210
const {makeTemplate, writeFiles, cleanup} = require('../utils');
1311
const runJest = require('../runJest');

integration_tests/__tests__/transform-test.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
const path = require('path');
1210
const skipOnWindows = require('skipOnWindows');
1311
const {linkJestPackage, run} = require('../utils');

integration_tests/__tests__/typescript-coverage-test.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
const path = require('path');
1210
const skipOnWindows = require('skipOnWindows');
1311
const {run} = require('../utils');

integration_tests/auto-clear-mocks/with-auto-clear/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@
88
* @flow
99
*/
1010

11-
'use strict';
12-
1311
module.exports = () => {};

integration_tests/auto-clear-mocks/without-auto-clear/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@
88
* @flow
99
*/
1010

11-
'use strict';
12-
1311
module.exports = () => {};

integration_tests/auto-reset-mocks/with-auto-reset/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
module.exports = () => {};

integration_tests/auto-reset-mocks/without-auto-reset/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
module.exports = () => {};

integration_tests/babel-plugin-jest-hoist/__test_modules__/Mocked.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
export default class Mocked {
1210
constructor() {
1311
this.isMocked = true;

integration_tests/babel-plugin-jest-hoist/__test_modules__/Unmocked.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
export default class Unmocked {
1210
constructor() {
1311
this.isUnmocked = true;

integration_tests/babel-plugin-jest-hoist/__test_modules__/a.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
export default () => 'unmocked';

integration_tests/babel-plugin-jest-hoist/__test_modules__/b.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
export default () => 'unmocked';

integration_tests/babel-plugin-jest-hoist/__test_modules__/c.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
export default () => 'unmocked';

integration_tests/babel-plugin-jest-hoist/__test_modules__/d.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
export default () => 'unmocked';

integration_tests/babel-plugin-jest-hoist/__test_modules__/e.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
export default () => 'unmocked';

integration_tests/coverage-remapping/typescript-preprocessor.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
'use strict';
10-
119
const tsc = require('typescript');
1210

1311
module.exports = {

integration_tests/coverage_report/not-required-in-test-suite.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* LICENSE file in the root directory of this source tree. An additional grant
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
8-
'use strict';
98

109
throw new Error(
1110
`this error should not be a problem because` +

integration_tests/coverage_report/other-file.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
* LICENSE file in the root directory of this source tree. An additional grant
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
8-
'use strict';
98

109
module.exports = {a: 5};

integration_tests/coverage_report/setup.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
* LICENSE file in the root directory of this source tree. An additional grant
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
8-
'use strict';
98

109
global.setup = true;

integration_tests/coverage_report/sum.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* LICENSE file in the root directory of this source tree. An additional grant
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
8-
'use strict';
98

109
require('./sum_dependency.js');
1110
require('./other-file');

integration_tests/coverage_report/sum_dependency.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* LICENSE file in the root directory of this source tree. An additional grant
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
8-
'use strict';
98

109
require('path');
1110

integration_tests/json_reporter/sum.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* LICENSE file in the root directory of this source tree. An additional grant
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
8-
'use strict';
98

109
module.exports = function(a, b) {
1110
return a + b;

integration_tests/resolve/test1.android.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
* LICENSE file in the root directory of this source tree. An additional grant
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
8-
'use strict';
98

109
module.exports = {extension: 'android.js'};

integration_tests/resolve/test1.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
* LICENSE file in the root directory of this source tree. An additional grant
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
8-
'use strict';
98

109
module.exports = {extension: 'js'};

0 commit comments

Comments
 (0)