@@ -6,64 +6,101 @@ var glob = require('glob');
66
77var constants = require ( '../tasks/util/constants' ) ;
88
9- // check for for focus and exclude jasmine blocks
10-
11- var BLACK_LIST = [ 'fdescribe' , 'fit' , 'xdescribe' , 'xit' ] ;
9+ var srcGlob = path . join ( constants . pathToSrc , '**/*.js' ) ;
10+ var libGlob = path . join ( constants . pathToLib , '**/*.js' ) ;
1211var testGlob = path . join ( constants . pathToJasmineTests , '**/*.js' ) ;
1312var bundleTestGlob = path . join ( constants . pathToJasmineBundleTests , '**/*.js' ) ;
1413
15- var logsJasmine = [ ] ;
16- glob ( '{' + testGlob + ',' + bundleTestGlob + '}' , function ( err , files ) {
17- files . forEach ( function ( file ) {
18- var code = fs . readFileSync ( file , 'utf-8' ) ;
19-
20- falafel ( code , { locations : true } , function ( node ) {
21- if ( node . type === 'Identifier' && BLACK_LIST . indexOf ( node . name ) !== - 1 ) {
22- logsJasmine . push ( [
23- path . basename ( file ) ,
24- '[line ' + node . loc . start . line + '] :' ,
25- 'contains either a *fdescribe*, *fit*,' ,
26- '*xdescribe* or *xit* block.'
27- ] . join ( ' ' ) ) ;
28- }
14+ // main
15+ assertJasmineSuites ( ) ;
16+ assertHeaders ( ) ;
17+ assertFileNames ( ) ;
18+
19+
20+ // check for for focus and exclude jasmine blocks
21+ function assertJasmineSuites ( ) {
22+ var BLACK_LIST = [ 'fdescribe' , 'fit' , 'xdescribe' , 'xit' ] ;
23+ var logs = [ ] ;
24+
25+ glob ( combineGlobs ( [ testGlob , bundleTestGlob ] ) , function ( err , files ) {
26+ files . forEach ( function ( file ) {
27+ var code = fs . readFileSync ( file , 'utf-8' ) ;
28+
29+ falafel ( code , { locations : true } , function ( node ) {
30+ if ( node . type === 'Identifier' && BLACK_LIST . indexOf ( node . name ) !== - 1 ) {
31+ logs . push ( [
32+ path . basename ( file ) ,
33+ '[line ' + node . loc . start . line + '] :' ,
34+ 'contains either a *fdescribe*, *fit*,' ,
35+ '*xdescribe* or *xit* block.'
36+ ] . join ( ' ' ) ) ;
37+ }
38+ } ) ;
39+
2940 } ) ;
3041
42+ log ( logs ) ;
3143 } ) ;
32-
33- if ( logsJasmine . length ) {
34- throw new Error ( '\n' + logsJasmine . join ( '\n' ) + '\n' ) ;
35- }
36- } ) ;
44+ }
3745
3846// check for header in src and lib files
47+ function assertHeaders ( ) {
48+ var licenseSrc = constants . licenseSrc ;
49+ var licenseStr = licenseSrc . substring ( 2 , licenseSrc . length - 2 ) ;
50+ var logs = [ ] ;
3951
40- var licenseSrc = constants . licenseSrc ;
41- var licenseStr = licenseSrc . substring ( 2 , licenseSrc . length - 2 ) ;
42- var srcGlob = path . join ( constants . pathToSrc , '**/*.js' ) ;
43- var libGlob = path . join ( constants . pathToLib , '**/*.js' ) ;
52+ glob ( combineGlobs ( [ srcGlob , libGlob ] ) , function ( err , files ) {
53+ files . forEach ( function ( file ) {
54+ var code = fs . readFileSync ( file , 'utf-8' ) ;
4455
45- var logsHeader = [ ] ;
46- glob ( '{' + srcGlob + ',' + libGlob + '}' , function ( err , files ) {
47- files . forEach ( function ( file ) {
48- var code = fs . readFileSync ( file , 'utf-8' ) ;
56+ // parse through code string while keeping track of comments
57+ var comments = [ ] ;
58+ falafel ( code , { onComment : comments , locations : true } , function ( ) { } ) ;
4959
50- // parse through code string while keeping track of comments
51- var comments = [ ] ;
52- falafel ( code , { onComment : comments , locations : true } , function ( ) { } ) ;
60+ var header = comments [ 0 ] ;
5361
54- var header = comments [ 0 ] ;
62+ if ( ! header || header . loc . start . line > 1 ) {
63+ logs . push ( file + ' : has no header information.' ) ;
64+ return ;
65+ }
5566
56- if ( ! header || header . loc . start . line > 1 ) {
57- logsHeader . push ( file + ' : has no header information.' ) ;
58- return ;
59- }
67+ if ( header . value !== licenseStr ) {
68+ logs . push ( file + ' : has incorrect header information.' ) ;
69+ }
70+ } ) ;
6071
61- if ( header . value !== licenseStr ) {
62- logsHeader . push ( file + ' : has incorrect header information.' ) ;
63- }
72+ log ( logs ) ;
6473 } ) ;
74+ }
75+
76+ // check that all file names are in lower case
77+ function assertFileNames ( ) {
78+ var logs = [ ] ;
79+
80+ glob ( combineGlobs ( [ srcGlob , libGlob , testGlob , bundleTestGlob ] ) , function ( err , files ) {
81+ files . forEach ( function ( file ) {
82+ var base = path . basename ( file ) ;
83+
84+ if ( base !== base . toLowerCase ( ) ) {
85+ logs . push ( [
86+ file , ' :' ,
87+ 'has a file name containing some' ,
88+ 'non-lower-case characters'
89+ ] ) ;
90+ }
91+ } ) ;
92+
93+ log ( logs ) ;
94+ } ) ;
95+
96+ }
97+
98+ function combineGlobs ( arr ) {
99+ return '{' + arr . join ( ',' ) + '}' ;
100+ }
65101
66- if ( logsHeader . length ) {
67- throw new Error ( '\n' + logsHeader . join ( '\n' ) + '\n' ) ;
102+ function log ( logs ) {
103+ if ( logs . length ) {
104+ throw new Error ( '\n' + logs . join ( '\n' ) + '\n' ) ;
68105 }
69- } ) ;
106+ }
0 commit comments