11"use strict" ;
2- var Q = require ( "q" ) ;
3- var FS = require ( "q-io/fs" ) ;
4- var esprima = require ( "esprima" ) ;
5- var pather = require ( "path" ) ;
2+ const Q = require ( "q" ) ;
3+ const FS = require ( "q-io/fs" ) ;
4+ const esprima = require ( "esprima" ) ;
5+ const pather = require ( "path" ) ;
66// http://www.regexr.com/38t47
7- var inlineCodeReg = / \[ s o u r c e .* ?j a v a s c r i p t \] \n [ \s \S ] * ?- - - - ( [ \s \S ] * ?) - - - - / gm;
8- var includeCodeReg = / i n c l u d e : : / ;
9- var skipContentPattern = / S y n t a x E r r o r / ;
7+ const inlineCodeReg = / \[ s o u r c e .* ?j a v a s c r i p t \] \n [ \s \S ] * ?- - - - ( [ \s \S ] * ?) - - - - / gm;
8+ const includeCodeReg = / i n c l u d e : : / ;
9+ const skipContentPattern = / S y n t a x E r r o r / ;
1010function trimIncludeCode ( code ) {
11- var replaceRegExp = / i n c l u d e : : .* / g;
12- var trimedCode = code . replace ( replaceRegExp , "" ) ;
11+ const replaceRegExp = / i n c l u d e : : .* / g;
12+ const trimedCode = code . replace ( replaceRegExp , "" ) ;
1313 return trimedCode . trim ( ) ;
1414}
1515function pickupContent ( content ) {
16- var results = [ ] ;
17- var matches ;
16+ const results = [ ] ;
17+ let matches ;
1818 while ( ( matches = inlineCodeReg . exec ( content ) ) !== null ) {
19- var code = matches [ 1 ] ;
19+ const code = matches [ 1 ] ;
2020 if ( includeCodeReg . test ( code ) ) {
21- var trimedCode = trimIncludeCode ( code ) ;
21+ const trimedCode = trimIncludeCode ( code ) ;
2222 if ( trimedCode . length > 0 ) {
2323 results . push ( trimedCode ) ;
2424 }
@@ -30,7 +30,7 @@ function pickupContent(content) {
3030}
3131function parseContents ( content , filePath ) {
3232 // skip
33- if ( skipContentPattern . test ( content ) ) {
33+ if ( skipContentPattern . test ( content ) ) {
3434 return ;
3535 }
3636 try {
@@ -43,39 +43,39 @@ function parseContents(content, filePath) {
4343}
4444
4545function printResults ( results ) {
46- results . forEach ( function ( errors ) {
47- errors . forEach ( function ( error ) {
46+ results . forEach ( ( errors ) => {
47+ errors . forEach ( ( error ) => {
4848 console . error ( ">> filePath : " + pather . resolve ( error . filePath ) + "\n"
4949 + "----\n" + error . fileContent . trim ( ) + "\n----\n" ,
50- error ,
51- "\n\n"
50+ error ,
51+ "\n\n"
5252 ) ;
5353 } ) ;
5454 } ) ;
5555}
5656
5757module . exports . checkInlineScript = function checkInlineScript ( rootPath ) {
58- var asciidocPromises = FS . listTree ( rootPath , function isAsciiDoc ( filePath , stat ) {
58+ const asciidocPromises = FS . listTree ( rootPath , ( filePath , stat ) => {
5959 if ( stat . isDirectory ( ) ) {
6060 return false ;
6161 }
6262 return pather . extname ( filePath ) === ".adoc" ;
6363 } ) ;
6464
65- return asciidocPromises . then ( function ( filePathList ) {
66- var promises = filePathList . map ( function ( filePath ) {
65+ return asciidocPromises . then ( ( filePathList ) => {
66+ const promises = filePathList . map ( ( filePath ) => {
6767 return FS . read ( filePath )
6868 . then ( pickupContent )
69- . then ( function ( contents ) {
70- return contents . map ( function ( content ) {
69+ . then ( ( contents ) => {
70+ return contents . map ( ( content ) => {
7171 return parseContents ( content , filePath ) ;
72- } ) . filter ( function hasError ( error ) {
72+ } ) . filter ( ( error ) => {
7373 return error != null && error instanceof Error ;
7474 } ) ;
7575 } ) ;
7676 } ) ;
77- return Q . all ( promises ) . then ( function ( results ) {
78- var filteredResults = results . filter ( function ( errors ) {
77+ return Q . all ( promises ) . then ( ( results ) => {
78+ const filteredResults = results . filter ( ( errors ) => {
7979 return Array . isArray ( errors ) && errors . length > 0 ;
8080 } ) ;
8181
0 commit comments