repometry 0.6.2 → 0.7.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.
Files changed (91) hide show
  1. package/package.json +1 -1
  2. package/target/main/resources/config/process-plugins-v1.schema.json +75 -0
  3. package/target/main/resources/report/json/report-v2.schema.json +21 -1
  4. package/target/main/resources/report/json/repository-summary-v1.schema.json +9 -0
  5. package/target/main/resources/report/json/viewer-inspection-v1.schema.json +11 -3
  6. package/target/main/resources/viewer/files.css +6 -0
  7. package/target/main/resources/viewer/index.html +1 -1
  8. package/target/main/resources/viewer/styles.css +1 -0
  9. package/target/main/ts/cli/config.d.ts +1 -0
  10. package/target/main/ts/cli/config.js +3 -2
  11. package/target/main/ts/cli/main.js +37 -19
  12. package/target/main/ts/cli/reporting.js +3 -3
  13. package/target/main/ts/compose/analysis-files.d.ts +1 -0
  14. package/target/main/ts/compose/analysis-files.js +27 -7
  15. package/target/main/ts/compose/analysis-imports.js +2 -1
  16. package/target/main/ts/compose/analysis-report.js +7 -3
  17. package/target/main/ts/compose/analysis-results.d.ts +4 -1
  18. package/target/main/ts/compose/analysis-results.js +3 -0
  19. package/target/main/ts/compose/analysis-sources.js +2 -1
  20. package/target/main/ts/compose/languages.js +4 -1
  21. package/target/main/ts/compose/plugin-list.d.ts +11 -2
  22. package/target/main/ts/compose/plugin-list.js +4 -1
  23. package/target/main/ts/compose/process-plugins.d.ts +2 -0
  24. package/target/main/ts/compose/process-plugins.js +63 -0
  25. package/target/main/ts/compose/structure-measures.d.ts +5 -0
  26. package/target/main/ts/compose/structure-measures.js +57 -0
  27. package/target/main/ts/core/engine/manifest.js +5 -1
  28. package/target/main/ts/core/model/clone-source.js +0 -1
  29. package/target/main/ts/core/model/code-structure.d.ts +14 -9
  30. package/target/main/ts/core/model/code-structure.js +23 -10
  31. package/target/main/ts/core/model/language.d.ts +2 -0
  32. package/target/main/ts/core/model/plugin-data.d.ts +2 -0
  33. package/target/main/ts/core/model/quality-summary.d.ts +4 -0
  34. package/target/main/ts/core/model/quality-summary.js +53 -29
  35. package/target/main/ts/core/model/report.d.ts +6 -0
  36. package/target/main/ts/plugin.d.ts +1 -1
  37. package/target/main/ts/plugins/coverage/coverage.d.ts +2 -1
  38. package/target/main/ts/plugins/coverage/coverage.js +40 -30
  39. package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -1
  40. package/target/main/ts/plugins/language-js/function-facts.js +0 -1
  41. package/target/main/ts/plugins/language-js/js-security.js +25 -37
  42. package/target/main/ts/plugins/language-js/structural-observations.js +5 -4
  43. package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -1
  44. package/target/main/ts/plugins/maintainability/maintainability.js +9 -8
  45. package/target/main/ts/plugins/security/dockerfile.js +45 -37
  46. package/target/main/ts/plugins/structure/structure.js +2 -2
  47. package/target/main/ts/report/html/app/viewer-code-map.js +6 -5
  48. package/target/main/ts/report/html/app/viewer-columns.d.ts +2 -0
  49. package/target/main/ts/report/html/app/viewer-columns.js +9 -4
  50. package/target/main/ts/report/html/app/viewer-data.d.ts +2 -1
  51. package/target/main/ts/report/html/app/viewer-data.js +1 -1
  52. package/target/main/ts/report/html/app/viewer-file-aside.d.ts +5 -9
  53. package/target/main/ts/report/html/app/viewer-file-aside.js +18 -8
  54. package/target/main/ts/report/html/app/viewer-file-figures.d.ts +2 -0
  55. package/target/main/ts/report/html/app/viewer-file-figures.js +6 -1
  56. package/target/main/ts/report/html/app/viewer-hotspots.js +7 -5
  57. package/target/main/ts/report/html/app/viewer-inspection.js +1 -1
  58. package/target/main/ts/report/html/app/viewer-issue-group.js +2 -2
  59. package/target/main/ts/report/html/app/viewer-languages.d.ts +3 -2
  60. package/target/main/ts/report/html/app/viewer-languages.js +14 -7
  61. package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +4 -4
  62. package/target/main/ts/report/html/app/viewer-line-coverage.js +11 -24
  63. package/target/main/ts/report/html/app/viewer-map-scale.d.ts +1 -1
  64. package/target/main/ts/report/html/app/viewer-map-scale.js +1 -1
  65. package/target/main/ts/report/html/app/viewer-map-shape.d.ts +2 -2
  66. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -3
  67. package/target/main/ts/report/html/app/viewer-metric-registry.js +0 -9
  68. package/target/main/ts/report/html/app/viewer-metrics-view.js +1 -4
  69. package/target/main/ts/report/html/app/viewer-metrics.d.ts +2 -0
  70. package/target/main/ts/report/html/app/viewer-metrics.js +5 -0
  71. package/target/main/ts/report/html/app/viewer-overview-cards.js +4 -1
  72. package/target/main/ts/report/html/app/viewer-overview-hotspots.js +2 -2
  73. package/target/main/ts/report/html/app/viewer-profile.js +15 -1
  74. package/target/main/ts/report/html/app/viewer-source-view.js +7 -6
  75. package/target/main/ts/report/html/app/viewer-table-cells.js +8 -2
  76. package/target/main/ts/report/html/app/viewer-table-rows.d.ts +2 -0
  77. package/target/main/ts/report/html/app/viewer-table-rows.js +7 -5
  78. package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +2 -5
  79. package/target/main/ts/report/html/app/viewer-tokenizer.js +9 -12
  80. package/target/main/ts/report/html/app/viewer-totals.d.ts +6 -0
  81. package/target/main/ts/report/html/app/viewer-totals.js +11 -0
  82. package/target/main/ts/report/html/app/viewer-trend-data.d.ts +1 -1
  83. package/target/main/ts/report/html/app/viewer-trend-data.js +1 -1
  84. package/target/main/ts/report/html/app/viewer-trend-nav.js +3 -2
  85. package/target/main/ts/report/html/app/viewer.js +1 -7
  86. package/target/main/ts/report/json/projections/commit-summary.js +5 -0
  87. package/target/main/ts/report/json/projections/file-metrics.js +20 -4
  88. package/target/main/ts/report/json/projections/inspection-details.js +32 -14
  89. package/target/main/ts/report/json/projections/metric-values.d.ts +1 -0
  90. package/target/main/ts/report/json/projections/metric-values.js +36 -3
  91. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +8 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repometry",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "Track repository metrics without SaaS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -0,0 +1,75 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "urn:repometry:schema:process-plugins:1",
4
+ "title": "Repometry process plugins",
5
+ "type": "array",
6
+ "items": {
7
+ "type": "object",
8
+ "additionalProperties": false,
9
+ "required": ["id", "version", "image", "command", "scope", "tools", "providesLanguages"],
10
+ "properties": {
11
+ "id": { "$ref": "#/$defs/id" },
12
+ "version": { "$ref": "#/$defs/text" },
13
+ "image": {
14
+ "type": "string",
15
+ "pattern": "^(?:[a-z0-9][a-z0-9.:/_-]*@)?sha256:[a-f0-9]{64}$",
16
+ "description": "The full ID or distribution digest of a locally available Docker image."
17
+ },
18
+ "command": {
19
+ "type": "array",
20
+ "minItems": 1,
21
+ "items": { "type": "string", "pattern": "^[^\\u0000]*$" }
22
+ },
23
+ "scope": { "enum": ["file", "repository"] },
24
+ "claims": {
25
+ "type": "object",
26
+ "additionalProperties": false,
27
+ "properties": {
28
+ "extensions": { "$ref": "#/$defs/extensions" },
29
+ "globs": { "$ref": "#/$defs/globs" }
30
+ }
31
+ },
32
+ "limits": {
33
+ "type": "object",
34
+ "additionalProperties": false,
35
+ "properties": {
36
+ "timeoutMs": { "type": "integer", "minimum": 1, "maximum": 2147483647 },
37
+ "maxOutputBytes": { "$ref": "#/$defs/positiveInteger" },
38
+ "memoryBytes": { "$ref": "#/$defs/positiveInteger" },
39
+ "pidsLimit": { "$ref": "#/$defs/positiveInteger" }
40
+ }
41
+ },
42
+ "tools": { "type": "object", "minProperties": 1, "additionalProperties": { "$ref": "#/$defs/text" } },
43
+ "settings": true,
44
+ "providesLanguages": {
45
+ "type": "array",
46
+ "minItems": 1,
47
+ "items": {
48
+ "type": "object",
49
+ "additionalProperties": false,
50
+ "required": ["id", "label"],
51
+ "properties": {
52
+ "id": { "$ref": "#/$defs/id" },
53
+ "label": { "$ref": "#/$defs/text" },
54
+ "color": { "type": "string", "pattern": "^#[0-9A-Fa-f]{6}$" },
55
+ "extensions": { "$ref": "#/$defs/extensions" },
56
+ "globs": { "$ref": "#/$defs/globs" },
57
+ "measures": {
58
+ "type": "array",
59
+ "uniqueItems": true,
60
+ "items": { "enum": ["functions", "cyclomaticComplexity", "cognitiveComplexity", "classes",
61
+ "commentLines", "codeLines", "duplication", "structuralRules"] }
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }
67
+ },
68
+ "$defs": {
69
+ "id": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
70
+ "text": { "type": "string", "pattern": "\\S" },
71
+ "positiveInteger": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
72
+ "extensions": { "type": "array", "uniqueItems": true, "items": { "type": "string", "pattern": "^\\.[\\w-]+$" } },
73
+ "globs": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/text" } }
74
+ }
75
+ }
@@ -91,6 +91,20 @@
91
91
  "$ref": "#/$defs/finding"
92
92
  }
93
93
  },
94
+ "ruleSkips": {
95
+ "type": "array",
96
+ "items": {
97
+ "type": "object",
98
+ "required": ["path", "plugin", "rules", "reason"],
99
+ "properties": {
100
+ "path": { "type": "string" },
101
+ "plugin": { "type": "string" },
102
+ "rules": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string" } },
103
+ "reason": { "const": "unmeasured" }
104
+ },
105
+ "additionalProperties": false
106
+ }
107
+ },
94
108
  "pluginData": {
95
109
  "type": "object",
96
110
  "required": ["metrics", "measured", "rules", "products"],
@@ -134,7 +148,13 @@
134
148
  "bytes": { "type": "integer", "minimum": 0 },
135
149
  "language": { "type": "string" },
136
150
  "provider": { "type": "string", "minLength": 1 },
137
- "analysed": { "type": "boolean" }
151
+ "analysed": { "type": "boolean" },
152
+ "unmeasured": {
153
+ "type": "array",
154
+ "uniqueItems": true,
155
+ "items": { "enum": ["functions", "cyclomaticComplexity", "cognitiveComplexity", "classes",
156
+ "commentLines", "codeLines", "duplication", "structuralRules"] }
157
+ }
138
158
  },
139
159
  "additionalProperties": false
140
160
  }
@@ -134,6 +134,15 @@
134
134
  "debtRatio": {
135
135
  "$ref": "#/$defs/ratio"
136
136
  },
137
+ "gradeCoverage": {
138
+ "type": "object",
139
+ "required": ["measuredFiles", "totalFiles"],
140
+ "properties": {
141
+ "measuredFiles": { "type": "integer", "minimum": 0 },
142
+ "totalFiles": { "type": "integer", "minimum": 0 }
143
+ },
144
+ "additionalProperties": false
145
+ },
137
146
  "grade": {
138
147
  "enum": [
139
148
  "A",
@@ -129,7 +129,6 @@
129
129
  "additionalProperties": false,
130
130
  "required": [
131
131
  "id",
132
- "extensions",
133
132
  "excludedPaths",
134
133
  "excludedDirectories",
135
134
  "rules",
@@ -146,10 +145,19 @@
146
145
  "null"
147
146
  ]
148
147
  },
149
- "extensions": {
148
+ "languages": {
150
149
  "type": "array",
151
150
  "items": {
152
- "type": "string"
151
+ "type": "object",
152
+ "additionalProperties": false,
153
+ "required": ["plugin", "id", "label", "extensions", "globs"],
154
+ "properties": {
155
+ "plugin": { "type": "string" },
156
+ "id": { "type": "string" },
157
+ "label": { "type": "string" },
158
+ "extensions": { "type": "array", "items": { "type": "string" } },
159
+ "globs": { "type": "array", "items": { "type": "string" } }
160
+ }
153
161
  }
154
162
  },
155
163
  "excludedPaths": {
@@ -553,6 +553,10 @@ code.fx-function-name { font-size: .75rem; color: var(--secondary); }
553
553
  .profile-facts dt { color: var(--secondary); font-size: .875rem; }
554
554
  .profile-facts dd { margin: 0; }
555
555
  .profile-facts code { font-size: .8125rem; }
556
+ /* Each language on its own line: its name, then the patterns of the files its plugin reads. */
557
+ .profile-claims { display: grid; gap: .5rem; margin: 0; padding: 0; list-style: none; }
558
+ .profile-claims > li { display: grid; grid-template-columns: minmax(6rem, auto) minmax(0, 1fr); gap: .75rem; align-items: baseline; }
559
+ .profile-claim { font-size: .875rem; color: var(--ink); }
556
560
  .profile-chips { display: flex; flex-wrap: wrap; gap: .375rem; margin: 0; padding: 0; list-style: none; }
557
561
  .profile-chips li { padding: .0625rem .5rem; border-radius: 5px; background: var(--surface-2); color: var(--ink); font: .8125rem/1.6 var(--mono); overflow-wrap: anywhere; }
558
562
  .profile-rule { font-size: .8125rem; font-weight: 600; }
@@ -607,3 +611,5 @@ code.fx-function-name { font-size: .75rem; color: var(--secondary); }
607
611
  .fx-source-meta .fx-source-forge:hover { color: var(--accent-strong); }
608
612
  .fx-occurrence-away { padding: .375rem 0 0; font-size: .8125rem; }
609
613
  .fx-occurrence-away .fx-source-forge { color: var(--secondary); }
614
+ /* A total over files that do not all carry the measure: the title says in how many it was measured. */
615
+ .fx-table .fx-partial { text-decoration: underline dotted; text-decoration-color: var(--muted); text-underline-offset: 3px; }
@@ -51,7 +51,7 @@
51
51
  <div class="verdicts" role="tablist" aria-label="Quality area">
52
52
  <div class="verdict">
53
53
  <span id="maintainability" class="mark grade"></span>
54
- <span class="verdict-text"><button type="button" role="tab" class="verdict-tab" data-metric="debt" aria-controls="trend" aria-describedby="maintainability maintainability-detail">Maintainability</button><span id="maintainability-detail" class="verdict-detail"></span></span>
54
+ <span class="verdict-text"><button type="button" role="tab" class="verdict-tab" data-metric="debt" aria-controls="trend" aria-describedby="maintainability maintainability-detail maintainability-scope">Maintainability</button><span id="maintainability-detail" class="verdict-detail"></span><span id="maintainability-scope" class="verdict-detail verdict-more" hidden></span></span>
55
55
  </div>
56
56
  <div class="verdict">
57
57
  <span id="coverage-mark" class="mark ring" aria-hidden="true"></span>
@@ -421,6 +421,7 @@ a.tc-tip-entry:hover { background: var(--surface-2); }
421
421
 
422
422
  /* Trends page */
423
423
  .trend-nav { display: grid; gap: 1.125rem; }
424
+ .trend-group-note { margin: -.2rem 0 .3rem; padding: 0 .5rem 0 .75rem; color: var(--muted); font-size: .75rem; }
424
425
  .trend-group h3 { display: flex; align-items: center; justify-content: space-between; gap: .75rem; min-height: 1.5rem; margin: 0 0 .3rem; padding: 0 .5rem 0 .75rem; color: var(--muted); font-size: .75rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; }
425
426
  /* A group's reading: the maintainability grade, or the coverage in its grade's colour, as the badges show them. */
426
427
  .trend-reading { flex: none; min-width: 1.25rem; padding: 0 .4rem; border-radius: 999px; background: var(--rule); color: var(--secondary); font-size: .75rem; font-weight: 600; letter-spacing: 0; line-height: 1.25rem; text-align: center; text-transform: none; font-variant-numeric: tabular-nums; }
@@ -2,6 +2,7 @@ import type { Invocation } from './arguments.js';
2
2
  export declare function readConfig(root: string, input: Invocation): Promise<{
3
3
  exclude: readonly string[];
4
4
  ignore: readonly import("../index.js").FindingIgnoreRule[];
5
+ plugins: readonly import("../core/engine/plugin.js").Plugin[];
5
6
  imports: readonly string[];
6
7
  reports: readonly string[];
7
8
  sources: string | undefined;
@@ -2,15 +2,16 @@ import { readFile } from 'node:fs/promises';
2
2
  import { resolve } from 'node:path';
3
3
  import { isRecord } from '../core/engine/plugin.js';
4
4
  import { normalizeProfile } from '../core/profile/profile.js';
5
+ import { readProcessPlugins } from '../compose/process-plugins.js';
5
6
  import { invocationDirectory } from './store.js';
6
7
  const keys = new Set(['$schema', 'exclude', 'ignore', 'imports', 'reports', 'sources', 'branch',
7
- 'minCoverage', 'minLines', 'maxCoverageDrop', 'maxNewIssues']);
8
+ 'minCoverage', 'minLines', 'maxCoverageDrop', 'maxNewIssues', 'plugins']);
8
9
  function parseConfig(value) {
9
10
  if (!isRecord(value) || Object.keys(value).some(key => !keys.has(key)))
10
11
  throw new Error('Invalid Repometry JSON configuration');
11
12
  string(value.$schema, '$schema');
12
13
  const profile = normalizeProfile({ exclude: value.exclude, ignore: value.ignore });
13
- return { ...profile, imports: list(value.imports, 'imports'), reports: list(value.reports, 'reports'),
14
+ return { ...profile, plugins: readProcessPlugins(value.plugins), imports: list(value.imports, 'imports'), reports: list(value.reports, 'reports'),
14
15
  sources: string(value.sources, 'sources'), branch: string(value.branch, 'branch'),
15
16
  minCoverage: number(value.minCoverage, 'minCoverage'), minLines: number(value.minLines, 'minLines'),
16
17
  maxCoverageDrop: number(value.maxCoverageDrop, 'maxCoverageDrop'), maxNewIssues: number(value.maxNewIssues, 'maxNewIssues') };
@@ -13,7 +13,7 @@ import { analyzeSnapshot, attachFindings, inspect } from '../compose/inspect.js'
13
13
  import { measureDiffCoverage } from '../compose/diff-coverage.js';
14
14
  import { prepareMetabranch } from '../compose/prepare-metabranch.js';
15
15
  import { reviewExitCode, reviewPull } from '../compose/review.js';
16
- import { builtInPlugins } from '../compose/plugin-list.js';
16
+ import { builtInPlugins, describePlugin } from '../compose/plugin-list.js';
17
17
  import { isRecord } from '../core/engine/plugin.js';
18
18
  import { validSubjectId } from '../core/model/report.js';
19
19
  import { sourceExclusionMatcher } from '../core/profile/exclusions.js';
@@ -115,10 +115,14 @@ const commands = {
115
115
  print({ schema: 'urn:repometry:schema:prepare-result:1', subject: report.subject, worktree, files });
116
116
  },
117
117
  },
118
- plugins: { description: 'List plugins and supported formats.', run() {
119
- print({ schema: 'urn:repometry:schema:plugin-list:1', plugins: builtInPlugins, importers: importerIds,
120
- reporters: reporterIds, ci: ['github'], stores: ['local', 'git'] });
121
- } },
118
+ plugins: { description: 'List effective plugins and supported formats.', options: configOptions,
119
+ async run(input) {
120
+ const { root } = await context(input);
121
+ const config = await readConfig(root, input);
122
+ print({ schema: 'urn:repometry:schema:plugin-list:1', plugins: [...builtInPlugins, ...config.plugins.map(describePlugin)],
123
+ importers: importerIds, reporters: reporterIds, ci: ['github'], stores: ['local', 'git'] });
124
+ },
125
+ },
122
126
  cache: {
123
127
  description: 'Find or clear the system cache.', parameters: 'path|clear', min: 1, max: 1,
124
128
  options: { sources: flag('Clear only source blobs.') },
@@ -167,13 +171,13 @@ async function analyze(input) {
167
171
  const importRoot = input.text('import-root');
168
172
  if (importRoot && findings.length === 0)
169
173
  throw new Error('--import-root requires a scanner report');
170
- const worker = input.text('worker');
174
+ const executor = analysisExecutor(input, config.plugins);
171
175
  const savedId = input.flag('skip-saved') ? await resolveGitCommit(root, revision) : undefined;
172
176
  const skipped = savedId !== undefined && await isSaved(output, savedId);
173
177
  const report = skipped ? await store.reader.read({ kind: 'commit', id: savedId })
174
178
  : await inspect({ directory, output, source: input.flag('working-tree') ? { workingTree: true } : { revision },
175
- lcov, exclude: [...config.exclude, ...input.many('exclude')], ignore: config.ignore,
176
- findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }, worker === undefined ? undefined : remoteExecutor(worker, workerToken(), defaultLanguages.isSource));
179
+ lcov, exclude: [...config.exclude, ...input.many('exclude')], ignore: config.ignore, plugins: config.plugins,
180
+ findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }, executor);
177
181
  if (github)
178
182
  await writeGitHubResult(report);
179
183
  const requested = input.many('report');
@@ -199,9 +203,19 @@ async function analyzeRange(input, range) {
199
203
  const { base, head, commits } = await firstParentRange(root, range.base, range.head);
200
204
  if (!commits.length)
201
205
  process.stderr.write(`No commits in ${range.base}..${range.head}.\n`);
202
- const worker = input.text('worker');
203
- const executor = worker === undefined ? undefined : remoteExecutor(worker, workerToken(), defaultLanguages.isSource);
206
+ const executor = analysisExecutor(input, config.plugins);
204
207
  const exclude = [...config.exclude, ...input.many('exclude')];
208
+ const inspectCommit = (id) => inspect({ directory, output, source: { revision: id }, exclude,
209
+ ignore: config.ignore, plugins: config.plugins }, executor);
210
+ const skip = input.flag('skip-saved') ? (id) => isSaved(output, id) : undefined;
211
+ const { interrupted, ...results } = await analyzeCommits(commits, inspectCommit, skip);
212
+ const requested = input.many('report');
213
+ const reports = interrupted ? [] : await outputReports(root, store, requested.length ? requested : config.reports, input, config);
214
+ print({ schema: 'urn:repometry:schema:analyze-range:1', range: `${base}..${head}`,
215
+ ...results, store: output, reports });
216
+ return interrupted ? 130 : results.failed.length || results.partial.length ? 2 : 0;
217
+ }
218
+ async function analyzeCommits(commits, inspectCommit, skip) {
205
219
  const analyzed = [], partial = [], skipped = [];
206
220
  const failed = [];
207
221
  let interrupted = false;
@@ -213,13 +227,13 @@ async function analyzeRange(input, range) {
213
227
  for (const [index, id] of commits.entries()) {
214
228
  if (interrupted)
215
229
  break;
216
- if (input.flag('skip-saved') && await isSaved(output, id)) {
230
+ if (skip !== undefined && await skip(id)) {
217
231
  skipped.push(id);
218
232
  progress(index, id, 'skipped');
219
233
  continue;
220
234
  }
221
235
  try {
222
- const report = await inspect({ directory, output, source: { revision: id }, exclude, ignore: config.ignore }, executor);
236
+ const report = await inspectCommit(id);
223
237
  analyzed.push(id);
224
238
  if (report.status === 'partial')
225
239
  partial.push(id);
@@ -237,11 +251,15 @@ async function analyzeRange(input, range) {
237
251
  finally {
238
252
  process.removeListener('SIGINT', stop);
239
253
  }
240
- const requested = input.many('report');
241
- const reports = interrupted ? [] : await outputReports(root, store, requested.length ? requested : config.reports, input, config);
242
- print({ schema: 'urn:repometry:schema:analyze-range:1', range: `${base}..${head}`,
243
- analyzed, partial, skipped, failed, store: output, reports });
244
- return interrupted ? 130 : failed.length || partial.length ? 2 : 0;
254
+ return { analyzed, partial, skipped, failed, interrupted };
255
+ }
256
+ function analysisExecutor(input, plugins) {
257
+ const worker = input.text('worker');
258
+ if (worker === undefined)
259
+ return undefined;
260
+ if (plugins.length)
261
+ throw new Error('Configured process plugins require local analysis. Use --no-config with --worker.');
262
+ return remoteExecutor(worker, workerToken(), defaultLanguages.isSource);
245
263
  }
246
264
  async function isSaved(store, id) {
247
265
  try {
@@ -285,7 +303,7 @@ async function diffCoverage(input) {
285
303
  const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
286
304
  if (!lcov || (imports.length && findings.length))
287
305
  throw new Error('diff-coverage requires --import lcov=PATH');
288
- const report = await measureDiffCoverage({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov,
306
+ const report = await measureDiffCoverage({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, plugins: config.plugins,
289
307
  exclude: [...config.exclude, ...input.many('exclude')], minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage') });
290
308
  if (useGitHub(input))
291
309
  await writeGitHubDiffCoverage(report);
@@ -314,7 +332,7 @@ async function review(input) {
314
332
  },
315
333
  } : store.reader;
316
334
  const number = count(input.text('pull'), '--pull', 1);
317
- const report = await reviewPull({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, exclude, number,
335
+ const report = await reviewPull({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, exclude, number, plugins: config.plugins,
318
336
  minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage'),
319
337
  minimumLines: count(input.text('min-lines') ?? config.minLines, '--min-lines'),
320
338
  maxCoverageDrop: percent(input.text('max-coverage-drop') ?? config.maxCoverageDrop, '--max-coverage-drop'),
@@ -3,7 +3,7 @@ import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
3
3
  import { basename, dirname, resolve } from 'node:path';
4
4
  import { commitMetadataReader } from '../api/git/commit-metadata.js';
5
5
  import { readLocalSources, sourceRemotes } from '../api/git/local-sources.js';
6
- import { defaultLanguages } from '../compose/languages.js';
6
+ import { defaultLanguages, languageRegistry } from '../compose/languages.js';
7
7
  import { resolveSourceLocator } from '../compose/sources.js';
8
8
  import { commitSummary, withCommitMetadata } from '../report/json/projections/commit-summary.js';
9
9
  import { exportSite, siteSummary } from '../report/html/site/export-site.js';
@@ -42,7 +42,7 @@ export async function outputReports(root, store, requested, input, config) {
42
42
  readComponents(componentsPath(root, input), input.text('components') === undefined),
43
43
  store.path ? listPullReviews(store.path) : [],
44
44
  ]);
45
- const options = { languages: defaultLanguages, sources, components, pulls, readCommitMetadata, branch: input.text('branch') ?? config.branch,
45
+ const options = { languages: config.plugins.length ? languageRegistry(config.plugins) : defaultLanguages, sources, components, pulls, readCommitMetadata, branch: input.text('branch') ?? config.branch,
46
46
  title: input.text('title') ?? (input.text('repo') ? basename(root) : undefined),
47
47
  footer: !input.flag('no-footer') };
48
48
  for (const request of requests) {
@@ -93,7 +93,7 @@ export async function viewTarget(input, port) {
93
93
  readConfig(root, input),
94
94
  ]);
95
95
  const local = repository ? readLocalSources(repository) : undefined;
96
- const server = await serveSite(store.reader, port, { languages: defaultLanguages, title: input.text('title') ?? basename(root), components, pulls,
96
+ const server = await serveSite(store.reader, port, { languages: config.plugins.length ? languageRegistry(config.plugins) : defaultLanguages, title: input.text('title') ?? basename(root), components, pulls,
97
97
  branch: input.text('branch') ?? config.branch, readCommitMetadata: repository ? commitMetadataReader(repository) : undefined,
98
98
  sources: local ? resolveSourceLocator('local', { remotes: [], env: {} }) : undefined, footer: !input.flag('no-footer') }, local);
99
99
  return { ...server, label: `${basename(root)} (live from ${store.path ?? input.text('store')})` };
@@ -8,6 +8,7 @@ import type { AnalysisSources } from './analysis-sources.js';
8
8
  export declare const defaultFilePlan: readonly PlannedOperation[];
9
9
  export interface FileAnalysis {
10
10
  readonly cloneSources: readonly CloneSource[];
11
+ readonly codeLines: ReadonlyMap<string, ReadonlySet<number>>;
11
12
  readonly functionBodies: ReadonlyMap<string, readonly SourceLineRange[]>;
12
13
  }
13
14
  export declare function inspectFiles(sources: AnalysisSources, batchFacts: ReadonlyMap<string, CodeStructure>, results: AnalysisResults, withCoverage: boolean, cache?: OperationCacheOptions): Promise<FileAnalysis>;
@@ -1,11 +1,12 @@
1
1
  import { execute } from '../core/engine/execute.js';
2
2
  import { plan } from '../core/engine/plan.js';
3
- import { codeStructure } from '../core/model/code-structure.js';
3
+ import { codeStructure, structuralCheckIds, structureCodeLines } from '../core/model/code-structure.js';
4
4
  import { sourceFile } from '../core/model/snapshot.js';
5
5
  import { isClaimedText, maxClaimedFileBytes } from '../core/model/source.js';
6
6
  import { fileQuality } from '../plugins/maintainability/maintainability.js';
7
7
  import { oversizedClaim } from './analysis-results.js';
8
8
  import { defaultProvider, inspectionKeys, pluginForScope, structuralInspections } from './analysis-sources.js';
9
+ import { unmeasuredStructure } from './structure-measures.js';
9
10
  const standardInspections = ['structure/size', 'structure/complexity', 'maintainability/file'];
10
11
  const fileInput = new Map([['file', sourceFile.id]]);
11
12
  const batchFileInput = new Map([...fileInput, ['syntax', codeStructure.id]]);
@@ -13,6 +14,7 @@ export const defaultFilePlan = filePlan(defaultProvider, []);
13
14
  export async function inspectFiles(sources, batchFacts, results, withCoverage, cache) {
14
15
  const plans = new Map([[filePlanKey(defaultProvider, []), defaultFilePlan]]);
15
16
  const cloneSources = [];
17
+ const codeLines = new Map();
16
18
  const functionBodies = new Map();
17
19
  for (const source of sources.sources) {
18
20
  const plugins = matchedInspections(source, sources, results);
@@ -26,12 +28,17 @@ export async function inspectFiles(sources, batchFacts, results, withCoverage, c
26
28
  products.set('syntax', { contract: codeStructure.id, value: facts });
27
29
  const outcomes = await execute(tasks, products, cache);
28
30
  const syntax = provider && outcomes.get(provider.key);
29
- const bodies = recordFileSyntax(source, syntax, facts, results, withCoverage);
30
- if (bodies !== undefined)
31
- functionBodies.set(file.path, bodies);
31
+ const parsed = recordFileSyntax(source, syntax, facts, results, withCoverage);
32
+ if (withCoverage && parsed) {
33
+ const lines = structureCodeLines(parsed);
34
+ if (lines !== undefined)
35
+ codeLines.set(file.path, new Set(lines));
36
+ if (parsed.functionBodies !== undefined)
37
+ functionBodies.set(file.path, parsed.functionBodies);
38
+ }
32
39
  collectFileProducts(tasks, outcomes, source, cloneSources, results);
33
40
  }
34
- return { cloneSources, functionBodies };
41
+ return { cloneSources, codeLines, functionBodies };
35
42
  }
36
43
  function matchedInspections({ file }, sources, results) {
37
44
  const claimed = sources.perFile.filter(({ matches }) => matches(file.path));
@@ -75,7 +82,20 @@ function recordFileSyntax({ file, provider }, outcome, batch, results, withCover
75
82
  const facts = batch ?? ((!builtinParsed || withCoverage) && codeStructure.accepts(value) ? value : undefined);
76
83
  if (facts || builtinParsed)
77
84
  results.parsed.add(file.path);
78
- return withCoverage ? facts?.functionBodies : undefined;
85
+ if (facts && !builtinParsed)
86
+ recordUnmeasured(file.path, facts, results);
87
+ return facts;
88
+ }
89
+ function recordUnmeasured(path, facts, results) {
90
+ const unmeasured = unmeasuredStructure(facts);
91
+ if (unmeasured.length)
92
+ results.unmeasured.set(path, unmeasured);
93
+ if (facts.observations === undefined) {
94
+ results.ruleSkips.push({ path, plugin: 'maintainability', rules: structuralCheckIds, reason: 'unmeasured' });
95
+ }
96
+ if (facts.clones === undefined) {
97
+ results.ruleSkips.push({ path, plugin: 'duplication', rules: ['identical-code', 'similar-code'], reason: 'unmeasured' });
98
+ }
79
99
  }
80
100
  function collectFileProducts(tasks, outcomes, { file, provider }, clones, results) {
81
101
  for (const task of tasks) {
@@ -90,6 +110,6 @@ function cloneSource(outcome, provider) {
90
110
  if (outcome.state !== 'completed' || outcome.product.contract !== fileQuality.id || !fileQuality.accepts(outcome.product.value))
91
111
  return;
92
112
  const source = outcome.product.value.cloneSource;
93
- return provider && source.scheme === undefined ? { ...source, scheme: provider.plugin.id } : source;
113
+ return source && provider && source.scheme === undefined ? { ...source, scheme: provider.plugin.id } : source;
94
114
  }
95
115
  //# sourceMappingURL=analysis-files.js.map
@@ -16,8 +16,9 @@ export async function inspectDuplication(files, results, cache) {
16
16
  export async function importAnalysisCoverage({ coverage: input, excludedPaths = [], snapshot }, sources, files, results, cache) {
17
17
  if (input === undefined)
18
18
  return;
19
+ const unclassified = new Set([...results.unmeasured].filter(([, missing]) => missing.includes('codeLines')).map(([path]) => path));
19
20
  const value = { text: input.text, root: input.sourceRoot, sourceLines: sourceLineCounts(sources.sourceFiles),
20
- codeLines: new Map(files.cloneSources.map(({ path, codeLines }) => [path, new Set(codeLines)])), functionBodies: files.functionBodies,
21
+ codeLines: files.codeLines, unclassified, functionBodies: files.functionBodies,
21
22
  excludes: sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded) };
22
23
  const outcomes = await execute(coveragePlan, new Map([['lcov', { contract: lcovInput.id, value }]]), cache);
23
24
  for (const task of coveragePlan) {
@@ -10,7 +10,7 @@ const measurementDefinitions = {
10
10
  [definitions.lines]: 'Physical lines including blank lines and comments. A final line terminator does not add a line.',
11
11
  [definitions.functions]: 'Babel function nodes with bodies, including nested functions and methods.',
12
12
  [definitions.complexity]: 'One plus branches in the function body: if, ternary, loops, catch, non-default switch cases and logical operators. Nested functions are measured separately. Line and column are 1-based and columns count UTF-16 units.',
13
- [definitions.coverage]: 'Distinct covered code lines divided by the distinct code lines listed in LCOV DA records. Hit counts are summed across records. A zero denominator has no ratio.',
13
+ [definitions.coverage]: 'Distinct covered lines divided by the distinct lines listed in LCOV DA records, filtered to code where classifications are available. Hit counts are summed across records. A zero denominator has no ratio.',
14
14
  [definitions.codeLines]: 'Nonblank physical lines after removing Babel comment spans and the interpreter directive. A line containing both code and a comment counts as code.',
15
15
  [definitions.comments]: 'Physical lines containing only a Babel comment or interpreter directive.',
16
16
  [definitions.classes]: 'Babel class declaration and expression nodes.',
@@ -33,6 +33,7 @@ export function assembleAnalysisReport(input, sources, results) {
33
33
  measurements: results.measurements,
34
34
  diagnostics: results.diagnostics,
35
35
  findings: results.findings,
36
+ ...(results.ruleSkips.length === 0 ? {} : { ruleSkips: results.ruleSkips }),
36
37
  ...(pluginData === undefined ? {} : { pluginData: { ...pluginData, languages: sources.languages.catalog,
37
38
  inventory: reportInventory(snapshot, sources, results) } }),
38
39
  };
@@ -47,7 +48,8 @@ function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], co
47
48
  parser: defaultProvider.plugin.settings,
48
49
  maintainability: { structuralRules, duplication: duplicationSettings, debtModel, remediation: 'nonoverlapping-complexity/v1' },
49
50
  coverage: coverage === undefined ? null : { inputDigest: digest(coverage.text), pathBase: coverage.sourceRoot,
50
- merge: 'any-hit', hitCounts: 'sum', lines: 'code-only' },
51
+ merge: 'any-hit', hitCounts: 'sum',
52
+ lines: [...results.unmeasured.values()].some(measures => measures.includes('codeLines')) ? 'code-when-classified' : 'code-only' },
51
53
  ...(securityScanners.length ? { securityScanners } : {}),
52
54
  plugins: plugins.map(pluginProvenance),
53
55
  operations: results.operationRecords(),
@@ -71,8 +73,10 @@ function reportInventory(snapshot, sources, results) {
71
73
  }
72
74
  return [...inventory].sort(([left], [right]) => comparePaths(left, right)).map(([path, { lines, bytes }]) => {
73
75
  const provider = sources.providersByPath.get(path);
76
+ const unmeasured = results.unmeasured.get(path);
74
77
  return { path, lines, ...(bytes === undefined ? {} : { bytes }), language: provider?.language(path) ?? fileTypeId(path),
75
- analysed: results.parsed.has(path) || results.inspected.has(path), ...(provider === undefined ? {} : { provider: provider.key }) };
78
+ analysed: results.parsed.has(path) || results.inspected.has(path), ...(provider === undefined ? {} : { provider: provider.key }),
79
+ ...(unmeasured === undefined ? {} : { unmeasured }) };
76
80
  });
77
81
  }
78
82
  //# sourceMappingURL=analysis-report.js.map
@@ -3,12 +3,14 @@ import type { PlannedOperation } from '../core/engine/plan.js';
3
3
  import type { Plugin } from '../core/engine/plugin.js';
4
4
  import type { Finding } from '../core/model/finding.js';
5
5
  import type { Measurement } from '../core/model/measurement.js';
6
- import type { Diagnostic } from '../core/model/report.js';
6
+ import type { Diagnostic, Report } from '../core/model/report.js';
7
7
  export declare class AnalysisResults {
8
8
  readonly measurements: Measurement[];
9
9
  readonly findings: Finding[];
10
10
  readonly diagnostics: Diagnostic[];
11
11
  readonly parsed: Set<string>;
12
+ readonly ruleSkips: NonNullable<Report['ruleSkips']>[number][];
13
+ readonly unmeasured: Map<string, readonly ("classes" | "codeLines" | "cognitiveComplexity" | "commentLines" | "cyclomaticComplexity" | "duplication" | "functions" | "structuralRules")[]>;
12
14
  readonly inspected: Set<string>;
13
15
  completedInspection: boolean;
14
16
  private readonly products;
@@ -32,6 +34,7 @@ export declare function operationProvenance(task: PlannedOperation, syntaxProvid
32
34
  inputs: {
33
35
  [k: string]: import("../core/engine/plan.js").InputBinding;
34
36
  };
37
+ implementation?: string | undefined;
35
38
  scope?: "repository" | undefined;
36
39
  syntaxProvider?: string | undefined;
37
40
  };
@@ -5,6 +5,8 @@ export class AnalysisResults {
5
5
  findings = [];
6
6
  diagnostics;
7
7
  parsed = new Set();
8
+ ruleSkips = [];
9
+ unmeasured = new Map();
8
10
  inspected = new Set();
9
11
  completedInspection = false;
10
12
  products;
@@ -69,6 +71,7 @@ export class AnalysisResults {
69
71
  }
70
72
  export function operationProvenance(task, syntaxProvider) {
71
73
  return { key: task.key, inputs: Object.fromEntries(task.inputs),
74
+ ...(task.operation.implementation === undefined ? {} : { implementation: task.operation.implementation }),
72
75
  ...(task.operation.scope === 'repository' ? { scope: task.operation.scope } : {}),
73
76
  ...(syntaxProvider === undefined ? {} : { syntaxProvider }) };
74
77
  }
@@ -17,7 +17,8 @@ export function selectAnalysisSources(snapshot, additional, withCoverage) {
17
17
  const sources = snapshot.files.map(file => ({ file, provider: languages.select(file.path) }));
18
18
  const providersByPath = new Map(sources.flatMap(({ file, provider }) => provider ? [[file.path, provider]] : []));
19
19
  const sourceFiles = sources.flatMap(({ file, provider }) => provider ? [file] : []);
20
- const claimedPlugins = [...securityPlugins.filter(plugin => !additional.includes(plugin)), ...additional];
20
+ const bound = new Map(languages.providers.map(({ plugin }) => [plugin.id, plugin]));
21
+ const claimedPlugins = [...securityPlugins.filter(plugin => !additional.includes(plugin)), ...additional.map(plugin => bound.get(plugin.id) ?? plugin)];
21
22
  const plugins = [defaultProvider.plugin, ...structuralInspections, duplication, ...(withCoverage ? [coverage] : []), ...claimedPlugins];
22
23
  validateRegistration(plugins, additional, withCoverage);
23
24
  const claims = claimedPlugins.map(plugin => ({ plugin, matches: plugin.kinds.includes('language')
@@ -3,6 +3,7 @@ import { fileTypeId } from '../core/model/file-types.js';
3
3
  import { codeStructure, codeStructures } from '../core/model/code-structure.js';
4
4
  import { isExcludedDirectory } from '../core/model/snapshot.js';
5
5
  import { exclusionMatcher } from '../core/profile/exclusions.js';
6
+ import { restrictStructureMeasures } from './structure-measures.js';
6
7
  import { babelProvider } from '../plugins/language-js/babel-provider.js';
7
8
  export const defaultLanguages = languageRegistry([]);
8
9
  export function languageRegistry(plugins) {
@@ -26,7 +27,9 @@ export function languageRegistry(plugins) {
26
27
  }
27
28
  return found;
28
29
  }
29
- const provider = { plugin, operation, key: `${plugin.id}/${operation.id}`, batch: operation.scope === 'repository', language };
30
+ const bound = restrictStructureMeasures(operation, declared, language);
31
+ const executable = bound === operation ? plugin : { ...plugin, operations: plugin.operations.map(item => item === operation ? bound : item) };
32
+ const provider = { plugin: executable, operation: bound, key: `${plugin.id}/${operation.id}`, batch: operation.scope === 'repository', language };
30
33
  const claims = declared.length ? declared : [plugin.claims];
31
34
  return { provider, claims, matches: declared.length ? (path) => language(path) !== undefined : claimMatcher(plugin.claims) };
32
35
  });
@@ -1,6 +1,15 @@
1
+ import type { Plugin } from '../core/engine/plugin.js';
1
2
  export declare const builtInPlugins: {
2
3
  id: string;
3
4
  version: string;
4
- kinds: readonly import("../plugin.js").PluginKind[];
5
- claims?: import("../plugin.js").FileClaims | undefined;
5
+ kinds: readonly import("../core/engine/plugin.js").PluginKind[];
6
+ claims?: import("../core/engine/plugin.js").FileClaims | undefined;
7
+ providesLanguages?: readonly import("../plugin.js").ProvidedLanguage[] | undefined;
6
8
  }[];
9
+ export declare function describePlugin({ id, version, kinds, claims, providesLanguages }: Pick<Plugin, 'id' | 'version' | 'kinds' | 'claims' | 'providesLanguages'>): {
10
+ id: string;
11
+ version: string;
12
+ kinds: readonly import("../core/engine/plugin.js").PluginKind[];
13
+ claims?: import("../core/engine/plugin.js").FileClaims | undefined;
14
+ providesLanguages?: readonly import("../plugin.js").ProvidedLanguage[] | undefined;
15
+ };
@@ -7,5 +7,8 @@ import { defaultLanguages } from './languages.js';
7
7
  import { sourceProviders } from './sources.js';
8
8
  import { securityPlugins } from './security-plugins.js';
9
9
  export const builtInPlugins = [...defaultLanguages.providers.map(({ plugin }) => plugin), structure, maintainability, duplication, coverage, diffCoverage, ...securityPlugins, ...sourceProviders]
10
- .map(({ id, version, kinds, claims }) => ({ id, version, kinds, ...(claims ? { claims } : {}) }));
10
+ .map(describePlugin);
11
+ export function describePlugin({ id, version, kinds, claims, providesLanguages }) {
12
+ return { id, version, kinds, ...(claims ? { claims } : {}), ...(providesLanguages ? { providesLanguages } : {}) };
13
+ }
11
14
  //# sourceMappingURL=plugin-list.js.map