Skip to content

New Results API #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# production
/build
bin
generated

# misc
.DS_Store
Expand Down
3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ coverage
bin

# Types
src/types/
src/types.ts
src/types/*
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ Top 4 files

## Advanced usage

Analyze an entire directory:

```javascript
const { analyzeProject } = require('codehawk-cli')

const output = analyzeProject('/path/to/project') // returns a Results object

// Get summary maintainability scores
const {
average,
median,
worst,
} = output.summary
```

Analyze a single piece of code:

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

```

Analyze an entire directory:

```javascript
const { analyzeProject } = require('codehawk-cli')

const output = analyzeProject('/path/to/project') // FullyAnalyzedEntity[]

// Output contains a tree structure of your directory,
// with all supported files containing a 'complexityReport'
// (see above for example)
```

## More information

Codehawk depends on `typhonjs-escomplex` for low level complexity metrics.
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Static analysis tool for JavaScript projects",
"scripts": {
"test": "jest --testTimeout 15000",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"lint": "eslint src/*.**",
"lint:fix": "eslint --fix src/*.**",
Expand All @@ -25,6 +26,7 @@
"dependencies": {
"@babel/core": "^7.7.2",
"@babel/plugin-transform-typescript": "^7.7.2",
"badgen": "^3.2.2",
"flow-remove-types": "^2.111.3",
"is-dotdir": "^1.0.1",
"is-dotfile": "^2.0.0",
Expand All @@ -46,14 +48,18 @@
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-promise": "4",
"eslint-plugin-standard": "4",
"jest": "^26.0.1",
"jest": "^26.6.3",
"prettier": "^2.0.5",
"typescript": "^3.9.5"
"typescript": "^4.1.3"
},
"bin": {
"codehawk": "build/index.js",
"codehawk-cli": "build/index.js"
},
"main": "build/codehawk.js",
"types": "build/codehawk.d.ts"
"types": "build/codehawk.d.ts",
"engines": {
"npm": "please-use-yarn",
"node": ">=10"
}
}
191 changes: 106 additions & 85 deletions samples/react-component-flow/expected.json
Original file line number Diff line number Diff line change
@@ -1,86 +1,107 @@
{
"results": [
{
"type": "file",
"fullPath": "/samples/react-component-flow/Button.css",
"path": "/samples/react-component-flow",
"filename": "Button.css",
"shouldAnalyze": false,
"complexityReport": null,
"timesDependedOn": 0
},
{
"type": "file",
"fullPath": "/samples/react-component-flow/Button.jsx",
"path": "/samples/react-component-flow",
"filename": "Button.jsx",
"shouldAnalyze": true,
"complexityReport": {
"aggregate": {
"cyclomatic": 12,
"cyclomaticDensity": 29.268,
"halstead": {
"bugs": 0.331,
"difficulty": 14.957,
"effort": 14872.029,
"length": 167,
"time": 826.224,
"vocabulary": 62,
"volume": 994.351,
"operands": {
"distinct": 46,
"total": 86
},
"operators": {
"distinct": 16,
"total": 81
}
},
"paramCount": 5,
"sloc": {
"logical": 41,
"physical": 74
}
},
"dependencies": [
{
"line": 3,
"path": "react",
"type": "esm"
},
{
"line": 4,
"path": "lodash/pick",
"type": "esm"
},
{
"line": 5,
"path": "../../../utils/classcaded",
"type": "esm"
},
{
"line": 6,
"path": "./Button.css",
"type": "esm"
}
],
"errors": [],
"lineEnd": 74,
"lineStart": 1,
"maintainability": 120.805,
"codehawkScore": 53.68354105285161,
"coverage": "0"
},
"timesDependedOn": 0
},
{
"type": "file",
"fullPath": "/samples/react-component-flow/expected.json",
"path": "/samples/react-component-flow",
"filename": "expected.json",
"shouldAnalyze": false,
"complexityReport": null,
"timesDependedOn": 0
}
]
}
"summary": {
"average": 53.68354105285161,
"median": 53.68354105285161,
"worst": 53.68354105285161
},
"resultsList": [
{
"fullPath": "/samples/react-component-flow/Button.jsx",
"filename": "Button.jsx",
"shouldAnalyze": true,
"path": "/samples/react-component-flow",
"type": "file",
"complexityReport": {
"aggregate": {
"cyclomatic": 12,
"cyclomaticDensity": 29.268,
"halstead": {
"bugs": 0.331,
"difficulty": 14.957,
"effort": 14872.029,
"length": 167,
"time": 826.224,
"vocabulary": 62,
"volume": 994.351,
"operands": { "distinct": 46, "total": 86 },
"operators": { "distinct": 16, "total": 81 }
},
"paramCount": 5,
"sloc": { "logical": 41, "physical": 74 }
},
"dependencies": [
{ "line": 3, "path": "react", "type": "esm" },
{ "line": 4, "path": "lodash/pick", "type": "esm" },
{ "line": 5, "path": "../../../utils/classcaded", "type": "esm" },
{ "line": 6, "path": "./Button.css", "type": "esm" }
],
"errors": [],
"lineEnd": 74,
"lineStart": 1,
"maintainability": 120.805,
"codehawkScore": 53.68354105285161,
"coverage": "0"
},
"timesDependedOn": 0
}
],
"fullResultsTree": [
{
"fullPath": "/samples/react-component-flow/Button.css",
"filename": "Button.css",
"shouldAnalyze": false,
"path": "/samples/react-component-flow",
"type": "file",
"complexityReport": null,
"timesDependedOn": 0
},
{
"fullPath": "/samples/react-component-flow/Button.jsx",
"filename": "Button.jsx",
"shouldAnalyze": true,
"path": "/samples/react-component-flow",
"type": "file",
"complexityReport": {
"aggregate": {
"cyclomatic": 12,
"cyclomaticDensity": 29.268,
"halstead": {
"bugs": 0.331,
"difficulty": 14.957,
"effort": 14872.029,
"length": 167,
"time": 826.224,
"vocabulary": 62,
"volume": 994.351,
"operands": { "distinct": 46, "total": 86 },
"operators": { "distinct": 16, "total": 81 }
},
"paramCount": 5,
"sloc": { "logical": 41, "physical": 74 }
},
"dependencies": [
{ "line": 3, "path": "react", "type": "esm" },
{ "line": 4, "path": "lodash/pick", "type": "esm" },
{ "line": 5, "path": "../../../utils/classcaded", "type": "esm" },
{ "line": 6, "path": "./Button.css", "type": "esm" }
],
"errors": [],
"lineEnd": 74,
"lineStart": 1,
"maintainability": 120.805,
"codehawkScore": 53.68354105285161,
"coverage": "0"
},
"timesDependedOn": 0
},
{
"fullPath": "/samples/react-component-flow/expected.json",
"filename": "expected.json",
"shouldAnalyze": false,
"path": "/samples/react-component-flow",
"type": "file",
"complexityReport": null,
"timesDependedOn": 0
}
]
}
Loading