diff --git a/README.md b/README.md index c93614b..dbec182 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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: diff --git a/generated/avg-maintainability.svg b/generated/avg-maintainability.svg index 2238685..d9816b0 100644 --- a/generated/avg-maintainability.svg +++ b/generated/avg-maintainability.svg @@ -1,5 +1,5 @@ - - maintainability (avg): 56.28 + + maintainability (avg): 56.25 @@ -13,8 +13,8 @@ \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 8fabab8..a90abd0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) { diff --git a/src/options.ts b/src/options.ts index 9f2d21e..720bb8b 100644 --- a/src/options.ts +++ b/src/options.ts @@ -45,6 +45,11 @@ const baseOptions: CodehawkOptions = { default: 10, replaceDefault: true, }, + cliOutputLimit: { + type: 'number', + default: 25, + replaceDefault: true, + }, } const injectOptionValues = ({ @@ -72,6 +77,7 @@ const injectOptionValues = ({ newOptions[optionKey] = val as string[] break case 'minimumThreshold': + case 'cliOutputLimit': newOptions[optionKey] = parseInt(val, 10) break default: diff --git a/src/types/codehawk.ts b/src/types/codehawk.ts index f922060..d811139 100644 --- a/src/types/codehawk.ts +++ b/src/types/codehawk.ts @@ -7,7 +7,7 @@ type SupportedStringArrayKeys = | 'extensions' | 'skipDirectories' type SupportedBooleanOptions = 'enableFlow' -type SupportedNumberOptions = 'minimumThreshold' +type SupportedNumberOptions = 'minimumThreshold' | 'cliOutputLimit' export type AllOptionKeys = | SupportedStringArrayKeys