Skip to content

Commit

Permalink
Add cliOutputLimit, document minimumThreshold (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgb-io authored Jan 9, 2021
1 parent c2ea528 commit 5311358
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ Top 14 files
| /src/index.ts | 20 | 1 | 60.97 OK |
```

## Options

To customise your analysis, use the following options, placed in a `codehawk.json` file in the root directory.

| Option | Description | Default |
|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
| `badgesDirectory` | Directory where the two maintainbility badges will be created (when enabled) | `['/generated']` |
| `enableFlow` | Enable Flow support | `false` |
| `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']` |
| `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']` |
| `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']` |
| `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']` | `[]` |
| `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']` |
| `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` |
| `cliOutputLimit` | Number of files to list in the CLI output (from worst scoring to best scoring). | `25` |


## Advanced usage

Analyze an entire directory:
Expand Down Expand Up @@ -107,21 +124,6 @@ Each analyzed file in your project ends up with:
- `dependencies` - a map of this file's dependecies
- `timesDependedOn` - number of times this file is imported by other files
- `complexityReport` - various detailed complexity metrics such as halstead metrics and cyclomatic complexity

## Options

To customise your analysis, use the following options, placed in a `codehawk.json` file in the root directory.

| Option | Description | Default |
|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
| `badgesDirectory` | Directory where the two maintainbility badges will be created (when enabled) | `['/generated']` |
| `enableFlow` | Enable Flow support | `false` |
| `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']` |
| `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']` |
| `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']` |
| `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']` | `[]` |
| `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']` |

## Badges

By default, codehawk-cli generates 2 badges (in `generated/*.svg`) when called via the main CLI interface:
Expand Down
8 changes: 4 additions & 4 deletions generated/avg-maintainability.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { hideBin } from 'yargs/helpers'
const run = (scanDir: string, createBadge: boolean): void => {
if (scanDir && scanDir !== '') {
const output = analyzeProject(`${process.cwd()}/${scanDir}`, true)
const formattedAsTable = output.resultsList.slice(0, 25)
const formattedAsTable = output.resultsList.slice(
0,
output.options.cliOutputLimit
)
console.log(formatResultsAsTable(formattedAsTable))

if (!createBadge) {
Expand Down
6 changes: 6 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const baseOptions: CodehawkOptions = {
default: 10,
replaceDefault: true,
},
cliOutputLimit: {
type: 'number',
default: 25,
replaceDefault: true,
},
}

const injectOptionValues = ({
Expand Down Expand Up @@ -72,6 +77,7 @@ const injectOptionValues = ({
newOptions[optionKey] = val as string[]
break
case 'minimumThreshold':
case 'cliOutputLimit':
newOptions[optionKey] = parseInt(val, 10)
break
default:
Expand Down
2 changes: 1 addition & 1 deletion src/types/codehawk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type SupportedStringArrayKeys =
| 'extensions'
| 'skipDirectories'
type SupportedBooleanOptions = 'enableFlow'
type SupportedNumberOptions = 'minimumThreshold'
type SupportedNumberOptions = 'minimumThreshold' | 'cliOutputLimit'

export type AllOptionKeys =
| SupportedStringArrayKeys
Expand Down

0 comments on commit 5311358

Please sign in to comment.