@repometry/cli 0.0.0 → 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/README.md CHANGED
@@ -22,7 +22,7 @@ Git can serve as a project’s single source of truth for code, tests, docs, and
22
22
 
23
23
  Node.js >=24
24
24
 
25
- Repometry analyses JavaScript, TypeScript, Go, Python, Java and PHP with no extra tools. Ruby, Kotlin and HCL (Terraform) come with `@repometry/all` or as plugins. See [Languages](docs/native-languages.md). Generating coverage uses your project's own test tools.
25
+ Repometry analyses JavaScript, TypeScript, Go, Python, Java and PHP with no extra tools. Ruby, Kotlin, HCL (Terraform), Lua, Scala, Elixir and Rust come with `@repometry/all` or as plugins. C#, C, C++ and Swift are separate plugins. See [Languages](docs/native-languages.md). Generating coverage uses your project's own test tools.
26
26
 
27
27
  ## Install
28
28
 
@@ -40,7 +40,7 @@ npm install --global repometry
40
40
  | --- | --- | --- | --- |
41
41
  | `@repometry/cli` | `repometry-cli` | JavaScript, TypeScript | about 8 MB |
42
42
  | `repometry` | `repometry` | The above, Go, Python, Java, PHP | about 15 MB |
43
- | `@repometry/all` | `repometry-all` | The above, Ruby, Kotlin, HCL | about 20 MB |
43
+ | `@repometry/all` | `repometry-all` | The above, Ruby, Kotlin, HCL, Lua, Scala, Elixir, Rust | about 28 MB |
44
44
 
45
45
  To add a language to `@repometry/cli`, install its `@repometry/language-*` package with your package manager and list it in `plugins`. Repometry never installs a plugin. See [Packages](docs/cli.md#packages).
46
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repometry/cli",
3
- "version": "0.0.0",
3
+ "version": "0.2.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.5.0",
71
71
  "ajv": "8.20.0",
72
72
  "semver": "7.8.6"
73
73
  },
@@ -1,4 +1,44 @@
1
1
  [
2
+ {
3
+ "language": "c",
4
+ "label": "C",
5
+ "package": "@repometry/language-c",
6
+ "experimental": true,
7
+ "extensions": [
8
+ ".c",
9
+ ".h"
10
+ ]
11
+ },
12
+ {
13
+ "language": "cpp",
14
+ "label": "C++",
15
+ "package": "@repometry/language-cpp",
16
+ "experimental": true,
17
+ "extensions": [
18
+ ".cc",
19
+ ".cpp",
20
+ ".cxx",
21
+ ".hpp",
22
+ ".hh"
23
+ ]
24
+ },
25
+ {
26
+ "language": "csharp",
27
+ "label": "C#",
28
+ "package": "@repometry/language-csharp",
29
+ "extensions": [
30
+ ".cs"
31
+ ]
32
+ },
33
+ {
34
+ "language": "elixir",
35
+ "label": "Elixir",
36
+ "package": "@repometry/language-elixir",
37
+ "extensions": [
38
+ ".ex",
39
+ ".exs"
40
+ ]
41
+ },
2
42
  {
3
43
  "language": "go",
4
44
  "label": "Go",
@@ -34,6 +74,14 @@
34
74
  ".kts"
35
75
  ]
36
76
  },
77
+ {
78
+ "language": "lua",
79
+ "label": "Lua",
80
+ "package": "@repometry/language-lua",
81
+ "extensions": [
82
+ ".lua"
83
+ ]
84
+ },
37
85
  {
38
86
  "language": "php",
39
87
  "label": "PHP",
@@ -57,5 +105,30 @@
57
105
  "extensions": [
58
106
  ".rb"
59
107
  ]
108
+ },
109
+ {
110
+ "language": "rust",
111
+ "label": "Rust",
112
+ "package": "@repometry/language-rust",
113
+ "extensions": [
114
+ ".rs"
115
+ ]
116
+ },
117
+ {
118
+ "language": "scala",
119
+ "label": "Scala",
120
+ "package": "@repometry/language-scala",
121
+ "extensions": [
122
+ ".scala"
123
+ ]
124
+ },
125
+ {
126
+ "language": "swift",
127
+ "label": "Swift",
128
+ "package": "@repometry/language-swift",
129
+ "experimental": true,
130
+ "extensions": [
131
+ ".swift"
132
+ ]
60
133
  }
61
134
  ]
@@ -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 }),
@@ -6,6 +6,7 @@ import { languageFileSelection } from './file-selection.js';
6
6
  const fileTypesByExtension = new Map(fileTypes.flatMap(type => (type.extensions ?? []).map(extension => [extension, type.id])));
7
7
  const officialByExtension = new Map();
8
8
  const packagesByLanguage = new Map();
9
+ const experimentalPackages = new Set(catalog.filter(entry => entry.experimental).map(entry => entry.package));
9
10
  const labels = new Map(catalog.map(({ language, label }) => [language, label]));
10
11
  for (const entry of catalog) {
11
12
  const packages = packagesByLanguage.get(entry.language) ?? new Set();
@@ -43,7 +44,7 @@ export function detectMissingLanguages(plugins) {
43
44
  }
44
45
  export function missingLanguageNotice({ language, files, packages }) {
45
46
  const label = labels.get(language) ?? language;
46
- const choices = packages.join(' or ');
47
+ const choices = packages.map(name => experimentalPackages.has(name) ? name + ' (experimental)' : name).join(' or ');
47
48
  const install = packages.map(name => 'npm install -D ' + name).join(' or ');
48
49
  const noun = files === 1 ? 'file has' : 'files have';
49
50
  return `${label}: ${files} ${noun} no configured parser. Install ${choices} next to Repometry (${install}) and add it to plugins in repometry.config.json.`;
@@ -1,3 +1,4 @@
1
+ import { extname } from 'node:path';
1
2
  import { plan } from '@repometry/core/internal/engine/plan.js';
2
3
  import { fileTypeId, fileTypes } from '@repometry/core/internal/model/file-types.js';
3
4
  import { codeStructure, codeStructures } from '@repometry/core/internal/model/code-structure.js';
@@ -7,6 +8,7 @@ import { languageMeasures, restrictStructureMeasures, structureImplementation }
7
8
  import { builtInPluginIds, builtInPlugins, registeredPlugins } from './built-ins.js';
8
9
  import { pluginRegistration } from './registered-plugin.js';
9
10
  import { languageFileSelection } from './file-selection.js';
11
+ import { pluginScope } from './plugin-scope.js';
10
12
  export { claimMatcher } from './file-selection.js';
11
13
  const fileTypeSyntax = new Map(fileTypes.flatMap(({ id, syntax }) => syntax === undefined ? [] : [[id, syntax]]));
12
14
  export const defaultLanguages = languageRegistry([]);
@@ -20,6 +22,8 @@ export function languageRegistry(plugins, parsers, label = 'parsers') {
20
22
  byProvider.set(plugin.id, [...byProvider.get(plugin.id) ?? [], language]);
21
23
  const bindings = new Map();
22
24
  const entries = registered.filter(plugin => plugin.kinds.includes('language')).flatMap(plugin => languageEntry(plugin, byProvider.get(plugin.id) ?? [], bindings));
25
+ // The official C++ package accepts .h only through a configured include.
26
+ const cpp = entries.find(entry => entry.id === 'language-cpp' && entry.requiresSource && entry.explicitInclude);
23
27
  const active = entries.flatMap(({ provider }) => provider ?? []);
24
28
  const { extensions, globs, catalog } = languageSelection(entries);
25
29
  const syntaxById = selectedSyntax(selection);
@@ -36,7 +40,10 @@ export function languageRegistry(plugins, parsers, label = 'parsers') {
36
40
  }
37
41
  function match(path) {
38
42
  let matched;
43
+ const cppHeader = cpp !== undefined && extname(path) === '.h' && cpp.matches(path);
39
44
  for (const entry of entries) {
45
+ if (cppHeader && entry.id === 'language-c' && entry.requiresSource)
46
+ continue;
40
47
  if (!entry.matches(path))
41
48
  continue;
42
49
  if (matched)
@@ -68,7 +75,8 @@ function languageEntry(plugin, chosen, bindings) {
68
75
  const provider = available && operation ? bindParser(plugin, operation, declared, identify) : undefined;
69
76
  if (provider)
70
77
  bindings.set(plugin, provider.plugin);
71
- return [{ id: plugin.id, provider, declared, claims, matches, identify, requiresSource: plugin.languageProvenanceRequiresSource }];
78
+ return [{ id: plugin.id, provider, declared, claims, matches, identify,
79
+ requiresSource: plugin.languageProvenanceRequiresSource, explicitInclude: pluginScope(plugin)?.include !== undefined }];
72
80
  }
73
81
  function languageSelection(entries) {
74
82
  const available = entries.filter(({ provider }) => provider !== undefined);
@@ -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;