build-system/tasks/todos.js
/**
 * Test if a file's contents contains closed TODOs.
 *
 * @param {!File} file file is a vinyl file object
 * @return {Promise<number>} Number of found closed TODOs.
 */
Test if a file's contents contains closed TODOs.
@param {!File} file file is a vinyl file object
@return {Promise} Number of found closed TODOs.
Test if a file ' s contents contains closed TODOs . @param { !File } file file is a vinyl file object @return { Promise } Number of found closed TODOs .
function findClosedTodosInFile(file) {
  var contents = file.contents.toString();
  var todos = contents.match(/TODO\([^\)]*\)/g);
  if (!todos || todos.length == 0) {
    return Promise.resolve(0);
  }
  var promises = [];
  for (var i = 0; i < todos.length; i++) {
    var todo = todos[i];
    var parts = /TODO\([^\)]*\#(\d*)\)/.exec(todo);
    var issueId = parts ? parts[1] : null;
    if (!issueId) {
      continue;
    }
    promises.push(reportClosedIssue(file, issueId, todo));
  }
  if (promises.length == 0) {
    return Promise.resolve(0);
  }
  return Promise.all(promises).then(results => {
    return results.reduce(function(acc, v) {
      return acc + v;
    }, 0);
  }).catch(function(error) {
    util.log(util.colors.red('Failed in', file.path, error, error.stack));
    return 0;
  });
}
function findClosedTodosInFile ( file ) { var contents = file . contents . toString ( ) ; var todos = contents . match ( / TODO\([^\)]*\) / g ) ; if ( ! todos || todos . length == 0 ) { return Promise . resolve ( 0 ) ; } var promises = [ ] ; for ( var i = 0 ; i < todos . length ; i ++ ) { var todo = todos [ i ] ; var parts = / TODO\([^\)]*\#(\d*)\) / . exec ( todo ) ; var issueId = parts ? parts [ 1 ] : null ; if ( ! issueId ) { continue ; } promises . push ( reportClosedIssue ( file , issueId , todo ) ) ; } if ( promises . length == 0 ) { return Promise . resolve ( 0 ) ; } return Promise . all ( promises ) . then ( results => { return results . reduce ( function ( acc , v ) { return acc + v ; } , 0 ) ; } ) . catch ( function ( error ) { util . log ( util . colors . red ( 'Failed in' , file . path , error , error . stack ) ) ; return 0 ; } ) ; }
Test if a file's contents contains closed TODOs.
Test if a file ' s contents contains closed TODOs .