repometry 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +28 -2
- package/package.json +64 -4
- package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
- package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
- package/target/main/resources/report/json/config-v1.schema.json +33 -0
- package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
- package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
- package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
- package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
- package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
- package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
- package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
- package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
- package/target/main/resources/report/json/report-v1.schema.json +65 -0
- package/target/main/resources/report/json/report-v2.schema.json +252 -0
- package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
- package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
- package/target/main/resources/viewer/files.css +578 -0
- package/target/main/resources/viewer/index.html +120 -0
- package/target/main/resources/viewer/projects.html +52 -0
- package/target/main/resources/viewer/styles.css +560 -0
- package/target/main/resources/viewer/viewer-pulls.css +64 -0
- package/target/main/ts/api/gh/github.d.ts +6 -0
- package/target/main/ts/api/gh/github.js +92 -0
- package/target/main/ts/api/git/blob-batch.d.ts +10 -0
- package/target/main/ts/api/git/blob-batch.js +106 -0
- package/target/main/ts/api/git/changes.d.ts +22 -0
- package/target/main/ts/api/git/changes.js +108 -0
- package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
- package/target/main/ts/api/git/commit-metadata.js +53 -0
- package/target/main/ts/api/git/git-churn.d.ts +9 -0
- package/target/main/ts/api/git/git-churn.js +71 -0
- package/target/main/ts/api/git/git-reader.d.ts +16 -0
- package/target/main/ts/api/git/git-reader.js +74 -0
- package/target/main/ts/api/git/git.d.ts +21 -0
- package/target/main/ts/api/git/git.js +153 -0
- package/target/main/ts/api/git/inspection-source.d.ts +15 -0
- package/target/main/ts/api/git/inspection-source.js +31 -0
- package/target/main/ts/api/git/local-sources.d.ts +5 -0
- package/target/main/ts/api/git/local-sources.js +47 -0
- package/target/main/ts/api/git/local.d.ts +3 -0
- package/target/main/ts/api/git/local.js +36 -0
- package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
- package/target/main/ts/api/git/metabranch-worktree.js +35 -0
- package/target/main/ts/api/git/source-cache.d.ts +3 -0
- package/target/main/ts/api/git/source-cache.js +57 -0
- package/target/main/ts/api/import/finding-import.d.ts +9 -0
- package/target/main/ts/api/import/finding-import.js +227 -0
- package/target/main/ts/api/import/lcov-files.d.ts +5 -0
- package/target/main/ts/api/import/lcov-files.js +14 -0
- package/target/main/ts/api/import/profile-file.d.ts +4 -0
- package/target/main/ts/api/import/profile-file.js +17 -0
- package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
- package/target/main/ts/api/worker/remote-executor.js +46 -0
- package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
- package/target/main/ts/api/worker/worker-protocol.js +102 -0
- package/target/main/ts/api/worker/worker.d.ts +5 -0
- package/target/main/ts/api/worker/worker.js +86 -0
- package/target/main/ts/cli/arguments.d.ts +28 -0
- package/target/main/ts/cli/arguments.js +111 -0
- package/target/main/ts/cli/config.d.ts +13 -0
- package/target/main/ts/cli/config.js +58 -0
- package/target/main/ts/cli/imports.d.ts +7 -0
- package/target/main/ts/cli/imports.js +30 -0
- package/target/main/ts/cli/main.d.ts +2 -0
- package/target/main/ts/cli/main.js +379 -0
- package/target/main/ts/cli/reporting.d.ts +18 -0
- package/target/main/ts/cli/reporting.js +104 -0
- package/target/main/ts/cli/revisions.d.ts +6 -0
- package/target/main/ts/cli/revisions.js +16 -0
- package/target/main/ts/cli/store.d.ts +13 -0
- package/target/main/ts/cli/store.js +39 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
- package/target/main/ts/compose/analyze-snapshot.js +164 -0
- package/target/main/ts/compose/attach-churn.d.ts +2 -0
- package/target/main/ts/compose/attach-churn.js +50 -0
- package/target/main/ts/compose/diff-coverage.d.ts +20 -0
- package/target/main/ts/compose/diff-coverage.js +57 -0
- package/target/main/ts/compose/inspect.d.ts +23 -0
- package/target/main/ts/compose/inspect.js +45 -0
- package/target/main/ts/compose/plugin-list.d.ts +6 -0
- package/target/main/ts/compose/plugin-list.js +10 -0
- package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
- package/target/main/ts/compose/prepare-metabranch.js +17 -0
- package/target/main/ts/compose/review.d.ts +16 -0
- package/target/main/ts/compose/review.js +39 -0
- package/target/main/ts/compose/sources.d.ts +3 -0
- package/target/main/ts/compose/sources.js +30 -0
- package/target/main/ts/core/engine/execute.d.ts +10 -0
- package/target/main/ts/core/engine/execute.js +50 -0
- package/target/main/ts/core/engine/manifest.d.ts +4 -0
- package/target/main/ts/core/engine/manifest.js +105 -0
- package/target/main/ts/core/engine/plan.d.ts +22 -0
- package/target/main/ts/core/engine/plan.js +107 -0
- package/target/main/ts/core/engine/plugin.d.ts +59 -0
- package/target/main/ts/core/engine/plugin.js +4 -0
- package/target/main/ts/core/engine/report-products.d.ts +16 -0
- package/target/main/ts/core/engine/report-products.js +86 -0
- package/target/main/ts/core/model/changes.d.ts +8 -0
- package/target/main/ts/core/model/changes.js +2 -0
- package/target/main/ts/core/model/churn.d.ts +11 -0
- package/target/main/ts/core/model/churn.js +5 -0
- package/target/main/ts/core/model/clone-source.d.ts +16 -0
- package/target/main/ts/core/model/clone-source.js +15 -0
- package/target/main/ts/core/model/code-structure.d.ts +30 -0
- package/target/main/ts/core/model/code-structure.js +32 -0
- package/target/main/ts/core/model/comparison.d.ts +24 -0
- package/target/main/ts/core/model/comparison.js +1 -0
- package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
- package/target/main/ts/core/model/diff-coverage.js +1 -0
- package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
- package/target/main/ts/core/model/finding-ignore.js +36 -0
- package/target/main/ts/core/model/finding.d.ts +28 -0
- package/target/main/ts/core/model/finding.js +29 -0
- package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
- package/target/main/ts/core/model/ignore-rule.js +1 -0
- package/target/main/ts/core/model/measurement.d.ts +33 -0
- package/target/main/ts/core/model/measurement.js +30 -0
- package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
- package/target/main/ts/core/model/metric-descriptor.js +1 -0
- package/target/main/ts/core/model/plugin-data.d.ts +25 -0
- package/target/main/ts/core/model/plugin-data.js +1 -0
- package/target/main/ts/core/model/pull-review.d.ts +48 -0
- package/target/main/ts/core/model/pull-review.js +1 -0
- package/target/main/ts/core/model/quality-summary.d.ts +42 -0
- package/target/main/ts/core/model/quality-summary.js +64 -0
- package/target/main/ts/core/model/report.d.ts +40 -0
- package/target/main/ts/core/model/report.js +5 -0
- package/target/main/ts/core/model/scanner-import.d.ts +39 -0
- package/target/main/ts/core/model/scanner-import.js +29 -0
- package/target/main/ts/core/model/snapshot.d.ts +15 -0
- package/target/main/ts/core/model/snapshot.js +51 -0
- package/target/main/ts/core/model/source-locator.d.ts +7 -0
- package/target/main/ts/core/model/source-locator.js +1 -0
- package/target/main/ts/core/model/source.d.ts +23 -0
- package/target/main/ts/core/model/source.js +1 -0
- package/target/main/ts/core/ports/report.d.ts +9 -0
- package/target/main/ts/core/ports/report.js +2 -0
- package/target/main/ts/core/ports/source-provider.d.ts +14 -0
- package/target/main/ts/core/ports/source-provider.js +5 -0
- package/target/main/ts/core/profile/exclusions.d.ts +11 -0
- package/target/main/ts/core/profile/exclusions.js +58 -0
- package/target/main/ts/core/profile/maintainability.d.ts +31 -0
- package/target/main/ts/core/profile/maintainability.js +10 -0
- package/target/main/ts/core/profile/profile.d.ts +4 -0
- package/target/main/ts/core/profile/profile.js +11 -0
- package/target/main/ts/core/usecases/compare.d.ts +6 -0
- package/target/main/ts/core/usecases/compare.js +146 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.js +11 -0
- package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
- package/target/main/ts/core/usecases/diff-coverage.js +16 -0
- package/target/main/ts/core/usecases/inspect.d.ts +38 -0
- package/target/main/ts/core/usecases/inspect.js +42 -0
- package/target/main/ts/core/usecases/review.d.ts +31 -0
- package/target/main/ts/core/usecases/review.js +129 -0
- package/target/main/ts/index.d.ts +35 -0
- package/target/main/ts/index.js +18 -0
- package/target/main/ts/plugin.d.ts +14 -0
- package/target/main/ts/plugin.js +6 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +25 -0
- package/target/main/ts/plugins/coverage/coverage.js +199 -0
- package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
- package/target/main/ts/plugins/coverage/diff-coverage.js +90 -0
- package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
- package/target/main/ts/plugins/duplication/duplication.js +94 -0
- package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
- package/target/main/ts/plugins/language-js/babel-provider.js +47 -0
- package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
- package/target/main/ts/plugins/language-js/clone-candidates.js +65 -0
- package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
- package/target/main/ts/plugins/language-js/code-lines.js +36 -0
- package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
- package/target/main/ts/plugins/language-js/function-facts.js +61 -0
- package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
- package/target/main/ts/plugins/language-js/structural-observations.js +80 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
- package/target/main/ts/plugins/maintainability/maintainability.js +43 -0
- package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
- package/target/main/ts/plugins/maintainability/structural-smells.js +16 -0
- package/target/main/ts/plugins/source/forges.d.ts +4 -0
- package/target/main/ts/plugins/source/forges.js +80 -0
- package/target/main/ts/plugins/structure/structure.d.ts +2 -0
- package/target/main/ts/plugins/structure/structure.js +38 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
- package/target/main/ts/report/html/app/viewer-chart.js +711 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
- package/target/main/ts/report/html/app/viewer-commits.js +280 -0
- package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-data.js +105 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
- package/target/main/ts/report/html/app/viewer-files.js +2104 -0
- package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
- package/target/main/ts/report/html/app/viewer-filter.js +492 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +70 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.js +224 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
- package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-profile.js +401 -0
- package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer-projects.js +90 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
- package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
- package/target/main/ts/report/html/app/viewer-source.js +313 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +73 -0
- package/target/main/ts/report/html/app/viewer-trends.js +423 -0
- package/target/main/ts/report/html/app/viewer.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer.js +735 -0
- package/target/main/ts/report/html/site/badges.d.ts +14 -0
- package/target/main/ts/report/html/site/badges.js +40 -0
- package/target/main/ts/report/html/site/export-site.d.ts +22 -0
- package/target/main/ts/report/html/site/export-site.js +150 -0
- package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
- package/target/main/ts/report/html/site/exported-server.js +71 -0
- package/target/main/ts/report/html/site/local-server.d.ts +7 -0
- package/target/main/ts/report/html/site/local-server.js +65 -0
- package/target/main/ts/report/html/site/projects.d.ts +3 -0
- package/target/main/ts/report/html/site/projects.js +80 -0
- package/target/main/ts/report/html/site/server.d.ts +4 -0
- package/target/main/ts/report/html/site/server.js +65 -0
- package/target/main/ts/report/html/site/source-route.d.ts +6 -0
- package/target/main/ts/report/html/site/source-route.js +23 -0
- package/target/main/ts/report/json/projections/commit-summary.d.ts +12 -0
- package/target/main/ts/report/json/projections/commit-summary.js +124 -0
- package/target/main/ts/report/json/projections/components.d.ts +4 -0
- package/target/main/ts/report/json/projections/components.js +30 -0
- package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
- package/target/main/ts/report/json/projections/file-metrics.js +244 -0
- package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
- package/target/main/ts/report/json/projections/inspection-context.js +93 -0
- package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
- package/target/main/ts/report/json/projections/inspection-details.js +70 -0
- package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
- package/target/main/ts/report/json/projections/metric-values.js +58 -0
- package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
- package/target/main/ts/report/json/projections/public-history.js +17 -0
- package/target/main/ts/report/json/store/components.d.ts +2 -0
- package/target/main/ts/report/json/store/components.js +32 -0
- package/target/main/ts/report/json/store/local-store.d.ts +13 -0
- package/target/main/ts/report/json/store/local-store.js +180 -0
- package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
- package/target/main/ts/report/json/store/pull-review-store.js +52 -0
- package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
- package/target/main/ts/report/json/validation/metabranch.js +8 -0
- package/target/main/ts/report/json/validation/report.d.ts +15 -0
- package/target/main/ts/report/json/validation/report.js +65 -0
- package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
- package/target/main/ts/report/json/validation/summary-validation.js +28 -0
- package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
- package/target/main/ts/report/json/wire/compact-json.js +76 -0
- package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
- package/target/main/ts/report/json/wire/component-model.js +1 -0
- package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
- package/target/main/ts/report/json/wire/domain-types.js +1 -0
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
- package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
- package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
- package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
- package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/project-model.js +1 -0
- package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
- package/target/main/ts/report/json/wire/public-history-model.js +6 -0
- package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
- package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
- package/target/main/ts/report/json/wire/summary-model.js +1 -0
- package/target/main/ts/report.d.ts +11 -0
- package/target/main/ts/report.js +6 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { MetricDescriptor, MetricValues } from '../../json/wire/summary-model.js';
|
|
2
|
+
export type { MetricDescriptor, MetricValues } from '../../json/wire/summary-model.js';
|
|
3
|
+
export type Direction = 'better' | 'worse' | 'same' | 'neutral';
|
|
4
|
+
export interface MetricSpec {
|
|
5
|
+
readonly descriptor: MetricDescriptor;
|
|
6
|
+
/** The word the query field takes and the Trends view id: `todo-count`. */
|
|
7
|
+
readonly key: string;
|
|
8
|
+
readonly plugin: string;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
/** The column header. */
|
|
11
|
+
readonly short: string;
|
|
12
|
+
readonly group: string;
|
|
13
|
+
/** A Metrics column shown before the reader picks columns. */
|
|
14
|
+
readonly column: boolean;
|
|
15
|
+
/** Offered in the Hotspots metric menu. */
|
|
16
|
+
readonly hotspot: boolean;
|
|
17
|
+
/** Has one value per commit, so a trend chart. */
|
|
18
|
+
readonly trend: boolean;
|
|
19
|
+
/** A count another metric's ratio is made of, as covered branches are of branch coverage. */
|
|
20
|
+
readonly ratioPart: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** A row that may carry values: a commit, a file or a folder. */
|
|
23
|
+
export interface Valued {
|
|
24
|
+
readonly values?: MetricValues | undefined;
|
|
25
|
+
readonly analysed?: boolean | undefined;
|
|
26
|
+
}
|
|
27
|
+
/** Curated groups first, in this order; groups named by plugins follow in catalog order. */
|
|
28
|
+
export declare const curatedGroups: readonly ['Maintainability', 'Coverage', 'Security', 'Size'];
|
|
29
|
+
/** The metrics the viewer draws from their typed fields; a Repometry metric it has no code for goes by its descriptor. */
|
|
30
|
+
export declare function isBuiltin(descriptor: MetricDescriptor): boolean;
|
|
31
|
+
/** One spec per descriptor, in catalog order; descriptors listed twice by id count once. */
|
|
32
|
+
export declare function metricSpecs(catalog: readonly MetricDescriptor[]): MetricSpec[];
|
|
33
|
+
/** Positions of a catalog's metrics by id: summary indexes for commits, the detail's own indexes for files. */
|
|
34
|
+
export declare function catalogIndex(catalog: readonly MetricDescriptor[] | undefined): Map<string, number>;
|
|
35
|
+
/** Specs by key, for the query field and the Trends views. Where versions share a key, the one the index holds wins. */
|
|
36
|
+
export declare function byKey(specs: readonly MetricSpec[], index?: ReadonlyMap<string, number>): Map<string, MetricSpec>;
|
|
37
|
+
/** The Trends groups: the curated ones in their order, then each plugin's, with the specs that have a trend. */
|
|
38
|
+
export declare function trendGroups(specs: readonly MetricSpec[]): [string, MetricSpec[]][];
|
|
39
|
+
/**
|
|
40
|
+
* The repository's value at a commit. A commit lists every metric it measured, null where nothing rolls up; a metric
|
|
41
|
+
* it does not list did not run, and has no value, so a chart breaks its line instead of dropping to zero.
|
|
42
|
+
*/
|
|
43
|
+
export declare function commitValue(index: ReadonlyMap<string, number>, commit: Valued, spec: MetricSpec): number | null;
|
|
44
|
+
/**
|
|
45
|
+
* A file's or folder's value against the detail's own catalog. None for a file no plugin analysed, nor for a metric
|
|
46
|
+
* this inspection did not run. Within a measured metric a missing value is zero: zeros are left out of the data.
|
|
47
|
+
*/
|
|
48
|
+
export declare function entryValue(index: ReadonlyMap<string, number>, entry: Valued, spec: MetricSpec): number | null;
|
|
49
|
+
/** The values of a group of files the viewer gathers itself (a filtered folder, a component), by each metric's roll-up. */
|
|
50
|
+
export declare function rollUp(catalog: readonly MetricDescriptor[] | undefined, entries: readonly Valued[]): MetricValues | undefined;
|
|
51
|
+
export declare function duration(minutes: number): string;
|
|
52
|
+
export declare function format(spec: MetricSpec, value: number | null): string;
|
|
53
|
+
/** The signed change between two values: percentage points for a ratio, coloured only where the metric has a better. */
|
|
54
|
+
export declare function difference(spec: MetricSpec, value: number, before: number): {
|
|
55
|
+
text: string;
|
|
56
|
+
direction: Direction;
|
|
57
|
+
};
|
|
58
|
+
/** The first click on a column sorts worst first. */
|
|
59
|
+
export declare function firstSortAscending(spec: MetricSpec): boolean;
|
|
60
|
+
/** Missing values sort last in both directions. */
|
|
61
|
+
export declare function compareValues(ascending: boolean): (a: number | null, b: number | null) => number;
|
|
62
|
+
/** The colour scale: heat where the metric has a better, so the worst is always red; neutral greys where it has none. */
|
|
63
|
+
export declare function bandScale(spec: MetricSpec): 'heat' | 'neutral';
|
|
64
|
+
/**
|
|
65
|
+
* One of five bands, 0 best to 4 worst. Fixed by the descriptor's limits where it has them; otherwise relative to the
|
|
66
|
+
* highest value shown. A metric where higher is better turns the scale round.
|
|
67
|
+
*/
|
|
68
|
+
export declare function bandOf(spec: MetricSpec, value: number, highest: number): number;
|
|
69
|
+
/** The legend's words, best band first; null where the bands are relative and the legend reads Lower … Higher. */
|
|
70
|
+
export declare function bandLabels(spec: MetricSpec): string[] | null;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/** Repometry's metrics keep short query words; every other key comes from the descriptor's id. */
|
|
2
|
+
const builtinKeys = {
|
|
3
|
+
'repometry.cyclomatic-babel/v1': 'complexity',
|
|
4
|
+
'repometry.cognitive-babel/v1': 'cognitive',
|
|
5
|
+
'repometry.code-lines-babel/v1': 'lines',
|
|
6
|
+
'repometry.functions/v1': 'functions',
|
|
7
|
+
'repometry.lcov-line-coverage/v1': 'coverage',
|
|
8
|
+
'repometry.duplicated-lines-babel/v1': 'duplication',
|
|
9
|
+
'repometry.git-change-frequency/v1': 'changes',
|
|
10
|
+
'repometry.lcov-branch-coverage/v1': 'branch-coverage',
|
|
11
|
+
'repometry.lcov-covered-branches/v1': 'covered-branches',
|
|
12
|
+
'repometry.lcov-coverable-branches/v1': 'coverable-branches',
|
|
13
|
+
'repometry.lcov-function-coverage/v1': 'function-coverage',
|
|
14
|
+
'repometry.lcov-covered-functions/v1': 'covered-functions',
|
|
15
|
+
'repometry.lcov-coverable-functions/v1': 'coverable-functions',
|
|
16
|
+
};
|
|
17
|
+
/** The Repometry metrics the viewer draws from typed fields, with their own labels, columns and charts. */
|
|
18
|
+
const handDrawn = new Set([
|
|
19
|
+
'repometry.physical-lines/v1', 'repometry.functions/v1', 'repometry.cyclomatic-babel/v1', 'repometry.cognitive-babel/v1',
|
|
20
|
+
'repometry.classes-babel/v1', 'repometry.code-lines-babel/v1', 'repometry.comment-lines-babel/v1',
|
|
21
|
+
'repometry.duplicated-lines-babel/v1', 'repometry.lcov-line-coverage/v1', 'repometry.lcov-covered-lines/v1',
|
|
22
|
+
'repometry.lcov-coverable-lines/v1', 'repometry.git-change-frequency/v1',
|
|
23
|
+
]);
|
|
24
|
+
/** Words that already mean something: query keys, Trends views and the series the viewer draws by hand. */
|
|
25
|
+
const reserved = new Set(['lang', 'language', 'component', 'path', 'in', 'has', 'analysed', 'ignored', 'lockfile', 'lockfiles', 'remediation', 'missedlines', 'churn',
|
|
26
|
+
'debt', 'debt-changes', 'diff-coverage', 'effort', 'smells', 'files', 'classes', 'comments', 'code-lines', 'security',
|
|
27
|
+
'coverable-lines', 'covered-lines', 'uncovered-lines', 'security-high', 'security-medium', 'security-low',
|
|
28
|
+
...Object.values(builtinKeys)]);
|
|
29
|
+
/** Curated groups first, in this order; groups named by plugins follow in catalog order. */
|
|
30
|
+
export const curatedGroups = ['Maintainability', 'Coverage', 'Security', 'Size'];
|
|
31
|
+
/** The metrics the viewer draws from their typed fields; a Repometry metric it has no code for goes by its descriptor. */
|
|
32
|
+
export function isBuiltin(descriptor) {
|
|
33
|
+
return handDrawn.has(descriptor.id);
|
|
34
|
+
}
|
|
35
|
+
function parts(id) {
|
|
36
|
+
const bare = id.replace(/\/v\d+$/, '');
|
|
37
|
+
const dot = bare.indexOf('.');
|
|
38
|
+
return dot < 0 ? { plugin: bare, name: bare } : { plugin: bare.slice(0, dot), name: bare.slice(dot + 1) };
|
|
39
|
+
}
|
|
40
|
+
/** One spec per descriptor, in catalog order; descriptors listed twice by id count once. */
|
|
41
|
+
export function metricSpecs(catalog) {
|
|
42
|
+
const unique = [...new Map(catalog.map(descriptor => [descriptor.id, descriptor])).values()];
|
|
43
|
+
// Two versions of one metric share a key: a commit measures one of them. Two plugins naming the same metric do not.
|
|
44
|
+
const owners = new Map();
|
|
45
|
+
for (const { id } of unique) {
|
|
46
|
+
const { plugin, name } = parts(id);
|
|
47
|
+
owners.set(name, (owners.get(name) ?? new Set()).add(plugin));
|
|
48
|
+
}
|
|
49
|
+
// The counts a ratio is made of (covered and measured branches) read through the ratio: no chart, column or rank of their own.
|
|
50
|
+
const ratioParts = new Set(unique.flatMap(({ ratio }) => ratio ? [ratio.of, ratio.over] : []));
|
|
51
|
+
return unique.map(descriptor => {
|
|
52
|
+
const { plugin, name } = parts(descriptor.id);
|
|
53
|
+
const builtin = builtinKeys[descriptor.id];
|
|
54
|
+
const key = builtin ?? (owners.get(name).size > 1 || reserved.has(name.toLowerCase()) ? `${plugin}.${name}` : name);
|
|
55
|
+
const rolls = descriptor.aggregate !== 'none' || descriptor.ratio !== undefined;
|
|
56
|
+
const ranked = descriptor.scope === 'file' && descriptor.better !== 'none' && !ratioParts.has(descriptor.id);
|
|
57
|
+
return {
|
|
58
|
+
descriptor, key, plugin,
|
|
59
|
+
label: descriptor.label,
|
|
60
|
+
short: descriptor.short ?? descriptor.label,
|
|
61
|
+
group: descriptor.group ?? plugin,
|
|
62
|
+
// Repometry's own columns are curated; its metrics without a hand-made column are there to pick, not shown first.
|
|
63
|
+
column: ranked && plugin !== 'repometry',
|
|
64
|
+
hotspot: ranked && rolls,
|
|
65
|
+
trend: !ratioParts.has(descriptor.id) && (descriptor.scope === 'repository' || rolls),
|
|
66
|
+
ratioPart: ratioParts.has(descriptor.id),
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** Positions of a catalog's metrics by id: summary indexes for commits, the detail's own indexes for files. */
|
|
71
|
+
export function catalogIndex(catalog) {
|
|
72
|
+
return new Map((catalog ?? []).map((descriptor, index) => [descriptor.id, index]));
|
|
73
|
+
}
|
|
74
|
+
/** Specs by key, for the query field and the Trends views. Where versions share a key, the one the index holds wins. */
|
|
75
|
+
export function byKey(specs, index) {
|
|
76
|
+
const keys = new Map();
|
|
77
|
+
for (const spec of specs) {
|
|
78
|
+
if (!keys.has(spec.key) || index?.has(spec.descriptor.id))
|
|
79
|
+
keys.set(spec.key, spec);
|
|
80
|
+
}
|
|
81
|
+
return keys;
|
|
82
|
+
}
|
|
83
|
+
/** The Trends groups: the curated ones in their order, then each plugin's, with the specs that have a trend. */
|
|
84
|
+
export function trendGroups(specs) {
|
|
85
|
+
const groups = new Map(curatedGroups.map(group => [group, []]));
|
|
86
|
+
for (const spec of specs)
|
|
87
|
+
if (spec.trend)
|
|
88
|
+
groups.set(spec.group, [...groups.get(spec.group) ?? [], spec]);
|
|
89
|
+
return [...groups].filter(([, members]) => members.length > 0);
|
|
90
|
+
}
|
|
91
|
+
/** The id whose presence says a metric was measured: a ratio is measured where its denominator is. */
|
|
92
|
+
function measuredId(spec) {
|
|
93
|
+
return spec.descriptor.ratio?.over ?? spec.descriptor.id;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The repository's value at a commit. A commit lists every metric it measured, null where nothing rolls up; a metric
|
|
97
|
+
* it does not list did not run, and has no value, so a chart breaks its line instead of dropping to zero.
|
|
98
|
+
*/
|
|
99
|
+
export function commitValue(index, commit, spec) {
|
|
100
|
+
const values = commit.values;
|
|
101
|
+
const at = index.get(measuredId(spec));
|
|
102
|
+
if (!values || at === undefined || !(at in values))
|
|
103
|
+
return null;
|
|
104
|
+
const ratio = spec.descriptor.ratio;
|
|
105
|
+
if (!ratio)
|
|
106
|
+
return values[at] ?? null;
|
|
107
|
+
const of = index.get(ratio.of);
|
|
108
|
+
const total = values[at] ?? 0;
|
|
109
|
+
return total > 0 && of !== undefined ? (values[of] ?? 0) / total : null;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A file's or folder's value against the detail's own catalog. None for a file no plugin analysed, nor for a metric
|
|
113
|
+
* this inspection did not run. Within a measured metric a missing value is zero: zeros are left out of the data.
|
|
114
|
+
*/
|
|
115
|
+
export function entryValue(index, entry, spec) {
|
|
116
|
+
if (entry.analysed === false)
|
|
117
|
+
return null;
|
|
118
|
+
const at = index.get(measuredId(spec));
|
|
119
|
+
if (at === undefined)
|
|
120
|
+
return null;
|
|
121
|
+
const ratio = spec.descriptor.ratio;
|
|
122
|
+
if (!ratio)
|
|
123
|
+
return entry.values?.[at] ?? 0;
|
|
124
|
+
const of = index.get(ratio.of);
|
|
125
|
+
const total = entry.values?.[at] ?? 0;
|
|
126
|
+
return total > 0 && of !== undefined ? (entry.values?.[of] ?? 0) / total : null;
|
|
127
|
+
}
|
|
128
|
+
/** The values of a group of files the viewer gathers itself (a filtered folder, a component), by each metric's roll-up. */
|
|
129
|
+
export function rollUp(catalog, entries) {
|
|
130
|
+
if (!catalog?.length)
|
|
131
|
+
return undefined;
|
|
132
|
+
const values = {};
|
|
133
|
+
catalog.forEach((descriptor, index) => {
|
|
134
|
+
if (descriptor.aggregate === 'none')
|
|
135
|
+
return;
|
|
136
|
+
let total = 0;
|
|
137
|
+
for (const entry of entries) {
|
|
138
|
+
if (entry.analysed === false)
|
|
139
|
+
continue;
|
|
140
|
+
const value = entry.values?.[index] ?? 0;
|
|
141
|
+
total = descriptor.aggregate === 'max' ? Math.max(total, value) : total + value;
|
|
142
|
+
}
|
|
143
|
+
if (total !== 0)
|
|
144
|
+
values[index] = total;
|
|
145
|
+
});
|
|
146
|
+
return values;
|
|
147
|
+
}
|
|
148
|
+
const integers = new Intl.NumberFormat();
|
|
149
|
+
const percent = new Intl.NumberFormat(undefined, { style: 'percent', maximumFractionDigits: 1 });
|
|
150
|
+
const decimal = new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 });
|
|
151
|
+
export function duration(minutes) {
|
|
152
|
+
const rounded = Math.round(minutes);
|
|
153
|
+
if (rounded < 60)
|
|
154
|
+
return `${integers.format(rounded)} min`;
|
|
155
|
+
const hours = Math.floor(rounded / 60);
|
|
156
|
+
const rest = rounded % 60;
|
|
157
|
+
return rest ? `${integers.format(hours)} h ${integers.format(rest)} min` : `${integers.format(hours)} h`;
|
|
158
|
+
}
|
|
159
|
+
export function format(spec, value) {
|
|
160
|
+
if (value === null)
|
|
161
|
+
return '—';
|
|
162
|
+
switch (spec.descriptor.unit) {
|
|
163
|
+
case 'ratio': return percent.format(value);
|
|
164
|
+
case 'minutes': return duration(value);
|
|
165
|
+
case 'count': return integers.format(value);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** The signed change between two values: percentage points for a ratio, coloured only where the metric has a better. */
|
|
169
|
+
export function difference(spec, value, before) {
|
|
170
|
+
const { unit, better } = spec.descriptor;
|
|
171
|
+
const raw = unit === 'ratio' ? (value - before) * 100 : value - before;
|
|
172
|
+
const rounded = unit === 'ratio' ? Math.round(raw * 10) / 10 : Math.round(raw);
|
|
173
|
+
if (rounded === 0)
|
|
174
|
+
return { text: 'No change', direction: 'same' };
|
|
175
|
+
const size = Math.abs(rounded);
|
|
176
|
+
const magnitude = unit === 'ratio' ? `${decimal.format(size)} pp` : unit === 'minutes' ? duration(size) : integers.format(size);
|
|
177
|
+
const direction = better === 'none' ? 'neutral' : (better === 'lower') === (rounded < 0) ? 'better' : 'worse';
|
|
178
|
+
return { text: `${rounded > 0 ? '+' : '−'}${magnitude}`, direction };
|
|
179
|
+
}
|
|
180
|
+
/** The first click on a column sorts worst first. */
|
|
181
|
+
export function firstSortAscending(spec) {
|
|
182
|
+
return spec.descriptor.better === 'higher';
|
|
183
|
+
}
|
|
184
|
+
/** Missing values sort last in both directions. */
|
|
185
|
+
export function compareValues(ascending) {
|
|
186
|
+
return (a, b) => a === null ? (b === null ? 0 : 1) : b === null ? -1 : ascending ? a - b : b - a;
|
|
187
|
+
}
|
|
188
|
+
/** The colour scale: heat where the metric has a better, so the worst is always red; neutral greys where it has none. */
|
|
189
|
+
export function bandScale(spec) {
|
|
190
|
+
return spec.descriptor.better === 'none' ? 'neutral' : 'heat';
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* One of five bands, 0 best to 4 worst. Fixed by the descriptor's limits where it has them; otherwise relative to the
|
|
194
|
+
* highest value shown. A metric where higher is better turns the scale round.
|
|
195
|
+
*/
|
|
196
|
+
export function bandOf(spec, value, highest) {
|
|
197
|
+
const limits = spec.descriptor.bands;
|
|
198
|
+
const higher = spec.descriptor.better === 'higher';
|
|
199
|
+
// A limit belongs to the better side: at most 5 is the best complexity band, 90% is already the best coverage band.
|
|
200
|
+
const step = limits ? (() => {
|
|
201
|
+
const index = limits.findIndex(limit => higher ? value < limit : value <= limit);
|
|
202
|
+
return index < 0 ? limits.length : index;
|
|
203
|
+
})() : highest > 0 ? Math.min(4, Math.floor(value / highest * 5)) : 0;
|
|
204
|
+
return higher ? 4 - step : step;
|
|
205
|
+
}
|
|
206
|
+
/** The legend's words, best band first; null where the bands are relative and the legend reads Lower … Higher. */
|
|
207
|
+
export function bandLabels(spec) {
|
|
208
|
+
const limits = spec.descriptor.bands;
|
|
209
|
+
if (!limits)
|
|
210
|
+
return null;
|
|
211
|
+
const unit = spec.descriptor.unit;
|
|
212
|
+
const show = (value) => unit === 'ratio' ? `${+(value * 100).toFixed(1)}%` : unit === 'minutes' ? duration(value) : integers.format(value);
|
|
213
|
+
const bare = (value) => show(value).replace(/%$/, '');
|
|
214
|
+
let ranges;
|
|
215
|
+
if (unit === 'count') {
|
|
216
|
+
ranges = [`≤${show(limits[0])}`, ...limits.slice(1).map((limit, index) => `${show(limits[index] + 1)}–${show(limit)}`),
|
|
217
|
+
`${show(limits[3] + 1)}+`];
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
const join = (low, high) => unit === 'ratio' ? `${bare(low)}–${show(high)}` : `${show(low)}–${show(high)}`;
|
|
221
|
+
ranges = [`<${show(limits[0])}`, ...limits.slice(1).map((limit, index) => join(limits[index], limit)), `${show(limits[3])}+`];
|
|
222
|
+
}
|
|
223
|
+
return spec.descriptor.better === 'higher' ? ranges.reverse() : ranges;
|
|
224
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { InspectionContext } from '../../json/wire/inspection-context-model.js';
|
|
2
|
+
import type { QualitySummary } from '../../json/wire/domain-types.js';
|
|
3
|
+
import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
|
|
4
|
+
import type { MetricDescriptor } from '../../json/wire/summary-model.js';
|
|
5
|
+
import type { MetricSpec } from './viewer-metric-registry.js';
|
|
6
|
+
export type BuiltinMetric = 'coverage' | 'lines' | 'files' | 'functions' | 'complexity' | 'cognitive' | 'duplication' | 'debt' | 'effort' | 'smells' | 'code-lines' | 'classes' | 'comments' | 'security' | 'coverable-lines' | 'covered-lines' | 'uncovered-lines' | 'security-high' | 'security-medium' | 'security-low';
|
|
7
|
+
/** Another plugin's metric, by the key the registry gives it. */
|
|
8
|
+
export type PluginMetric = string & {
|
|
9
|
+
readonly plugin: unique symbol;
|
|
10
|
+
};
|
|
11
|
+
export type Metric = BuiltinMetric | PluginMetric;
|
|
12
|
+
/** One name per metric, for every page: Trends, the Overview figures, the Metrics and Issues summaries and columns. */
|
|
13
|
+
export declare const metricLabels: Record<BuiltinMetric, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Security is graded like the other areas, by the worst finding's risk: none A, low or unclassified B, medium C,
|
|
16
|
+
* high D, critical F. The letter grades the repository; the words name the risk the findings carry, never a level of
|
|
17
|
+
* security ("high risk" is not "high security").
|
|
18
|
+
*/
|
|
19
|
+
export declare const securityGrades: readonly ['A', 'B', 'C', 'D', 'F'];
|
|
20
|
+
export declare const securityRisks: readonly ['No findings', 'Low risk', 'Medium risk', 'High risk', 'Critical risk'];
|
|
21
|
+
export declare const metricDefinitions: Record<BuiltinMetric, string>;
|
|
22
|
+
export declare function useCatalog(catalog: readonly MetricDescriptor[] | undefined): void;
|
|
23
|
+
/** A detail's own catalog may name metrics the history does not, as when its inspection is newer than the summary. */
|
|
24
|
+
export declare function extendCatalog(catalog: readonly MetricDescriptor[] | undefined): void;
|
|
25
|
+
export declare function pluginMetrics(): readonly MetricSpec[];
|
|
26
|
+
export declare function pluginSpec(metric: string): MetricSpec | undefined;
|
|
27
|
+
export declare function isMetric(value: string | null | undefined): value is Metric;
|
|
28
|
+
export declare function labelOf(metric: Metric): string;
|
|
29
|
+
export declare function definitionOf(metric: Metric): string;
|
|
30
|
+
/** Which way is better: the green and red of changes and the flags on a chart follow it. */
|
|
31
|
+
export declare function betterOf(metric: Metric): 'lower' | 'higher' | 'none';
|
|
32
|
+
export declare function metricValue(report: PublicHistoryEntry, metric: Metric, quality: QualitySummary | undefined, context?: InspectionContext): number | null;
|
|
33
|
+
export declare function isPercent(metric: Metric): boolean;
|
|
34
|
+
export declare function formatMetric(value: number, metric: Metric): string;
|
|
35
|
+
/** A size in bytes, in binary units named the way code hosts name them: 512 B, 4.8 KB, 340 KB, 1.2 MB. */
|
|
36
|
+
export declare function size(bytes: number | null | undefined): string;
|
|
37
|
+
export declare function count(value: number | null): string;
|
|
38
|
+
export declare function duration(minutes: number): string;
|
|
39
|
+
export type Direction = 'better' | 'worse' | 'same' | 'neutral';
|
|
40
|
+
/** Signed change between two values of one metric, in percentage points for ratios. */
|
|
41
|
+
export declare function difference(value: number, before: number, metric: Metric): {
|
|
42
|
+
text: string;
|
|
43
|
+
direction: Direction;
|
|
44
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import * as registry from './viewer-metric-registry.js';
|
|
2
|
+
/** One name per metric, for every page: Trends, the Overview figures, the Metrics and Issues summaries and columns. */
|
|
3
|
+
export const metricLabels = {
|
|
4
|
+
coverage: 'Line coverage', lines: 'Physical lines', files: 'Analysed files', functions: 'Functions',
|
|
5
|
+
complexity: 'Peak cyclomatic', cognitive: 'Cognitive complexity', duplication: 'Duplication',
|
|
6
|
+
debt: 'Technical debt ratio', effort: 'Remediation time', smells: 'Code smells', 'code-lines': 'Code lines',
|
|
7
|
+
classes: 'Classes', comments: 'Comment lines', security: 'Security findings',
|
|
8
|
+
'coverable-lines': 'Measured lines', 'covered-lines': 'Covered lines', 'uncovered-lines': 'Uncovered lines',
|
|
9
|
+
'security-high': 'High severity', 'security-medium': 'Medium severity', 'security-low': 'Low severity',
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Security is graded like the other areas, by the worst finding's risk: none A, low or unclassified B, medium C,
|
|
13
|
+
* high D, critical F. The letter grades the repository; the words name the risk the findings carry, never a level of
|
|
14
|
+
* security ("high risk" is not "high security").
|
|
15
|
+
*/
|
|
16
|
+
export const securityGrades = ['A', 'B', 'C', 'D', 'F'];
|
|
17
|
+
export const securityRisks = ['No findings', 'Low risk', 'Medium risk', 'High risk', 'Critical risk'];
|
|
18
|
+
export const metricDefinitions = {
|
|
19
|
+
coverage: 'Share of measured lines executed by tests, read from LCOV.',
|
|
20
|
+
lines: 'All lines in inspected source files, including blanks and comments.',
|
|
21
|
+
files: 'Files in the inspection scope that a plugin analysed.',
|
|
22
|
+
functions: 'Functions and methods found in inspected source files.',
|
|
23
|
+
complexity: 'Highest cyclomatic complexity of any single function.',
|
|
24
|
+
cognitive: 'Sum of cognitive complexity over all functions.',
|
|
25
|
+
duplication: 'Share of code lines that belong to duplicated blocks.',
|
|
26
|
+
debt: 'Estimated time to fix all code smells as a share of the estimated time to write the code (basic COCOMO).',
|
|
27
|
+
effort: 'Estimated time to fix all code smells.',
|
|
28
|
+
smells: 'Structural findings counted toward technical debt.',
|
|
29
|
+
'code-lines': 'Lines of code, excluding blanks and comments.',
|
|
30
|
+
classes: 'Classes found in inspected source files.',
|
|
31
|
+
comments: 'Lines that contain only comments.',
|
|
32
|
+
security: 'Findings from imported security scanners, all severities.',
|
|
33
|
+
'coverable-lines': 'Lines the coverage report measured.',
|
|
34
|
+
'covered-lines': 'Measured lines executed by tests.',
|
|
35
|
+
'uncovered-lines': 'Measured lines no test executed.',
|
|
36
|
+
'security-high': 'High-severity findings from imported security scanners.',
|
|
37
|
+
'security-medium': 'Medium-severity findings from imported security scanners.',
|
|
38
|
+
'security-low': 'Low-severity findings from imported security scanners.',
|
|
39
|
+
};
|
|
40
|
+
/** Metrics where a lower value is better. Coverage is better higher; the rest are neutral. */
|
|
41
|
+
const lowerIsBetter = new Set(['complexity', 'cognitive', 'duplication', 'debt', 'effort', 'smells', 'security',
|
|
42
|
+
'uncovered-lines', 'security-high', 'security-medium', 'security-low']);
|
|
43
|
+
const integers = new Intl.NumberFormat();
|
|
44
|
+
const percent = new Intl.NumberFormat(undefined, { style: 'percent', maximumFractionDigits: 1 });
|
|
45
|
+
const decimal = new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 });
|
|
46
|
+
/**
|
|
47
|
+
* The metrics other plugins declare, from the summary's catalog. Repometry's own metrics keep their typed fields and
|
|
48
|
+
* hand-made surfaces, so a catalog that lists them changes nothing on screen.
|
|
49
|
+
*/
|
|
50
|
+
let plugins = [];
|
|
51
|
+
let pluginKeys = new Map();
|
|
52
|
+
let historyIndex = new Map();
|
|
53
|
+
export function useCatalog(catalog) {
|
|
54
|
+
historyIndex = registry.catalogIndex(catalog);
|
|
55
|
+
plugins = registry.metricSpecs(catalog ?? []).filter(spec => !registry.isBuiltin(spec.descriptor));
|
|
56
|
+
pluginKeys = registry.byKey(plugins);
|
|
57
|
+
}
|
|
58
|
+
/** A detail's own catalog may name metrics the history does not, as when its inspection is newer than the summary. */
|
|
59
|
+
export function extendCatalog(catalog) {
|
|
60
|
+
const known = new Set(plugins.map(spec => spec.descriptor.id));
|
|
61
|
+
const added = (catalog ?? []).filter(descriptor => !registry.isBuiltin(descriptor) && !known.has(descriptor.id));
|
|
62
|
+
if (!added.length)
|
|
63
|
+
return;
|
|
64
|
+
plugins = registry.metricSpecs([...plugins.map(spec => spec.descriptor), ...added]);
|
|
65
|
+
pluginKeys = registry.byKey(plugins);
|
|
66
|
+
}
|
|
67
|
+
export function pluginMetrics() {
|
|
68
|
+
return plugins;
|
|
69
|
+
}
|
|
70
|
+
export function pluginSpec(metric) {
|
|
71
|
+
return metric in metricLabels ? undefined : pluginKeys.get(metric);
|
|
72
|
+
}
|
|
73
|
+
export function isMetric(value) {
|
|
74
|
+
return value != null && (value in metricLabels || pluginKeys.has(value));
|
|
75
|
+
}
|
|
76
|
+
export function labelOf(metric) {
|
|
77
|
+
return pluginSpec(metric)?.label ?? metricLabels[metric];
|
|
78
|
+
}
|
|
79
|
+
export function definitionOf(metric) {
|
|
80
|
+
const spec = pluginSpec(metric);
|
|
81
|
+
return spec ? spec.descriptor.description ?? '' : metricDefinitions[metric];
|
|
82
|
+
}
|
|
83
|
+
/** Which way is better: the green and red of changes and the flags on a chart follow it. */
|
|
84
|
+
export function betterOf(metric) {
|
|
85
|
+
const spec = pluginSpec(metric);
|
|
86
|
+
if (spec)
|
|
87
|
+
return spec.descriptor.better;
|
|
88
|
+
return lowerIsBetter.has(metric) ? 'lower' : metric === 'coverage' ? 'higher' : 'none';
|
|
89
|
+
}
|
|
90
|
+
export function metricValue(report, metric, quality, context) {
|
|
91
|
+
const spec = pluginSpec(metric);
|
|
92
|
+
if (spec)
|
|
93
|
+
return registry.commitValue(historyIndex, report, spec);
|
|
94
|
+
switch (metric) {
|
|
95
|
+
case 'coverage': return report.lineCoverage && report.lineCoverage.total > 0 ? report.lineCoverage.covered / report.lineCoverage.total : null;
|
|
96
|
+
case 'lines': return report.lines;
|
|
97
|
+
case 'files': return report.files;
|
|
98
|
+
case 'functions': return report.functions;
|
|
99
|
+
case 'complexity': return report.maxComplexity;
|
|
100
|
+
case 'cognitive': return quality?.cognitiveComplexity ?? null;
|
|
101
|
+
case 'duplication': return quality?.duplication?.ratio ?? null;
|
|
102
|
+
case 'debt': return quality?.maintainability?.debtRatio ?? null;
|
|
103
|
+
case 'effort': return quality?.maintainability?.effortMinutes ?? null;
|
|
104
|
+
case 'smells': return quality?.maintainability?.smells ?? null;
|
|
105
|
+
case 'code-lines': return quality?.codeLines ?? null;
|
|
106
|
+
case 'classes': return quality?.classes ?? null;
|
|
107
|
+
case 'comments': return quality?.comments ?? null;
|
|
108
|
+
case 'security': return context?.security ? Object.values(context.security).reduce((total, value) => total + value, 0) : null;
|
|
109
|
+
case 'coverable-lines': return report.lineCoverage?.total ?? null;
|
|
110
|
+
case 'covered-lines': return report.lineCoverage?.covered ?? null;
|
|
111
|
+
case 'uncovered-lines': return report.lineCoverage ? report.lineCoverage.total - report.lineCoverage.covered : null;
|
|
112
|
+
case 'security-high': return context?.security?.high ?? null;
|
|
113
|
+
case 'security-medium': return context?.security?.medium ?? null;
|
|
114
|
+
case 'security-low': return context?.security?.low ?? null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export function isPercent(metric) {
|
|
118
|
+
const spec = pluginSpec(metric);
|
|
119
|
+
if (spec)
|
|
120
|
+
return spec.descriptor.unit === 'ratio';
|
|
121
|
+
return metric === 'coverage' || metric === 'duplication' || metric === 'debt';
|
|
122
|
+
}
|
|
123
|
+
export function formatMetric(value, metric) {
|
|
124
|
+
const spec = pluginSpec(metric);
|
|
125
|
+
if (spec)
|
|
126
|
+
return registry.format(spec, value);
|
|
127
|
+
if (isPercent(metric))
|
|
128
|
+
return percent.format(value);
|
|
129
|
+
return metric === 'effort' ? duration(value) : count(value);
|
|
130
|
+
}
|
|
131
|
+
/** A size in bytes, in binary units named the way code hosts name them: 512 B, 4.8 KB, 340 KB, 1.2 MB. */
|
|
132
|
+
export function size(bytes) {
|
|
133
|
+
if (bytes === null || bytes === undefined)
|
|
134
|
+
return '—';
|
|
135
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
136
|
+
let value = bytes;
|
|
137
|
+
let unit = 0;
|
|
138
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
139
|
+
value /= 1024;
|
|
140
|
+
unit++;
|
|
141
|
+
}
|
|
142
|
+
// Below ten of a unit one decimal tells sizes apart; above it, whole units read faster.
|
|
143
|
+
const shown = unit === 0 ? Math.round(value) : value < 10 ? Math.round(value * 10) / 10 : Math.round(value);
|
|
144
|
+
if (shown >= 1024 && unit < units.length - 1)
|
|
145
|
+
return `1 ${units[unit + 1]}`;
|
|
146
|
+
return `${shown.toLocaleString(undefined, { maximumFractionDigits: 1 })} ${units[unit]}`;
|
|
147
|
+
}
|
|
148
|
+
export function count(value) {
|
|
149
|
+
return value === null ? '—' : integers.format(value);
|
|
150
|
+
}
|
|
151
|
+
export function duration(minutes) {
|
|
152
|
+
const rounded = Math.round(minutes);
|
|
153
|
+
if (rounded < 60)
|
|
154
|
+
return `${count(rounded)} min`;
|
|
155
|
+
const hours = Math.floor(rounded / 60);
|
|
156
|
+
const rest = rounded % 60;
|
|
157
|
+
return rest ? `${count(hours)} h ${count(rest)} min` : `${count(hours)} h`;
|
|
158
|
+
}
|
|
159
|
+
/** Signed change between two values of one metric, in percentage points for ratios. */
|
|
160
|
+
export function difference(value, before, metric) {
|
|
161
|
+
const spec = pluginSpec(metric);
|
|
162
|
+
if (spec)
|
|
163
|
+
return registry.difference(spec, value, before);
|
|
164
|
+
const percentPoints = isPercent(metric);
|
|
165
|
+
const raw = percentPoints ? (value - before) * 100 : value - before;
|
|
166
|
+
const rounded = percentPoints ? Math.round(raw * 10) / 10 : Math.round(raw);
|
|
167
|
+
if (rounded === 0)
|
|
168
|
+
return { text: 'No change', direction: 'same' };
|
|
169
|
+
const magnitude = percentPoints ? `${decimal.format(Math.abs(rounded))} pp` : metric === 'effort' ? duration(Math.abs(rounded)) : count(Math.abs(rounded));
|
|
170
|
+
const better = lowerIsBetter.has(metric) ? rounded < 0 : metric === 'coverage' ? rounded > 0 : null;
|
|
171
|
+
return { text: `${rounded > 0 ? '+' : '−'}${magnitude}`, direction: better === null ? 'neutral' : better ? 'better' : 'worse' };
|
|
172
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { InspectionContext } from '../../json/wire/inspection-context-model.js';
|
|
2
|
+
import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
|
|
3
|
+
import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
|
|
4
|
+
import type { QualitySummary } from '../../json/wire/domain-types.js';
|
|
5
|
+
export interface ProfileData {
|
|
6
|
+
readonly report: PublicHistoryEntry;
|
|
7
|
+
readonly context: InspectionContext | undefined;
|
|
8
|
+
/** Present in local and private views: the applied profile travels with them. */
|
|
9
|
+
readonly details: InspectionDetails | undefined;
|
|
10
|
+
/** The newest inspection, which the badges show, with its quality and context. */
|
|
11
|
+
readonly latest: {
|
|
12
|
+
readonly report: PublicHistoryEntry;
|
|
13
|
+
readonly quality: QualitySummary | undefined;
|
|
14
|
+
readonly context: InspectionContext | undefined;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export declare function renderProfile(container: HTMLElement, data: ProfileData): void;
|