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,61 @@
|
|
|
1
|
+
import { VISITOR_KEYS, isFunction, isIdentifier, isStringLiteral } from '@babel/types';
|
|
2
|
+
const decisionNodes = new Set(['IfStatement', 'ConditionalExpression', 'ForStatement', 'ForInStatement', 'ForOfStatement',
|
|
3
|
+
'WhileStatement', 'DoWhileStatement', 'CatchClause', 'LogicalExpression']);
|
|
4
|
+
export function functionFacts(ast) {
|
|
5
|
+
let functions = 0;
|
|
6
|
+
walk(ast, node => { if (isFunction(node) && node.body)
|
|
7
|
+
functions++; });
|
|
8
|
+
const cyclomaticFunctions = [];
|
|
9
|
+
visit(ast, undefined);
|
|
10
|
+
return { functions, cyclomaticFunctions };
|
|
11
|
+
function visit(node, frame) {
|
|
12
|
+
if (isFunction(node) && node.body) {
|
|
13
|
+
const own = { value: 1 };
|
|
14
|
+
// The body defines this method's decision scope. Nested functions get separate frames.
|
|
15
|
+
visit(node.body, own);
|
|
16
|
+
for (const parameter of node.params)
|
|
17
|
+
visit(parameter, undefined);
|
|
18
|
+
const start = node.loc?.start;
|
|
19
|
+
cyclomaticFunctions.push({ line: start?.line,
|
|
20
|
+
column: start === undefined ? undefined : start.column + 1, name: functionName(node), value: own.value });
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (frame && (decisionNodes.has(node.type) || (node.type === 'SwitchCase' && node.test !== null)))
|
|
24
|
+
frame.value++;
|
|
25
|
+
for (const child of children(node))
|
|
26
|
+
visit(child, frame);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function* children(node) {
|
|
30
|
+
const properties = node;
|
|
31
|
+
for (const key of VISITOR_KEYS[node.type] ?? []) {
|
|
32
|
+
const value = properties[key];
|
|
33
|
+
if (Array.isArray(value)) {
|
|
34
|
+
for (const child of value)
|
|
35
|
+
if (child)
|
|
36
|
+
yield child;
|
|
37
|
+
}
|
|
38
|
+
else if (value && 'type' in value) {
|
|
39
|
+
yield value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function walk(node, visit) {
|
|
44
|
+
visit(node);
|
|
45
|
+
for (const child of children(node))
|
|
46
|
+
walk(child, visit);
|
|
47
|
+
}
|
|
48
|
+
export function functionName(node) {
|
|
49
|
+
if ('id' in node && node.id && isIdentifier(node.id))
|
|
50
|
+
return node.id.name;
|
|
51
|
+
if ('key' in node) {
|
|
52
|
+
if (isIdentifier(node.key))
|
|
53
|
+
return node.key.name;
|
|
54
|
+
if (isStringLiteral(node.key))
|
|
55
|
+
return node.key.value;
|
|
56
|
+
if (node.key.type === 'PrivateName')
|
|
57
|
+
return `#${node.key.id.name}`;
|
|
58
|
+
}
|
|
59
|
+
return '(anonymous)';
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=function-facts.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Node } from '@babel/types';
|
|
2
|
+
import type { FunctionComplexity, StructuralObservation } from '../../core/model/code-structure.js';
|
|
3
|
+
export declare function structuralObservations(ast: Node): {
|
|
4
|
+
observations: StructuralObservation[];
|
|
5
|
+
cognitiveFunctions: FunctionComplexity[];
|
|
6
|
+
cognitiveComplexity: number;
|
|
7
|
+
classes: number;
|
|
8
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { isClass, isFunction, isIdentifier, isVariableDeclarator } from '@babel/types';
|
|
2
|
+
import { children, functionName } from './function-facts.js';
|
|
3
|
+
const complexityBlocks = new Set([
|
|
4
|
+
'IfStatement', 'ConditionalExpression', 'ForStatement', 'ForInStatement', 'ForOfStatement',
|
|
5
|
+
'WhileStatement', 'DoWhileStatement', 'CatchClause', 'SwitchStatement',
|
|
6
|
+
]);
|
|
7
|
+
export function structuralObservations(ast) {
|
|
8
|
+
const observations = [];
|
|
9
|
+
const cognitiveFunctions = [];
|
|
10
|
+
let cognitive = 0;
|
|
11
|
+
let classes = 0;
|
|
12
|
+
const topLevel = { cognitive: 0, returns: 0, maxNesting: 0 };
|
|
13
|
+
visit(ast, topLevel, 0);
|
|
14
|
+
if (topLevel.nestedRange !== undefined)
|
|
15
|
+
observe('nested-control-flow', topLevel.maxNesting, 'Module control-flow depth', topLevel.nestedRange);
|
|
16
|
+
cognitive += topLevel.cognitive;
|
|
17
|
+
observe('file-complexity', cognitive, 'File cognitive complexity');
|
|
18
|
+
return { observations, cognitiveFunctions, cognitiveComplexity: cognitive, classes };
|
|
19
|
+
function visit(node, frame, depth, parent) {
|
|
20
|
+
if (isClass(node))
|
|
21
|
+
classes++;
|
|
22
|
+
if (isFunction(node) && node.body) {
|
|
23
|
+
const own = { cognitive: 0, returns: 0, maxNesting: 0 };
|
|
24
|
+
visit(node.body, own, 0, node);
|
|
25
|
+
for (const parameter of node.params)
|
|
26
|
+
visit(parameter, own, 0, node);
|
|
27
|
+
const name = isVariableDeclarator(parent) && isIdentifier(parent.id) ? parent.id.name : functionName(node);
|
|
28
|
+
const start = node.loc?.start;
|
|
29
|
+
cognitiveFunctions.push({ line: start?.line,
|
|
30
|
+
column: start === undefined ? undefined : start.column + 1, name, value: own.cognitive });
|
|
31
|
+
cognitive += own.cognitive;
|
|
32
|
+
observe('function-parameters', node.params.length, `${name} · Parameters`, node);
|
|
33
|
+
observe('return-statements', own.returns, `${name} · Return statements`, node);
|
|
34
|
+
observe('function-complexity', own.cognitive, `${name} · Cognitive complexity`, node);
|
|
35
|
+
if (own.nestedRange !== undefined)
|
|
36
|
+
observe('nested-control-flow', own.maxNesting, `${name} · Control-flow depth`, own.nestedRange);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (node.type === 'ReturnStatement')
|
|
40
|
+
frame.returns++;
|
|
41
|
+
if ((node.type === 'BreakStatement' || node.type === 'ContinueStatement') && node.label)
|
|
42
|
+
frame.cognitive++;
|
|
43
|
+
if (node.type === 'LogicalExpression') {
|
|
44
|
+
if (parent?.type !== 'LogicalExpression' || parent.operator !== node.operator)
|
|
45
|
+
frame.cognitive++;
|
|
46
|
+
if (parent?.type !== 'LogicalExpression')
|
|
47
|
+
observe('boolean-logic', countLogicalOperators(node), 'Logical operators in one expression', node);
|
|
48
|
+
}
|
|
49
|
+
const block = complexityBlocks.has(node.type);
|
|
50
|
+
const chained = node.type === 'IfStatement' && parent?.type === 'IfStatement' && parent.alternate === node;
|
|
51
|
+
if (block) {
|
|
52
|
+
frame.cognitive += chained ? 1 : 1 + depth;
|
|
53
|
+
if (depth + 1 > frame.maxNesting) {
|
|
54
|
+
frame.maxNesting = depth + 1;
|
|
55
|
+
frame.nestedRange = node;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const child of children(node)) {
|
|
59
|
+
if (node.type === 'IfStatement' && child === node.alternate) {
|
|
60
|
+
if (child.type === 'IfStatement')
|
|
61
|
+
visit(child, frame, depth, node);
|
|
62
|
+
else {
|
|
63
|
+
frame.cognitive++;
|
|
64
|
+
visit(child, frame, depth + 1, node);
|
|
65
|
+
}
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
visit(child, frame, depth + Number(block || node.type === 'TryStatement'), node);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function observe(rule, value, label, location) {
|
|
72
|
+
observations.push({ rule, value, label, line: location?.loc?.start.line, endLine: location?.loc?.end.line });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function countLogicalOperators(node) {
|
|
76
|
+
if (node.type !== 'LogicalExpression')
|
|
77
|
+
return 0;
|
|
78
|
+
return 1 + countLogicalOperators(node.left) + countLogicalOperators(node.right);
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=structural-observations.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DataContract, Plugin } from '../../core/engine/plugin.js';
|
|
2
|
+
import type { CloneSource } from '../../core/model/clone-source.js';
|
|
3
|
+
import type { FindingResult } from '../../core/model/finding.js';
|
|
4
|
+
interface FileQuality extends FindingResult {
|
|
5
|
+
readonly cloneSource: CloneSource;
|
|
6
|
+
}
|
|
7
|
+
export declare const fileQuality: DataContract<FileQuality>;
|
|
8
|
+
export declare const maintainability: Plugin;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isRecord, pluginApi } from '../../core/engine/plugin.js';
|
|
2
|
+
import { isCloneSource } from '../../core/model/clone-source.js';
|
|
3
|
+
import { codeStructure } from '../../core/model/code-structure.js';
|
|
4
|
+
import { findingResult } from '../../core/model/finding.js';
|
|
5
|
+
import { definitions } from '../../core/model/measurement.js';
|
|
6
|
+
import { sourceFile } from '../../core/model/snapshot.js';
|
|
7
|
+
import { structuralRules } from '../../core/profile/maintainability.js';
|
|
8
|
+
import { structuralSmells } from './structural-smells.js';
|
|
9
|
+
export const fileQuality = {
|
|
10
|
+
id: 'repometry.maintainability-file/v1',
|
|
11
|
+
accepts: (value) => isRecord(value) && isCloneSource(value.cloneSource) && findingResult.accepts(value),
|
|
12
|
+
};
|
|
13
|
+
export const maintainability = {
|
|
14
|
+
id: 'maintainability', version: '1.0.0', api: pluginApi,
|
|
15
|
+
kinds: ['analysis'],
|
|
16
|
+
produces: [{ contract: fileQuality.id, persistence: 'report', metrics: [
|
|
17
|
+
{ id: definitions.cognitiveComplexity, label: 'Cognitive complexity', unit: 'count', scope: 'file', aggregate: 'sum',
|
|
18
|
+
better: 'lower', group: 'Maintainability' },
|
|
19
|
+
{ id: definitions.classes, label: 'Classes', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Size' },
|
|
20
|
+
{ id: definitions.codeLines, label: 'Lines of code', short: 'Code lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none',
|
|
21
|
+
group: 'Size' },
|
|
22
|
+
{ id: definitions.comments, label: 'Comment lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Size' },
|
|
23
|
+
] }],
|
|
24
|
+
rules: Object.entries(structuralRules).map(([id, { limit, minutesPerExcess }]) => ({ id, category: 'structure', defaults: { limit, cost: minutesPerExcess } })),
|
|
25
|
+
operations: [{
|
|
26
|
+
id: 'file', role: 'inspection', inputs: { syntax: codeStructure, source: sourceFile }, output: fileQuality,
|
|
27
|
+
execute(inputs) {
|
|
28
|
+
const { path, observations, cognitiveFunctions, cognitiveComplexity, classes, commentLines, clones } = inputs.read('syntax', codeStructure);
|
|
29
|
+
return {
|
|
30
|
+
findings: structuralSmells(path, observations),
|
|
31
|
+
measurements: [
|
|
32
|
+
...cognitiveFunctions.map(({ line, column, name, value }) => ({ definition: definitions.cognitiveComplexity, target: 'function', path, line, column, name, value })),
|
|
33
|
+
{ definition: definitions.cognitiveComplexity, target: 'file', path, value: cognitiveComplexity },
|
|
34
|
+
{ definition: definitions.classes, target: 'file', path, value: classes },
|
|
35
|
+
{ definition: definitions.codeLines, target: 'file', path, value: clones.codeLines.length },
|
|
36
|
+
{ definition: definitions.comments, target: 'file', path, value: commentLines },
|
|
37
|
+
],
|
|
38
|
+
cloneSource: clones,
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
}],
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=maintainability.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { structuralRules } from '../../core/profile/maintainability.js';
|
|
2
|
+
export function structuralSmells(path, observations) {
|
|
3
|
+
const findings = [];
|
|
4
|
+
const functionLimit = structuralRules['function-complexity'].limit;
|
|
5
|
+
const functionExcess = observations.reduce((total, { rule, value }) => total + (rule === 'function-complexity' ? Math.max(0, value - functionLimit) : 0), 0);
|
|
6
|
+
for (const { rule, value, label, line, endLine } of observations) {
|
|
7
|
+
const { limit, minutesPerExcess } = structuralRules[rule];
|
|
8
|
+
if (value <= limit)
|
|
9
|
+
continue;
|
|
10
|
+
const chargedExcess = rule === 'file-complexity' ? Math.max(0, value - limit - functionExcess) : value - limit;
|
|
11
|
+
findings.push({ tool: 'repometry', rule, category: 'structure', level: 'medium', path,
|
|
12
|
+
message: `${label} ${value} (limit ${limit})`, line, endLine, effortMinutes: chargedExcess * minutesPerExcess });
|
|
13
|
+
}
|
|
14
|
+
return findings;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=structural-smells.js.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { pluginApi } from '../../core/engine/plugin.js';
|
|
2
|
+
const manifest = {
|
|
3
|
+
api: pluginApi, version: '1.0.0', kinds: ['source'],
|
|
4
|
+
operations: [], produces: [{ contract: 'repometry.source-locator/v1', persistence: 'report' }],
|
|
5
|
+
};
|
|
6
|
+
export const localSource = {
|
|
7
|
+
...manifest, id: 'local',
|
|
8
|
+
locate: () => ({ provider: 'local', url: './sources/{revision}/{path}' }),
|
|
9
|
+
};
|
|
10
|
+
export const githubSource = {
|
|
11
|
+
...manifest, id: 'github',
|
|
12
|
+
locate(context) {
|
|
13
|
+
const project = forgeProject(context, 'github.com', context.env.GITHUB_REPOSITORY, context.env.GITHUB_SERVER_URL, 2);
|
|
14
|
+
if (!project)
|
|
15
|
+
return undefined;
|
|
16
|
+
const { origin, path } = project;
|
|
17
|
+
const url = origin === 'https://github.com' ? `https://raw.githubusercontent.com/${path}/{revision}/{path}`
|
|
18
|
+
: `${origin}/${path}/raw/{revision}/{path}`;
|
|
19
|
+
return { provider: 'github', url, web: `${origin}/${path}/blob/{revision}/{path}#L{line}` };
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export const gitlabSource = {
|
|
23
|
+
...manifest, id: 'gitlab',
|
|
24
|
+
locate(context) {
|
|
25
|
+
const project = forgeProject(context, 'gitlab.com', context.env.CI_PROJECT_PATH, context.env.CI_SERVER_URL);
|
|
26
|
+
if (!project)
|
|
27
|
+
return undefined;
|
|
28
|
+
const { origin, path } = project;
|
|
29
|
+
return { provider: 'gitlab', url: `${origin}/api/v4/projects/${encodeURIComponent(path)}/repository/files/{path:component}/raw?ref={revision}`,
|
|
30
|
+
web: `${origin}/${path}/-/blob/{revision}/{path}#L{line}` };
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
function forgeProject(context, host, ciProject, ciServer, segments) {
|
|
34
|
+
if (context.option !== undefined && context.option !== '') {
|
|
35
|
+
const explicit = remoteProject(context.option) ?? projectAt('https://' + host, context.option);
|
|
36
|
+
return validProject(explicit, segments);
|
|
37
|
+
}
|
|
38
|
+
if (ciProject)
|
|
39
|
+
return validProject(projectAt(ciServer ?? 'https://' + host, ciProject), segments);
|
|
40
|
+
for (const remote of context.remotes) {
|
|
41
|
+
const project = validProject(remoteProject(remote), segments);
|
|
42
|
+
if (project && new URL(project.origin).hostname.toLowerCase() === host)
|
|
43
|
+
return project;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
function validProject(project, segments) {
|
|
48
|
+
if (!project)
|
|
49
|
+
return undefined;
|
|
50
|
+
const parts = project.path.split('/');
|
|
51
|
+
return parts.length >= 2 && (segments === undefined || parts.length === segments) ? project : undefined;
|
|
52
|
+
}
|
|
53
|
+
function projectAt(server, path) {
|
|
54
|
+
try {
|
|
55
|
+
const url = new URL(server);
|
|
56
|
+
if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password)
|
|
57
|
+
return undefined;
|
|
58
|
+
const project = path.replace(/^\/+|\/+$/g, '').replace(/\.git$/, '');
|
|
59
|
+
return project.split('/').every(part => /^[A-Za-z0-9_.-]+$/.test(part) && part !== '.' && part !== '..')
|
|
60
|
+
? { origin: url.origin, path: project } : undefined;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function remoteProject(remote) {
|
|
67
|
+
const scp = /^(?:[^@/]+@)?([a-z\d.-]+):([^/][^?#]*)$/i.exec(remote);
|
|
68
|
+
if (scp)
|
|
69
|
+
return projectAt(`https://${scp[1]}`, scp[2]);
|
|
70
|
+
try {
|
|
71
|
+
const url = new URL(remote);
|
|
72
|
+
if (!['https:', 'http:', 'ssh:'].includes(url.protocol))
|
|
73
|
+
return undefined;
|
|
74
|
+
return projectAt((url.protocol === 'ssh:' ? 'https://' + url.hostname : url.origin), url.pathname);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=forges.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { pluginApi } from '../../core/engine/plugin.js';
|
|
2
|
+
import { codeStructure } from '../../core/model/code-structure.js';
|
|
3
|
+
import { definitions, measurements } from '../../core/model/measurement.js';
|
|
4
|
+
export const structure = {
|
|
5
|
+
id: 'structure',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
api: pluginApi,
|
|
8
|
+
kinds: ['analysis'],
|
|
9
|
+
produces: [{ contract: measurements.id, persistence: 'report', metrics: [
|
|
10
|
+
{ id: definitions.lines, label: 'Physical lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Size' },
|
|
11
|
+
{ id: definitions.functions, label: 'Functions', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Size' },
|
|
12
|
+
{ id: definitions.complexity, label: 'Most complex function', short: 'Peak cyclomatic', unit: 'count', scope: 'file',
|
|
13
|
+
aggregate: 'max', better: 'lower', bands: [5, 10, 20, 50], group: 'Maintainability' },
|
|
14
|
+
] }],
|
|
15
|
+
operations: [{
|
|
16
|
+
id: 'size',
|
|
17
|
+
role: 'inspection',
|
|
18
|
+
inputs: { syntax: codeStructure },
|
|
19
|
+
output: measurements,
|
|
20
|
+
execute(inputs) {
|
|
21
|
+
const { path, lines, functions } = inputs.read('syntax', codeStructure);
|
|
22
|
+
return [
|
|
23
|
+
{ definition: definitions.lines, target: 'file', path, value: lines },
|
|
24
|
+
{ definition: definitions.functions, target: 'file', path, value: functions },
|
|
25
|
+
];
|
|
26
|
+
},
|
|
27
|
+
}, {
|
|
28
|
+
id: 'complexity',
|
|
29
|
+
role: 'inspection',
|
|
30
|
+
inputs: { syntax: codeStructure },
|
|
31
|
+
output: measurements,
|
|
32
|
+
execute(inputs) {
|
|
33
|
+
const { path, cyclomaticFunctions } = inputs.read('syntax', codeStructure);
|
|
34
|
+
return cyclomaticFunctions.map(({ line, column, name, value }) => ({ definition: definitions.complexity, target: 'function', path, line, column, name, value }));
|
|
35
|
+
},
|
|
36
|
+
}],
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=structure.js.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { ProfileBoundary } from '../../json/wire/inspection-context-model.js';
|
|
2
|
+
export interface ChartPoint {
|
|
3
|
+
readonly value: number | null;
|
|
4
|
+
/** Axis label used only when the points have no commit times. */
|
|
5
|
+
readonly label: string;
|
|
6
|
+
/** Accessible name of the point. */
|
|
7
|
+
readonly title: string;
|
|
8
|
+
readonly href: string;
|
|
9
|
+
readonly current: boolean;
|
|
10
|
+
readonly partial: boolean;
|
|
11
|
+
readonly boundary?: ProfileBoundary | null;
|
|
12
|
+
/** Commit time in milliseconds; the x axis is a time scale when every point has one. */
|
|
13
|
+
readonly time: number | null;
|
|
14
|
+
/** Hover card lines: a heading, then details. */
|
|
15
|
+
readonly tip: ChartTip;
|
|
16
|
+
/** A green flag on the best value of the series, a red one at half-mast on the worst. */
|
|
17
|
+
readonly flag?: 'best' | 'worst' | undefined;
|
|
18
|
+
}
|
|
19
|
+
export interface ChartTip {
|
|
20
|
+
readonly heading: string;
|
|
21
|
+
readonly commit: string;
|
|
22
|
+
/** The commit's message, first line: what the chart's step was. */
|
|
23
|
+
readonly subject?: string;
|
|
24
|
+
readonly value: string;
|
|
25
|
+
readonly change?: {
|
|
26
|
+
readonly text: string;
|
|
27
|
+
readonly direction: string;
|
|
28
|
+
} | null;
|
|
29
|
+
readonly notes: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export interface ChartOptions {
|
|
32
|
+
readonly format: (value: number) => string;
|
|
33
|
+
/** Values are ratios within [0, 1]. */
|
|
34
|
+
readonly ratio: boolean;
|
|
35
|
+
readonly compact: boolean;
|
|
36
|
+
/** Ticks fall on whole multiples of this unit, for example 60 to tick minutes in whole hours. */
|
|
37
|
+
readonly tickUnit?: number;
|
|
38
|
+
/** Label the selected point's value; off where the page already shows it next to the chart. */
|
|
39
|
+
readonly labelCurrent?: boolean;
|
|
40
|
+
/** Overall height in pixels, where the layout needs the chart to fill a given space. */
|
|
41
|
+
readonly height?: number | undefined;
|
|
42
|
+
/** A second series drawn as a grey line behind the first, on its own scale labelled at the right edge. */
|
|
43
|
+
readonly secondary?: SecondarySeries | undefined;
|
|
44
|
+
}
|
|
45
|
+
export interface SecondarySeries {
|
|
46
|
+
/** One value per point, in the same order. */
|
|
47
|
+
readonly values: readonly (number | null)[];
|
|
48
|
+
readonly format: (value: number) => string;
|
|
49
|
+
/** Ticks fall on whole multiples of this unit, as for the main series. */
|
|
50
|
+
readonly tickUnit?: number;
|
|
51
|
+
}
|
|
52
|
+
export declare function renderLineChart(container: HTMLElement, points: readonly ChartPoint[], options: ChartOptions): void;
|
|
53
|
+
export interface BarOptions {
|
|
54
|
+
readonly format: (value: number) => string;
|
|
55
|
+
readonly compact: boolean;
|
|
56
|
+
/** Positive values are bad news (for example, added debt). */
|
|
57
|
+
readonly upIsWorse: boolean;
|
|
58
|
+
/** Round tick values to this unit, as for line charts. */
|
|
59
|
+
readonly tickUnit?: number | undefined;
|
|
60
|
+
}
|
|
61
|
+
/** Diverging bars around zero, one per point; a point without a value gets a mark on the zero line. */
|
|
62
|
+
export declare function renderBarChart(container: HTMLElement, points: readonly ChartPoint[], options: BarOptions): void;
|
|
63
|
+
interface Layout {
|
|
64
|
+
readonly width: number;
|
|
65
|
+
readonly height: number;
|
|
66
|
+
readonly top: number;
|
|
67
|
+
readonly plotHeight: number;
|
|
68
|
+
left: number;
|
|
69
|
+
plotWidth: number;
|
|
70
|
+
/** Horizontal position of each point. */
|
|
71
|
+
xs: number[];
|
|
72
|
+
/** Y of each point's mark, for the hover card. */
|
|
73
|
+
ys: (number | null)[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Labels for ticks in time order. Each names its own unit, and the coarser units join it only where they change:
|
|
77
|
+
* Jul 2023, Nov, Dec, Jan 2024, Feb; 30 Jun, 1 Jul, 2; 23:00, 1 Jul, 01:00. The first tick always carries them.
|
|
78
|
+
*/
|
|
79
|
+
export declare function tickLabels(times: readonly number[], unit: TickUnit): string[];
|
|
80
|
+
/**
|
|
81
|
+
* The labels under the ticks. Which ticks keep a label is settled first: one that would sit far off its tick at the
|
|
82
|
+
* edge, or touch the label before it, keeps only its mark. Only then are the labels written, so the first label shown
|
|
83
|
+
* carries the coarser units, and every later one carries them only where they change.
|
|
84
|
+
*/
|
|
85
|
+
export declare function axisLabels(ticks: readonly {
|
|
86
|
+
time: number;
|
|
87
|
+
x: number;
|
|
88
|
+
}[], unit: TickUnit, layout: Layout): {
|
|
89
|
+
at: number;
|
|
90
|
+
label: string;
|
|
91
|
+
}[];
|
|
92
|
+
interface TimeTick {
|
|
93
|
+
readonly time: number;
|
|
94
|
+
readonly label: string;
|
|
95
|
+
readonly unit: TickUnit;
|
|
96
|
+
}
|
|
97
|
+
export type TickUnit = 'minute' | 'hour' | 'day' | 'month' | 'year';
|
|
98
|
+
/** Calendar-aligned ticks between two times, as many as fit the width without overlapping labels. */
|
|
99
|
+
export declare function timeTicks(start: number, end: number, width: number): TimeTick[];
|
|
100
|
+
export declare function niceTicks(values: readonly number[], ratio: boolean, count: number): number[];
|
|
101
|
+
export {};
|