Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch dangerfile to only do use strict checks on non-es modules (jest…
Browse files Browse the repository at this point in the history
…js#2709)

ES modules are strict mode by default, so the check should look
for use of "import"/"export" to determine if flagging is required.
Evan Scott authored and cpojer committed Jan 26, 2017
1 parent 975dcef commit 9c7cbdc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -86,11 +86,15 @@ const noFlowFiles = newJsFiles

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

// based on assumptions from https://github.com/nodejs/node/wiki/ES6-Module-Detection-in-Node
// basically it needs to contain at least one line with import or export at the
// beginning of it, followed by a space; any content thereafter doesn't matter
const esModuleRegex = /^(import|export)\s/g;

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

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

0 comments on commit 9c7cbdc

Please sign in to comment.