-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (44 loc) · 1.42 KB
/
index.js
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
48
49
50
'use strict'
const escomplex = require('typhonjs-escomplex')
const path = require('path')
const read = require('read-file')
function sanitize (fileName, filePath, result) {
return {
cyclomatic: result.methodAggregate.cyclomatic,
cyclomaticDensity: result.methodAggregate.cyclomaticDensity,
file: {
name: fileName,
path: filePath
},
halstead: {
bugs: result.methodAggregate.halstead.bugs,
difficulty: result.methodAggregate.halstead.difficulty,
effort: result.methodAggregate.halstead.effort,
length: result.methodAggregate.halstead.length,
time: result.methodAggregate.halstead.time,
vocabulary: result.methodAggregate.halstead.vocabulary,
volume: result.methodAggregate.halstead.volume
},
maintainability: result.maintainability,
sloc: {
logical: result.methodAggregate.sloc.logical,
physical: result.methodAggregate.sloc.physical
}
}
}
module.exports.analyze = (source) => {
const reports = []
let report
let result
if (Array.isArray(source)) {
source.forEach((filePath) => {
let fullPath = path.resolve(__dirname, filePath)
let content = read.sync(fullPath, 'utf8')
result = escomplex.analyzeModule(content)
report = sanitize(path.basename(filePath), filePath, result)
reports.push(report)
})
}
return reports
}
module.exports.extension = 'js'