Skip to content

Commit 5311358

Browse files
authored
Add cliOutputLimit, document minimumThreshold (#91)
1 parent c2ea528 commit 5311358

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ Top 14 files
5757
| /src/index.ts | 20 | 1 | 60.97 OK |
5858
```
5959

60+
## Options
61+
62+
To customise your analysis, use the following options, placed in a `codehawk.json` file in the root directory.
63+
64+
| Option | Description | Default |
65+
|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
66+
| `badgesDirectory` | Directory where the two maintainbility badges will be created (when enabled) | `['/generated']` |
67+
| `enableFlow` | Enable Flow support | `false` |
68+
| `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']` |
69+
| `excludeFilenames` | Filename matches that should be excluded from static analysis (but still show in the data). 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']` |
70+
| `excludeDirectories` | Directory matches that should be excluded from static analysis (but still show in the data). Relative to the root. E.g. `['/fixtures', '/test']` | `['/dist', '/bin', '/build']` |
71+
| `excludeExact` | Exact file matches that should be excluded from static analysis (but still show in the data). Relative to the root. E.g. `['/src/foo/bar.ts']` | `[]` |
72+
| `skipDirectories` | Directories that should be excluded completely, i.e. not visible in the resulting data at all. The defaults will always be skipped. | `['/node_modules', '/flow-typed', '/coverage']` |
73+
| `minimumThreshold` | Minimum acceptable maintainability score. If a file violates this score, the CLI will exit with code 1 (used to ensure a minimum level of maintainability in CI). It is recommended to set this to at least 30. | `10` |
74+
| `cliOutputLimit` | Number of files to list in the CLI output (from worst scoring to best scoring). | `25` |
75+
76+
6077
## Advanced usage
6178

6279
Analyze an entire directory:
@@ -107,21 +124,6 @@ Each analyzed file in your project ends up with:
107124
- `dependencies` - a map of this file's dependecies
108125
- `timesDependedOn` - number of times this file is imported by other files
109126
- `complexityReport` - various detailed complexity metrics such as halstead metrics and cyclomatic complexity
110-
111-
## Options
112-
113-
To customise your analysis, use the following options, placed in a `codehawk.json` file in the root directory.
114-
115-
| Option | Description | Default |
116-
|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
117-
| `badgesDirectory` | Directory where the two maintainbility badges will be created (when enabled) | `['/generated']` |
118-
| `enableFlow` | Enable Flow support | `false` |
119-
| `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']` |
120-
| `excludeFilenames` | Filename matches that should be excluded from static analysis (but still show in the data). 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']` |
121-
| `excludeDirectories` | Directory matches that should be excluded from static analysis (but still show in the data). Relative to the root. E.g. `['/fixtures', '/test']` | `['/dist', '/bin', '/build']` |
122-
| `excludeExact` | Exact file matches that should be excluded from static analysis (but still show in the data). Relative to the root. E.g. `['/src/foo/bar.ts']` | `[]` |
123-
| `skipDirectories` | Directories that should be excluded completely, i.e. not visible in the resulting data at all. The defaults will always be skipped. | `['/node_modules', '/flow-typed', '/coverage']` |
124-
125127
## Badges
126128

127129
By default, codehawk-cli generates 2 badges (in `generated/*.svg`) when called via the main CLI interface:

generated/avg-maintainability.svg

Lines changed: 4 additions & 4 deletions
Loading

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { hideBin } from 'yargs/helpers'
1111
const run = (scanDir: string, createBadge: boolean): void => {
1212
if (scanDir && scanDir !== '') {
1313
const output = analyzeProject(`${process.cwd()}/${scanDir}`, true)
14-
const formattedAsTable = output.resultsList.slice(0, 25)
14+
const formattedAsTable = output.resultsList.slice(
15+
0,
16+
output.options.cliOutputLimit
17+
)
1518
console.log(formatResultsAsTable(formattedAsTable))
1619

1720
if (!createBadge) {

src/options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ const baseOptions: CodehawkOptions = {
4545
default: 10,
4646
replaceDefault: true,
4747
},
48+
cliOutputLimit: {
49+
type: 'number',
50+
default: 25,
51+
replaceDefault: true,
52+
},
4853
}
4954

5055
const injectOptionValues = ({
@@ -72,6 +77,7 @@ const injectOptionValues = ({
7277
newOptions[optionKey] = val as string[]
7378
break
7479
case 'minimumThreshold':
80+
case 'cliOutputLimit':
7581
newOptions[optionKey] = parseInt(val, 10)
7682
break
7783
default:

src/types/codehawk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type SupportedStringArrayKeys =
77
| 'extensions'
88
| 'skipDirectories'
99
type SupportedBooleanOptions = 'enableFlow'
10-
type SupportedNumberOptions = 'minimumThreshold'
10+
type SupportedNumberOptions = 'minimumThreshold' | 'cliOutputLimit'
1111

1212
export type AllOptionKeys =
1313
| SupportedStringArrayKeys

0 commit comments

Comments
 (0)