@repometry/cli 0.0.0 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repometry/cli",
3
- "version": "0.0.0",
3
+ "version": "0.1.0",
4
4
  "description": "Track repository metrics without SaaS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -67,7 +67,7 @@
67
67
  "dependencies": {
68
68
  "@babel/parser": "7.29.15",
69
69
  "@babel/types": "7.29.15",
70
- "@repometry/core": "0.3.0",
70
+ "@repometry/core": "0.4.0",
71
71
  "ajv": "8.20.0",
72
72
  "semver": "7.8.6"
73
73
  },
@@ -1,4 +1,12 @@
1
1
  [
2
+ {
3
+ "language": "csharp",
4
+ "label": "C#",
5
+ "package": "@repometry/language-csharp",
6
+ "extensions": [
7
+ ".cs"
8
+ ]
9
+ },
2
10
  {
3
11
  "language": "go",
4
12
  "label": "Go",
@@ -34,6 +42,14 @@
34
42
  ".kts"
35
43
  ]
36
44
  },
45
+ {
46
+ "language": "lua",
47
+ "label": "Lua",
48
+ "package": "@repometry/language-lua",
49
+ "extensions": [
50
+ ".lua"
51
+ ]
52
+ },
37
53
  {
38
54
  "language": "php",
39
55
  "label": "PHP",
@@ -62,6 +62,10 @@
62
62
  },
63
63
  "parsed": {
64
64
  "$ref": "#/$defs/count"
65
+ },
66
+ "recovered": {
67
+ "type": "integer",
68
+ "minimum": 1
65
69
  }
66
70
  },
67
71
  "additionalProperties": false
@@ -201,6 +201,10 @@
201
201
  "parsed": {
202
202
  "$ref": "#/$defs/count"
203
203
  },
204
+ "recovered": {
205
+ "type": "integer",
206
+ "minimum": 1
207
+ },
204
208
  "lines": {
205
209
  "$ref": "#/$defs/nullableCount"
206
210
  },
@@ -33,7 +33,8 @@ export function assembleAnalysisReport(input, sources, results) {
33
33
  appliedConfig: appliedConfiguration(input, sources, results, selectors),
34
34
  definitions: { ...Object.fromEntries((pluginData?.metrics ?? []).map(metric => [metric.id, metric.description ?? metric.label])),
35
35
  ...measurementDefinitions },
36
- scope: { files: fileCount, parsed: results.parsed.size },
36
+ scope: { files: fileCount, parsed: results.parsed.size,
37
+ ...(results.recovered.size ? { recovered: results.recovered.size } : {}) },
37
38
  status: inspectionStatus(fileCount > 0, results),
38
39
  measurements: results.measurements,
39
40
  diagnostics: results.diagnostics,
@@ -110,7 +111,7 @@ function pluginProvenance(plugin) {
110
111
  ...(providesLanguages === undefined ? {} : { providesLanguages: providesLanguages.map(({ syntax, ...language }) => language) }), ...(unavailableReason === undefined ? {} : { unavailableReason }) };
111
112
  }
112
113
  function inspectionStatus(hasSources, results) {
113
- if (results.diagnostics.length > 0)
114
+ if (results.hasBlockingDiagnostics())
114
115
  return 'partial';
115
116
  return !hasSources && !results.completedInspection ? 'not-applicable' : 'complete';
116
117
  }
@@ -9,6 +9,7 @@ export declare class AnalysisResults {
9
9
  readonly findings: Finding[];
10
10
  readonly diagnostics: Diagnostic[];
11
11
  readonly parsed: Set<string>;
12
+ readonly recovered: Map<string, Diagnostic>;
12
13
  readonly ran: Set<string>;
13
14
  readonly ruleSkips: NonNullable<Report['ruleSkips']>[number][];
14
15
  readonly unmeasured: Map<string, readonly ("classes" | "codeLines" | "cognitiveComplexity" | "commentLines" | "cyclomaticComplexity" | "duplication" | "functions" | "structuralRules")[]>;
@@ -18,6 +19,7 @@ export declare class AnalysisResults {
18
19
  private readonly scanned;
19
20
  private readonly scanOnly;
20
21
  private readonly securityOperations;
22
+ private readonly recoveryOperations;
21
23
  private readonly usedPlans;
22
24
  constructor(plugins: readonly Plugin[], oversized: readonly string[]);
23
25
  remember(task: PlannedOperation, syntaxProvider?: string): void;
@@ -28,6 +30,8 @@ export declare class AnalysisResults {
28
30
  version: string;
29
31
  }[];
30
32
  record(task: PlannedOperation, outcome: Outcome, path?: string, paths?: readonly string[]): void;
33
+ hasBlockingDiagnostics(): boolean;
34
+ private recordRecovery;
31
35
  private recordInspection;
32
36
  }
33
37
  export declare function operationProvenance(task: PlannedOperation, syntaxProvider?: string): {
@@ -1,9 +1,13 @@
1
+ import { isRecord } from '@repometry/core/internal/engine/plugin.js';
1
2
  import { ReportProducts } from '@repometry/core/internal/engine/report-products.js';
3
+ import { codeStructure, recoveredSyntax } from '@repometry/core/internal/model/code-structure.js';
4
+ import { recoveredSourceOperation } from '@repometry/core/internal/model/report.js';
2
5
  export class AnalysisResults {
3
6
  measurements = [];
4
7
  findings = [];
5
8
  diagnostics;
6
9
  parsed = new Set();
10
+ recovered = new Map();
7
11
  ran = new Set();
8
12
  ruleSkips = [];
9
13
  unmeasured = new Map();
@@ -13,10 +17,13 @@ export class AnalysisResults {
13
17
  scanned = new Set();
14
18
  scanOnly;
15
19
  securityOperations;
20
+ recoveryOperations;
16
21
  usedPlans = new Map();
17
22
  constructor(plugins, oversized) {
18
23
  this.products = new ReportProducts(plugins);
19
24
  this.diagnostics = oversized.map(oversizedClaim);
25
+ this.recoveryOperations = new Set(plugins.filter(plugin => plugin.languageProvenanceRequiresSource && plugin.kinds.includes('language')).flatMap(({ id, operations }) => operations.filter(operation => operation.role === 'provider' && operation.output.id === codeStructure.id)
26
+ .map(operation => id + '/' + operation.id)));
20
27
  this.scanOnly = new Set(plugins.filter(plugin => plugin.claims?.scanOnly).flatMap(({ id, operations }) => operations.map(operation => `${id}/${operation.id}`)));
21
28
  this.securityOperations = new Map(plugins.filter(plugin => plugin.kinds.includes('security')).flatMap(plugin => plugin.operations.filter(({ role }) => role === 'inspection').map(({ id }) => [`${plugin.id}/${id}`, plugin.id])));
22
29
  }
@@ -42,6 +49,7 @@ export class AnalysisResults {
42
49
  }
43
50
  try {
44
51
  const stored = this.products.record(task, outcome.product, path);
52
+ this.recordRecovery(task, outcome.product.value, path);
45
53
  this.recordInspection(task, outcome.diagnostics ?? [], path, paths);
46
54
  if (stored) {
47
55
  for (const measurement of stored.measurements)
@@ -54,6 +62,23 @@ export class AnalysisResults {
54
62
  this.diagnostics.push({ operation: task.key, state: 'failed', path, message: error instanceof Error ? error.message : String(error) });
55
63
  }
56
64
  }
65
+ hasBlockingDiagnostics() {
66
+ return this.diagnostics.some(row => row.path === undefined || this.recovered.get(row.path) !== row);
67
+ }
68
+ recordRecovery(task, value, path) {
69
+ if (path === undefined || this.recovered.has(path) || !this.recoveryOperations.has(task.key))
70
+ return;
71
+ const facts = value;
72
+ const details = recoveryDetails(facts[recoveredSyntax]);
73
+ if (details === undefined)
74
+ return;
75
+ const message = details.reason + ' at ' + details.location + '. Declarations omitted: ' + details.omitted + '.';
76
+ const measured = (facts.functions ?? 0) + (facts.classes ?? 0);
77
+ const diagnostic = { operation: recoveredSourceOperation, state: 'partial', path,
78
+ message: measured ? message : message + ' No declarations could be measured.' };
79
+ this.recovered.set(path, diagnostic);
80
+ this.diagnostics.push(diagnostic);
81
+ }
57
82
  recordInspection(task, messages, path, paths) {
58
83
  for (const { message, path: own = path } of messages)
59
84
  this.diagnostics.push({ operation: task.key, state: 'partial', ...(own === undefined ? {} : { path: own }), message });
@@ -72,6 +97,16 @@ export class AnalysisResults {
72
97
  this.inspected.add(file);
73
98
  }
74
99
  }
100
+ function recoveryDetails(value) {
101
+ if (!isRecord(value))
102
+ return undefined;
103
+ const { reason, location, omitted } = value;
104
+ if (typeof reason !== 'string' || !reason.trim()
105
+ || typeof location !== 'string' || !/^line [1-9]\d*, column [1-9]\d*$/.test(location)
106
+ || typeof omitted !== 'number' || !Number.isSafeInteger(omitted) || omitted < 0)
107
+ return undefined;
108
+ return { reason, location, omitted };
109
+ }
75
110
  export function operationProvenance(task, syntaxProvider) {
76
111
  return { key: task.key, inputs: Object.fromEntries(task.inputs),
77
112
  ...(task.operation.implementation === undefined ? {} : { implementation: task.operation.implementation }),
@@ -117,9 +117,10 @@ export function historyEntry(report) {
117
117
  const endingAt = isRecord(window) && typeof window.endingAt === 'string' ? window.endingAt : '';
118
118
  const committedAt = Date.parse(report.committedAt ?? endingAt);
119
119
  const generatedAt = Date.parse(report.generatedAt);
120
+ const { files, parsed, recovered } = report.scope;
120
121
  return { sha: report.subject.id, generatedAt: Number.isFinite(generatedAt) ? new Date(generatedAt).toISOString() : '',
121
122
  ...(Number.isFinite(committedAt) ? { committedAt: new Date(committedAt).toISOString() } : {}), status: report.status,
122
- files: report.scope.files, parsed: report.scope.parsed, lines: measured(definitions.lines, lines),
123
+ files, parsed, ...(recovered ? { recovered } : {}), lines: measured(definitions.lines, lines),
123
124
  functions: measured(definitions.functions, functions), maxComplexity: measured(definitions.complexity, maxComplexity), lineCoverage };
124
125
  }
125
126
  //# sourceMappingURL=commit-summary.js.map
@@ -55,8 +55,7 @@ export function readReport(value) {
55
55
  if (lines && !lcovLines.accepts(lines[0]?.value))
56
56
  throw new Error('Invalid report: LCOV line ranges must be sorted and merged');
57
57
  }
58
- if (value.scope.parsed > value.scope.files)
59
- throw new Error('Invalid report: parsed count exceeds source count');
58
+ validateScope(value.scope);
60
59
  if (value.findings?.some(finding => !isFinding(finding)))
61
60
  throw new Error('Invalid report: inconsistent finding location');
62
61
  const ignore = value.appliedConfig.findingIgnore;
@@ -74,4 +73,10 @@ export function readReport(value) {
74
73
  }
75
74
  return value;
76
75
  }
76
+ function validateScope({ files, parsed, recovered = 0 }) {
77
+ if (parsed > files)
78
+ throw new Error('Invalid report: parsed count exceeds source count');
79
+ if (recovered > parsed)
80
+ throw new Error('Invalid report: recovered count exceeds parsed count');
81
+ }
77
82
  //# sourceMappingURL=report.js.map
@@ -8,10 +8,14 @@ export const validateSummary = validator.compile(summaryContract);
8
8
  const rowShape = validator.compile({ $ref: `${summarySchema}#/$defs/commit` });
9
9
  export function validateSummaryIndex(value) {
10
10
  return validateSummary(value) && validCatalog(value.metrics, value.privateMetrics)
11
- && value.commits.every(row => validCatalog(row.metrics, row.privateMetrics) && validPositions(row, value.metrics));
11
+ && value.commits.every(row => validRow(row, value.metrics));
12
12
  }
13
13
  export function validateSummaryRow(value) {
14
- return rowShape(value) && validCatalog(value.metrics, value.privateMetrics) && validPositions(value);
14
+ return rowShape(value) && validRow(value);
15
+ }
16
+ function validRow(row, fallback) {
17
+ return (row.recovered === undefined || row.recovered <= row.parsed)
18
+ && validCatalog(row.metrics, row.privateMetrics) && validPositions(row, fallback);
15
19
  }
16
20
  function validCatalog(catalog, privateMetrics = []) {
17
21
  if (catalog && !catalog.every(isMetricDescriptor))
@@ -16,6 +16,7 @@ export interface PublicHistoryEntry {
16
16
  readonly status: Report['status'];
17
17
  readonly files: number;
18
18
  readonly parsed: number;
19
+ readonly recovered?: number;
19
20
  readonly lines: number | null;
20
21
  readonly functions: number | null;
21
22
  readonly maxComplexity: number | null;