Skip to content

Commit abba797

Browse files
authored
New Results API (#49)
1 parent c1a79d7 commit abba797

File tree

28 files changed

+2585
-2704
lines changed

28 files changed

+2585
-2704
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# production
1010
/build
1111
bin
12+
generated
1213

1314
# misc
1415
.DS_Store

.prettierignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ coverage
55
bin
66

77
# Types
8-
src/types/
9-
src/types.ts
8+
src/types/*

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ Top 4 files
4343

4444
## Advanced usage
4545

46+
Analyze an entire directory:
47+
48+
```javascript
49+
const { analyzeProject } = require('codehawk-cli')
50+
51+
const output = analyzeProject('/path/to/project') // returns a Results object
52+
53+
// Get summary maintainability scores
54+
const {
55+
average,
56+
median,
57+
worst,
58+
} = output.summary
59+
```
60+
4661
Analyze a single piece of code:
4762

4863
```javascript
@@ -64,18 +79,6 @@ console.log(metrics) // Inspect the full metrics
6479

6580
```
6681

67-
Analyze an entire directory:
68-
69-
```javascript
70-
const { analyzeProject } = require('codehawk-cli')
71-
72-
const output = analyzeProject('/path/to/project') // FullyAnalyzedEntity[]
73-
74-
// Output contains a tree structure of your directory,
75-
// with all supported files containing a 'complexityReport'
76-
// (see above for example)
77-
```
78-
7982
## More information
8083

8184
Codehawk depends on `typhonjs-escomplex` for low level complexity metrics.

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Static analysis tool for JavaScript projects",
55
"scripts": {
66
"test": "jest --testTimeout 15000",
7+
"test:watch": "jest --watch",
78
"test:coverage": "jest --coverage",
89
"lint": "eslint src/*.**",
910
"lint:fix": "eslint --fix src/*.**",
@@ -25,6 +26,7 @@
2526
"dependencies": {
2627
"@babel/core": "^7.7.2",
2728
"@babel/plugin-transform-typescript": "^7.7.2",
29+
"badgen": "^3.2.2",
2830
"flow-remove-types": "^2.111.3",
2931
"is-dotdir": "^1.0.1",
3032
"is-dotfile": "^2.0.0",
@@ -46,14 +48,18 @@
4648
"eslint-plugin-prettier": "^3.1.4",
4749
"eslint-plugin-promise": "4",
4850
"eslint-plugin-standard": "4",
49-
"jest": "^26.0.1",
51+
"jest": "^26.6.3",
5052
"prettier": "^2.0.5",
51-
"typescript": "^3.9.5"
53+
"typescript": "^4.1.3"
5254
},
5355
"bin": {
5456
"codehawk": "build/index.js",
5557
"codehawk-cli": "build/index.js"
5658
},
5759
"main": "build/codehawk.js",
58-
"types": "build/codehawk.d.ts"
60+
"types": "build/codehawk.d.ts",
61+
"engines": {
62+
"npm": "please-use-yarn",
63+
"node": ">=10"
64+
}
5965
}
Lines changed: 106 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,107 @@
11
{
2-
"results": [
3-
{
4-
"type": "file",
5-
"fullPath": "/samples/react-component-flow/Button.css",
6-
"path": "/samples/react-component-flow",
7-
"filename": "Button.css",
8-
"shouldAnalyze": false,
9-
"complexityReport": null,
10-
"timesDependedOn": 0
11-
},
12-
{
13-
"type": "file",
14-
"fullPath": "/samples/react-component-flow/Button.jsx",
15-
"path": "/samples/react-component-flow",
16-
"filename": "Button.jsx",
17-
"shouldAnalyze": true,
18-
"complexityReport": {
19-
"aggregate": {
20-
"cyclomatic": 12,
21-
"cyclomaticDensity": 29.268,
22-
"halstead": {
23-
"bugs": 0.331,
24-
"difficulty": 14.957,
25-
"effort": 14872.029,
26-
"length": 167,
27-
"time": 826.224,
28-
"vocabulary": 62,
29-
"volume": 994.351,
30-
"operands": {
31-
"distinct": 46,
32-
"total": 86
33-
},
34-
"operators": {
35-
"distinct": 16,
36-
"total": 81
37-
}
38-
},
39-
"paramCount": 5,
40-
"sloc": {
41-
"logical": 41,
42-
"physical": 74
43-
}
44-
},
45-
"dependencies": [
46-
{
47-
"line": 3,
48-
"path": "react",
49-
"type": "esm"
50-
},
51-
{
52-
"line": 4,
53-
"path": "lodash/pick",
54-
"type": "esm"
55-
},
56-
{
57-
"line": 5,
58-
"path": "../../../utils/classcaded",
59-
"type": "esm"
60-
},
61-
{
62-
"line": 6,
63-
"path": "./Button.css",
64-
"type": "esm"
65-
}
66-
],
67-
"errors": [],
68-
"lineEnd": 74,
69-
"lineStart": 1,
70-
"maintainability": 120.805,
71-
"codehawkScore": 53.68354105285161,
72-
"coverage": "0"
73-
},
74-
"timesDependedOn": 0
75-
},
76-
{
77-
"type": "file",
78-
"fullPath": "/samples/react-component-flow/expected.json",
79-
"path": "/samples/react-component-flow",
80-
"filename": "expected.json",
81-
"shouldAnalyze": false,
82-
"complexityReport": null,
83-
"timesDependedOn": 0
84-
}
85-
]
86-
}
2+
"summary": {
3+
"average": 53.68354105285161,
4+
"median": 53.68354105285161,
5+
"worst": 53.68354105285161
6+
},
7+
"resultsList": [
8+
{
9+
"fullPath": "/samples/react-component-flow/Button.jsx",
10+
"filename": "Button.jsx",
11+
"shouldAnalyze": true,
12+
"path": "/samples/react-component-flow",
13+
"type": "file",
14+
"complexityReport": {
15+
"aggregate": {
16+
"cyclomatic": 12,
17+
"cyclomaticDensity": 29.268,
18+
"halstead": {
19+
"bugs": 0.331,
20+
"difficulty": 14.957,
21+
"effort": 14872.029,
22+
"length": 167,
23+
"time": 826.224,
24+
"vocabulary": 62,
25+
"volume": 994.351,
26+
"operands": { "distinct": 46, "total": 86 },
27+
"operators": { "distinct": 16, "total": 81 }
28+
},
29+
"paramCount": 5,
30+
"sloc": { "logical": 41, "physical": 74 }
31+
},
32+
"dependencies": [
33+
{ "line": 3, "path": "react", "type": "esm" },
34+
{ "line": 4, "path": "lodash/pick", "type": "esm" },
35+
{ "line": 5, "path": "../../../utils/classcaded", "type": "esm" },
36+
{ "line": 6, "path": "./Button.css", "type": "esm" }
37+
],
38+
"errors": [],
39+
"lineEnd": 74,
40+
"lineStart": 1,
41+
"maintainability": 120.805,
42+
"codehawkScore": 53.68354105285161,
43+
"coverage": "0"
44+
},
45+
"timesDependedOn": 0
46+
}
47+
],
48+
"fullResultsTree": [
49+
{
50+
"fullPath": "/samples/react-component-flow/Button.css",
51+
"filename": "Button.css",
52+
"shouldAnalyze": false,
53+
"path": "/samples/react-component-flow",
54+
"type": "file",
55+
"complexityReport": null,
56+
"timesDependedOn": 0
57+
},
58+
{
59+
"fullPath": "/samples/react-component-flow/Button.jsx",
60+
"filename": "Button.jsx",
61+
"shouldAnalyze": true,
62+
"path": "/samples/react-component-flow",
63+
"type": "file",
64+
"complexityReport": {
65+
"aggregate": {
66+
"cyclomatic": 12,
67+
"cyclomaticDensity": 29.268,
68+
"halstead": {
69+
"bugs": 0.331,
70+
"difficulty": 14.957,
71+
"effort": 14872.029,
72+
"length": 167,
73+
"time": 826.224,
74+
"vocabulary": 62,
75+
"volume": 994.351,
76+
"operands": { "distinct": 46, "total": 86 },
77+
"operators": { "distinct": 16, "total": 81 }
78+
},
79+
"paramCount": 5,
80+
"sloc": { "logical": 41, "physical": 74 }
81+
},
82+
"dependencies": [
83+
{ "line": 3, "path": "react", "type": "esm" },
84+
{ "line": 4, "path": "lodash/pick", "type": "esm" },
85+
{ "line": 5, "path": "../../../utils/classcaded", "type": "esm" },
86+
{ "line": 6, "path": "./Button.css", "type": "esm" }
87+
],
88+
"errors": [],
89+
"lineEnd": 74,
90+
"lineStart": 1,
91+
"maintainability": 120.805,
92+
"codehawkScore": 53.68354105285161,
93+
"coverage": "0"
94+
},
95+
"timesDependedOn": 0
96+
},
97+
{
98+
"fullPath": "/samples/react-component-flow/expected.json",
99+
"filename": "expected.json",
100+
"shouldAnalyze": false,
101+
"path": "/samples/react-component-flow",
102+
"type": "file",
103+
"complexityReport": null,
104+
"timesDependedOn": 0
105+
}
106+
]
107+
}

0 commit comments

Comments
 (0)