Skip to content

Commit

Permalink
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.
  • Loading branch information
Evan Scott authored and skovhus committed Apr 29, 2017
1 parent a8314f2 commit 8382598
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
Expand Up @@ -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'");
Expand Down

0 comments on commit 8382598

Please sign in to comment.