1
1
// @flow
2
2
3
- import { fail , warn , danger } from 'danger' ;
4
- import fs from 'fs' ;
3
+ // const { danger, fail, warn } = require( 'danger') ;
4
+ const fs = require ( 'fs' )
5
5
6
6
// Takes a list of file paths, and converts it into clickable links
7
7
const linkableFiles = ( paths : Array < string > ) : string => {
@@ -26,28 +26,38 @@ const createLink = (href: string, text: string): string =>
26
26
const newJsFiles = danger . git . created_files . filter ( path => path . endsWith ( 'js' ) ) ;
27
27
28
28
// 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
+ ]
40
35
41
36
const noFBCopyrightFiles = newJsFiles . filter ( filepath => {
42
37
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
+ }
44
43
} ) ;
45
44
46
45
if ( noFBCopyrightFiles . length > 0 ) {
47
46
const files = linkableFiles ( noFBCopyrightFiles ) ;
48
47
fail ( `New JS files do not have the Facebook copyright header: ${ files } ` ) ;
49
48
}
50
49
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
+
51
61
// No merge from master commmits
52
62
// TODO: blocked by https://github.com/danger/danger-js/issues/81
53
63
0 commit comments