Skip to content

Commit 4ec5c58

Browse files
committed
just run danger
1 parent 41781fe commit 4ec5c58

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

dangerfile.js

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

3-
import {fail, warn, danger} from 'danger';
4-
import fs from 'fs';
3+
// const { danger, fail, warn } = require('danger');
4+
const fs = require('fs')
55

66
// Takes a list of file paths, and converts it into clickable links
77
const linkableFiles = (paths: Array<string>): string => {
@@ -26,28 +26,38 @@ const createLink = (href: string, text: string): string =>
2626
const newJsFiles = danger.git.created_files.filter(path => path.endsWith('js'));
2727

2828
// New JS files should have the FB copyright header + flow
29-
const facebookLicenseHeader = `/\/\*\*
30-
\* Copyright \(c\) .*, Facebook, Inc. All rights reserved.
31-
\*
32-
\* This source code is licensed under the BSD-style license found in the
33-
\* LICENSE file in the root directory of this source tree. An additional grant
34-
\* of patent rights can be found in the PATENTS file in the same directory.
35-
\*
36-
\* @flow
37-
\*\/
38-
'use strict'`;
39-
const licenseRegex = new RegExp(facebookLicenseHeader);
29+
const facebookLicenseHeaderComponents = [
30+
'Copyright \(c\) .*, Facebook, Inc. All rights reserved.',
31+
'This source code is licensed under the BSD-style license found in the',
32+
'LICENSE file in the root directory of this source tree. An additional grant',
33+
'of patent rights can be found in the PATENTS file in the same directory.',
34+
]
4035

4136
const noFBCopyrightFiles = newJsFiles.filter(filepath => {
4237
const content = fs.readFileSync(filepath).toString();
43-
return !content.match(licenseRegex);
38+
for (const line of facebookLicenseHeaderComponents) {
39+
if(!content.match(new RegExp(line))) {
40+
return true
41+
}
42+
}
4443
});
4544

4645
if (noFBCopyrightFiles.length > 0) {
4746
const files = linkableFiles(noFBCopyrightFiles);
4847
fail(`New JS files do not have the Facebook copyright header: ${files}`);
4948
}
5049

50+
// Ensure the use of Flow and 'use strict';
51+
const noFlowFiles = newJsFiles.filter(filepath => {
52+
const content = fs.readFileSync(filepath).toString();
53+
return content.includes('@flow') && content.includes("use strict")
54+
})
55+
56+
if (noFlowFiles.length > 0) {
57+
const files = linkableFiles(noFlowFiles);
58+
warn(`Please ensure that @flow and 'use strict' are enabled on: ${files}`);
59+
}
60+
5161
// No merge from master commmits
5262
// TODO: blocked by https://github.com/danger/danger-js/issues/81
5363

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"postinstall": "node ./scripts/postinstall.js && node ./scripts/build.js",
4747
"publish": "yarn run build-clean && yarn run build && lerna publish",
4848
"test": "yarn run typecheck && yarn run lint && yarn run build && yarn run jest && yarn run test-examples",
49-
"test-ci": "yarn run typecheck && yarn run lint && yarn run build && yarn run jest-coverage -- -i && yarn run test-examples && node scripts/mapCoverage.js && codecov && yarn run danger",
49+
"test-ci": "yarn run danger",
5050
"test-examples": "node scripts/test_examples.js",
5151
"typecheck": "flow check",
5252
"watch": "yarn run build; node ./scripts/watch.js"

0 commit comments

Comments
 (0)