Skip to content

Commit c6f6082

Browse files
authored
Merge pull request #8 from inspekter/develop
Develop
2 parents 26a2d48 + 83868cf commit c6f6082

File tree

4 files changed

+34
-26
lines changed

4 files changed

+34
-26
lines changed

index.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
'use strict'
22

3-
const escomplex = require('escomplex')
3+
const escomplex = require('typhonjs-escomplex')
44
const path = require('path')
55
const read = require('read-file')
66

77
function sanitize (fileName, filePath, result) {
88
return {
9-
cyclomatic: result.aggregate.cyclomatic,
10-
cyclomaticDensity: result.aggregate.cyclomaticDensity,
9+
cyclomatic: result.methodAggregate.cyclomatic,
10+
cyclomaticDensity: result.methodAggregate.cyclomaticDensity,
1111
file: {
1212
name: fileName,
1313
path: filePath
1414
},
1515
halstead: {
16-
bugs: result.aggregate.halstead.bugs,
17-
difficulty: result.aggregate.halstead.difficulty,
18-
effort: result.aggregate.halstead.effort,
19-
length: result.aggregate.halstead.length,
20-
time: result.aggregate.halstead.time,
21-
vocabulary: result.aggregate.halstead.vocabulary,
22-
volume: result.aggregate.halstead.volume
16+
bugs: result.methodAggregate.halstead.bugs,
17+
difficulty: result.methodAggregate.halstead.difficulty,
18+
effort: result.methodAggregate.halstead.effort,
19+
length: result.methodAggregate.halstead.length,
20+
time: result.methodAggregate.halstead.time,
21+
vocabulary: result.methodAggregate.halstead.vocabulary,
22+
volume: result.methodAggregate.halstead.volume
2323
},
2424
maintainability: result.maintainability,
2525
sloc: {
26-
logical: result.aggregate.sloc.logical,
27-
physical: result.aggregate.sloc.physical
26+
logical: result.methodAggregate.sloc.logical,
27+
physical: result.methodAggregate.sloc.physical
2828
}
2929
}
3030
}
@@ -36,9 +36,9 @@ module.exports.analyze = (source) => {
3636

3737
if (Array.isArray(source)) {
3838
source.forEach((filePath) => {
39-
// let fullPath = path.resolve(__dirname, filePath)
40-
let content = read.sync(filePath, 'utf8')
41-
result = escomplex.analyse(content)
39+
let fullPath = path.resolve(__dirname, filePath)
40+
let content = read.sync(fullPath, 'utf8')
41+
result = escomplex.analyzeModule(content)
4242
report = sanitize(path.basename(filePath), filePath, result)
4343
reports.push(report)
4444
})
@@ -47,6 +47,4 @@ module.exports.analyze = (source) => {
4747
return reports
4848
}
4949

50-
module.exports.getExtension = () => {
51-
return 'js'
52-
}
50+
module.exports.extension = 'js'

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "inspekter-plugin-javascript",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "Inspekter JavaScript reporter",
55
"main": "index.js",
66
"scripts": {
@@ -20,9 +20,8 @@
2020
},
2121
"homepage": "https://github.com/inspekter/inspekter-plugin-javascript#readme",
2222
"dependencies": {
23-
"escomplex": "^2.0.0-alpha",
24-
"esprima": "^4.0.0",
25-
"read-file": "^0.2.0"
23+
"read-file": "^0.2.0",
24+
"typhonjs-escomplex": "0.0.12"
2625
},
2726
"devDependencies": {
2827
"chai": "^4.1.2",

test/fixtures/file3.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict'
2+
3+
import os from 'os'
4+
5+
class CpuInfo {
6+
getCpuInfo () {
7+
return os.cpus()
8+
}
9+
}
10+
11+
export default CpuInfo

test/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ describe('inspekter-plugin-javascript', () => {
7575
})
7676

7777
it('should return one report object for each file', () => {
78-
const source = ['test/fixtures/file1.js', 'test/fixtures/file2.js']
78+
const source = ['test/fixtures/file1.js', 'test/fixtures/file2.js', 'test/fixtures/file3.js']
7979
const actual = ipj.analyze(source)
8080

8181
expect(actual).to.be.an('array')
82-
expect(actual).to.have.lengthOf(2)
82+
expect(actual).to.have.lengthOf(source.length)
8383
})
8484

8585
it('should return an object with all standard properties', () => {
@@ -92,9 +92,9 @@ describe('inspekter-plugin-javascript', () => {
9292
})
9393
})
9494

95-
describe('getExtension', () => {
95+
describe('extension', () => {
9696
it('should return js', () => {
97-
const actual = ipj.getExtension()
97+
const actual = ipj.extension
9898

9999
expect(actual).to.equal('js')
100100
})

0 commit comments

Comments
 (0)