Example #1
0
		Report.findOne( conditions, function ( error, report ) {
			if ( error ) {
				throw new Error( error );
			}

			if ( report ) {
				return callback();
			}

			var ast = {
				'path' : file,
				'code' : contents
			};

			var result = escomplex.analyse( [ ast ], options );

			result.reports.forEach( function ( value, index ) {
				var report = new Report( {
					'project'         : project,
					'path'            : value.path,
					'checksum'        : sha1,
					'date'            : now,
					'maintainability' : value.maintainability,
					'params'          : value.params,
					'aggregate'       : value.aggregate,
					'functions'       : value.functions,
					'dependencies'    : value.dependencies
				} );

				saveReport( report, callback );

			} );

		} );
Example #2
0
function getReports () {
    var jsResult, coffeeResult, result, failingModules;

    try {
        if (cli.coffeescript) {
            // if we have coffeescript,
            // we will be merning results
            // and recalculating all the values.
            // skipping the calculation here saves on computation
            options.skipCalculation = true;
            coffeeResult = coffee.analyse(state.sources.coffee, options);
        }
        jsResult = js.analyse(state.sources.js, options);
        result = mergeResults(jsResult, coffeeResult);

        if (!cli.silent) {
            writeReports(result);
        }

        failingModules = getFailingModules(result.reports);
        if (failingModules.length > 0) {
            return fail('Warning: Complexity threshold breached!\nFailing modules:\n' + failingModules.join('\n'));
        }

        if (isProjectComplexityThresholdSet() && isProjectTooComplex(result)) {
            fail('Warning: Project complexity threshold breached!');
        }
    } catch (err) {
        error('getReports', err);
    }
}
Example #3
0
function analyse(sourcePaths, options) {
  var sources = [];
  sourcePaths.forEach(function (sourcePath) {
    var source = fs.readFileSync(sourcePath, {encoding: 'utf8'});
    if (!source.indexOf('#!')) {
      source = '//' + source;
    }
    sources.push({
      path: sourcePath,
      code: source
    });
  });

  return escomplex.analyse(
    sources, {
      logicalor: options.ignoreOr,
      switchcase: options.ignoreSwitch,
      forin: options.includeForIn,
      trycatch: options.includeTryCatch,
      newmi: options.msMaintainabilityIndex
    }
  );
}
Example #4
0
function analyseSource (source, options) {
  return escomplex.analyse(source, options);
}