Skip to content

Commit b118195

Browse files
authored
Track codehawks own badges, add a script to regenerate them (#53)
* Track codehawks own badges, add a script to regenerate them * Testing badge rendering * Improve docs, exclude mocks from results
1 parent 4bbf165 commit b118195

File tree

7 files changed

+73
-16
lines changed

7 files changed

+73
-16
lines changed

.gitignore

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

1413
# misc
1514
.DS_Store

README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
# codehawk-cli
1+
# Codehawk CLI
22

33
Codehawk is a static analysis tool for JavaScript projects. It is intended as a warning system, to identify complex areas of code that need special attention by developers.
44

5-
JavaScript, TypeScript and Flow projects are supported for analysis. The CLI tool supports unix and windows filesystems (there is a reasonable amount of Windows compatibility code). It works by traversing a directory and discovering all supported filetypes, runs a static analysis routine on each file, then performs project-wide analysis such as inter-dependency counting and test coverage mapping.
5+
![Average Maintainability](generated/avg-maintainability.svg)
6+
![Worst Maintainability](generated/worst-maintainability.svg)
7+
8+
## Scope
9+
10+
*JavaScript, TypeScript and Flow* projects are supported for analysis. The CLI tool supports unix and windows filesystems (there is a reasonable amount of Windows compatibility code).
11+
12+
It works by traversing a directory and discovering all supported filetypes, runs a static analysis routine on each file, then performs project-wide analysis such as inter-dependency counting and test coverage mapping.
613

714
The CLI runs as a Node.js process. Node.js >=12 is recommended, but >=10 should also work. <10 is unsupported.
815

@@ -31,14 +38,23 @@ Also see [an example using Next.js](https://github.com/sgb-io/codehawk-cli-examp
3138

3239
```markdown
3340
Codehawk Static Analysis Results
34-
Top 4 files
35-
36-
| File | # of Lines | Times Used/Depended On | Maintainability (higher is better) |
37-
| ------------------------------ | ---------- | ---------------------- | ---------------------------------- |
38-
| complex-utils.js | 99 | 1 | 50.76 (Could be better) |
39-
| typescript-sample.ts | 11 | 1 | 70.73 OK |
40-
| index.js | 209 | 1 | 89.94 OK |
41-
| hello.js | 6 | 1 | 91.93 OK |
41+
Top 14 files
42+
43+
| File | # of Lines | Times Used/Depended On | Maintainability (higher is better) |
44+
| -------------------------------------------------- | ---------- | ---------------------- | ---------------------------------- |
45+
| /test/codehawk.test.js | 149 | 1 | 45.3 (Needs improvement) |
46+
| /src/util.ts | 143 | 4 | 47.26 (Needs improvement) |
47+
| /src/codehawk.ts | 122 | 2 | 47.94 (Needs improvement) |
48+
| /src/options.ts | 72 | 2 | 52.64 (Could be better) |
49+
| /src/analyze.ts | 67 | 3 | 54.04 (Could be better) |
50+
| /src/cli-util.ts | 63 | 2 | 54.68 (Could be better) |
51+
| /src/traverseProject.ts | 51 | 2 | 56.91 (Could be better) |
52+
| /src/reporters/escomplex.ts | 43 | 2 | 57.44 (Could be better) |
53+
| /src/badge.ts | 45 | 2 | 58.09 (Could be better) |
54+
| /test/options.test.js | 47 | 1 | 58.55 (Could be better) |
55+
| /src/dependencies.ts | 40 | 2 | 58.7 (Could be better) |
56+
| /src/coverage.ts | 21 | 2 | 60.75 OK |
57+
| /src/index.ts | 20 | 1 | 60.97 OK |
4258
```
4359

4460
## Advanced usage
@@ -99,7 +115,7 @@ To customise your analysis, use the following options, placed in a `codehawk.jso
99115
| Option | Description | Default |
100116
|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
101117
| `enableFlow` | Enable Flow support | `false` |
102-
| `extensions` | File extensions that should be analyzed. The default is always used, but you can add more extensions. Use the `exclude` option to skip any of the default extensions. | `['.js', '.jsx', '.ts', '.tsx']` |
118+
| `extensions` | File extensions that should be analyzed. The default is always used, but you can add more extensions. You can use the `exclude[...]` options to exclude specific files. | `['.js', '.jsx', '.ts', '.tsx']` |
103119
| `excludeFilenames` | Filename matches that should be excluded from analysis. The default is always used, but you can add more matches to be excluded. Note that the matching is exact. The exclude list is taken into consideration after the extension list. | `['.d.ts', '.min.js', '.bundle.js']` |
104120
| `excludeDirectories` | Directory matches that should be excluded from analysis. Relative to the root. E.g. `['/fixtures', '/test']` | `['/dist', '/bin', '/build']` |
105121
| `skipDirectories` | Directories that should be excluded completely. The defaults will always be skipped. | `['/node_modules', '/flow-typed', '/coverage']` |

codehawk.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"skipDirectories": ["/generated", "/samples", "/test/__mocks__"]
3+
}

generated/avg-maintainability.svg

Lines changed: 20 additions & 0 deletions
Loading
Lines changed: 20 additions & 0 deletions
Loading

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "eslint src/*.**",
1010
"lint:fix": "eslint --fix src/*.**",
1111
"build": "tsc",
12+
"build:badges": "node build/index.js src",
1213
"build:watch": "tsc --watch",
1314
"prettier": "prettier --check src",
1415
"prettier:fix": "prettier --write src",

src/util.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,11 @@ export const shouldAnalyzeEntity = (
150150
return false
151151
}
152152

153-
const isWhitelisted = options.extensions.includes(extension)
154-
if (!isWhitelisted) {
153+
if (!options.extensions.includes(extension)) {
155154
return false
156155
}
157156

158-
const blacklisted = isBlocklisted(relativeDir, filename, options)
159-
if (blacklisted) {
157+
if (isBlocklisted(relativeDir, filename, options)) {
160158
return false
161159
}
162160

0 commit comments

Comments
 (0)