Skip to content

Commit

Permalink
Audit @flow and "use strict" (#3451)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mpontus authored and cpojer committed May 12, 2017
1 parent 6a12116 commit 9b157c3
Show file tree
Hide file tree
Showing 296 changed files with 48 additions and 536 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"transform-flow-strip-types",
"transform-es2015-destructuring",
"transform-es2015-parameters",
"transform-async-to-generator"
"transform-async-to-generator",
"transform-strict-mode"
],
"retainLines": true
}
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
* 80 character line length strongly preferred.
* Prefer `'` over `"`.
* ES6 syntax when possible.
* `'use strict';`.
* Use [Flow types](http://flowtype.org/).
* Use semicolons;
* Trailing commas,
Expand Down
14 changes: 0 additions & 14 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

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

'use strict';

const fs = require('fs');
const {danger, fail, warn} = require('danger');
// As danger's deps are inside a sub-folder, need to resolve via relative paths
Expand Down Expand Up @@ -88,18 +86,6 @@ const noFlowFiles = newJsFiles.filter(isSourceFile).filter(filepath => {

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

// detects the presence of ES module import/export syntax, while ignoring the
// variant introduced by flowtype; examples here: http://regexr.com/3f64p
const esModuleRegex = /^(import|export)\s(?!type(of\s|\s)(?!from)).*?$/gm;

// Ensure the use of 'use strict' on all non-ES module files
const noStrictFiles = newJsFiles.filter(filepath => {
const content = fs.readFileSync(filepath, 'utf8');
return !content.match(esModuleRegex) && !includes(content, 'use strict');
});

raiseIssueAboutPaths(fail, noStrictFiles, "'use strict'");

// No merge from master commmits
// TODO: blocked by https://github.com/danger/danger-js/issues/81

Expand Down
2 changes: 0 additions & 2 deletions examples/async/request.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2004-present Facebook. All Rights Reserved.

'use strict';

const http = require('http');

export default function request(url) {
Expand Down
2 changes: 0 additions & 2 deletions examples/async/user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2004-present Facebook. All Rights Reserved.

'use strict';

import request from './request';

export function getUserName(userID) {
Expand Down
2 changes: 0 additions & 2 deletions examples/getting_started/sum.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2004-present Facebook. All Rights Reserved.

'use strict';

function sum(a, b) {
return a + b;
}
Expand Down
2 changes: 0 additions & 2 deletions examples/getting_started/sum.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2004-present Facebook. All Rights Reserved.

'use strict';

test('adds 1 + 2 to equal 3', () => {
const sum = require('./sum');
expect(sum(1, 2)).toBe(3);
Expand Down
2 changes: 0 additions & 2 deletions examples/jquery/fetchCurrentUser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2004-present Facebook. All Rights Reserved.

'use strict';

const $ = require('jquery');

function parseJSON(user) {
Expand Down
2 changes: 0 additions & 2 deletions examples/manual_mocks/FileSummarizer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2004-present Facebook. All Rights Reserved.

'use strict';

const fs = require('fs');

function summarizeFilesInDirectorySync(directory) {
Expand Down
1 change: 0 additions & 1 deletion examples/react-native/Intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* https://github.com/facebook/react-native
* @flow
*/
'use strict';

import React, {Component} from 'react';
import {StyleSheet, Text, View} from 'react-native';
Expand Down
2 changes: 0 additions & 2 deletions examples/timer/infiniteTimerGame.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2004-present Facebook. All Rights Reserved.

'use strict';

function infiniteTimerGame(callback) {
console.log('Ready....go!');

Expand Down
2 changes: 0 additions & 2 deletions examples/timer/timerGame.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2004-present Facebook. All Rights Reserved.

'use strict';

function timerGame(callback) {
console.log('Ready....go!');
setTimeout(() => {
Expand Down
2 changes: 0 additions & 2 deletions fixtures/parserTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

const fixtures = __dirname;

function parserTests(parse: (file: string) => any) {
Expand Down
1 change: 0 additions & 1 deletion flow-typed/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
* @flow
*/
'use strict';

declare module "console" {
declare export class Console {
Expand Down
1 change: 0 additions & 1 deletion flow-typed/graceful-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
* @flow
*/
'use strict';

declare module "graceful-fs" {
declare class Stats {
Expand Down
1 change: 0 additions & 1 deletion flow-typed/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
* @flow
*/
'use strict';

declare module "resolve" {
declare function isCore(moduleName: string): boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports[`collects coverage only from specified files avoiding dependencies 1`] =
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | 85.71 | 100 | 50 | 85.71 | |
sum.js | 85.71 | 100 | 50 | 85.71 | 14 |
sum.js | 85.71 | 100 | 50 | 85.71 | 13 |
----------|----------|----------|----------|----------|----------------|
"
`;
Expand All @@ -34,10 +34,10 @@ exports[`outputs coverage report 1`] = `
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
-------------------------------|----------|----------|----------|----------|----------------|
All files | 41.18 | 0 | 25 | 41.18 | |
not-required-in-test-suite.js | 0 | 0 | 0 | 0 | 10,17,18,19,21 |
not-required-in-test-suite.js | 0 | 0 | 0 | 0 | 9,16,17,18,20 |
other-file.js | 100 | 100 | 100 | 100 | |
sum.js | 85.71 | 100 | 50 | 85.71 | 14 |
sum_dependency.js | 0 | 0 | 0 | 0 | 10,12,13,16 |
sum.js | 85.71 | 100 | 50 | 85.71 | 13 |
sum_dependency.js | 0 | 0 | 0 | 0 | 9,11,12,15 |
-------------------------------|----------|----------|----------|----------|----------------|
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`babel-jest instruments only specific files and collects coverage 1`] =
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
------------|----------|----------|----------|----------|----------------|
All files | 83.33 | 100 | 50 | 83.33 | |
covered.js | 83.33 | 100 | 50 | 83.33 | 18 |
covered.js | 83.33 | 100 | 50 | 83.33 | 16 |
------------|----------|----------|----------|----------|----------------|
"
`;
Expand All @@ -24,7 +24,7 @@ exports[`no babel-jest instrumentation with no babel-jest 1`] = `
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
------------|----------|----------|----------|----------|----------------|
All files | 83.33 | 100 | 50 | 83.33 | |
covered.js | 83.33 | 100 | 50 | 83.33 | 18 |
covered.js | 83.33 | 100 | 50 | 83.33 | 16 |
------------|----------|----------|----------|----------|----------------|
"
`;
2 changes: 0 additions & 2 deletions integration_tests/__tests__/debug-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

const path = require('path');
const skipOnWindows = require('skipOnWindows');
const {linkJestPackage} = require('../utils');
Expand Down
2 changes: 0 additions & 2 deletions integration_tests/__tests__/failures-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

const path = require('path');
const skipOnWindows = require('skipOnWindows');
const {extractSummary} = require('../utils');
Expand Down
2 changes: 0 additions & 2 deletions integration_tests/__tests__/toMatchSnapshot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

const path = require('path');
const {makeTemplate, writeFiles, cleanup} = require('../utils');
const runJest = require('../runJest');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

const path = require('path');
const {makeTemplate, writeFiles, cleanup} = require('../utils');
const runJest = require('../runJest');
Expand Down
2 changes: 0 additions & 2 deletions integration_tests/__tests__/transform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

const path = require('path');
const skipOnWindows = require('skipOnWindows');
const {linkJestPackage, run} = require('../utils');
Expand Down
2 changes: 0 additions & 2 deletions integration_tests/__tests__/typescript-coverage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

const path = require('path');
const skipOnWindows = require('skipOnWindows');
const {run} = require('../utils');
Expand Down
2 changes: 0 additions & 2 deletions integration_tests/auto-clear-mocks/with-auto-clear/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
* @flow
*/

'use strict';

module.exports = () => {};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
* @flow
*/

'use strict';

module.exports = () => {};
2 changes: 0 additions & 2 deletions integration_tests/auto-reset-mocks/with-auto-reset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

module.exports = () => {};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

module.exports = () => {};
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

export default class Mocked {
constructor() {
this.isMocked = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

export default class Unmocked {
constructor() {
this.isUnmocked = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

export default () => 'unmocked';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

export default () => 'unmocked';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

export default () => 'unmocked';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

export default () => 'unmocked';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

export default () => 'unmocked';
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

const tsc = require('typescript');

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

throw new Error(
`this error should not be a problem because` +
Expand Down
1 change: 0 additions & 1 deletion integration_tests/coverage_report/other-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

module.exports = {a: 5};
1 change: 0 additions & 1 deletion integration_tests/coverage_report/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

global.setup = true;
1 change: 0 additions & 1 deletion integration_tests/coverage_report/sum.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

require('./sum_dependency.js');
require('./other-file');
Expand Down
1 change: 0 additions & 1 deletion integration_tests/coverage_report/sum_dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

require('path');

Expand Down
1 change: 0 additions & 1 deletion integration_tests/json_reporter/sum.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

module.exports = function(a, b) {
return a + b;
Expand Down
1 change: 0 additions & 1 deletion integration_tests/resolve/test1.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

module.exports = {extension: 'android.js'};
1 change: 0 additions & 1 deletion integration_tests/resolve/test1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

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

0 comments on commit 9b157c3

Please sign in to comment.