forked from alexeyraspopov/gulp-complexity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreporter.js
More file actions
47 lines (40 loc) · 1.37 KB
/
reporter.js
File metadata and controls
47 lines (40 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* jshint node:true */
var multiline, template, reportTemplate, reportFn;
multiline = require('multiline');
template = require('string-interpolate');
reportTemplate = multiline(function(){/*
{ chalk.styles.yellow.open }{ nope } { path }:{ line } - { name } is too complicated{ chalk.styles.yellow.close }
Cyclomatic: { complexity.cyclomatic }
Halstead: { complexity.halstead.difficulty }
| Effort: { complexity.halstead.effort }
| Volume: { complexity.halstead.volume }
| Vocabulary: { complexity.halstead.vocabulary }
*/});
reportFn = template(reportTemplate);
exports.log = function(file, report, options, fittedName){
var chalk = require('chalk'),
path = require('path'),
name = path.relative(file.cwd, file.path),
helpers = require('./reporter-helpers'),
valid = true;
report.functions.filter(function(fn){
var cyclomatic = fn.complexity.cyclomatic,
halstead = fn.complexity.halstead;
return cyclomatic > options.cyclomatic[0] || halstead.difficulty > options.halstead[0];
}).map(function(fn){
return {
path: name,
line: fn.line,
name: fn.name,
complexity: fn.complexity,
chalk: chalk,
nope: '\u2717'
};
}).forEach(function(report){
valid = false;
console.log(reportFn(report));
});
if(valid){
console.log(chalk.green('\u2713'), fittedName, helpers.generateBar(report.maintainability, options.maintainability));
}
};