@repometry/core 0.0.0-dev.0 → 0.0.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/LICENSE +21 -0
  2. package/package.json +37 -2
  3. package/target/main/ts/engine/execute.d.ts +15 -0
  4. package/target/main/ts/engine/execute.js +63 -0
  5. package/target/main/ts/engine/manifest.d.ts +3 -0
  6. package/target/main/ts/engine/manifest.js +129 -0
  7. package/target/main/ts/engine/operation-cache.d.ts +14 -0
  8. package/target/main/ts/engine/operation-cache.js +66 -0
  9. package/target/main/ts/engine/plan.d.ts +21 -0
  10. package/target/main/ts/engine/plan.js +123 -0
  11. package/target/main/ts/engine/plugin.d.ts +71 -0
  12. package/target/main/ts/engine/plugin.js +3 -0
  13. package/target/main/ts/engine/report-products.d.ts +16 -0
  14. package/target/main/ts/engine/report-products.js +76 -0
  15. package/target/main/ts/index.d.ts +20 -0
  16. package/target/main/ts/index.js +8 -0
  17. package/target/main/ts/model/changes.d.ts +39 -0
  18. package/target/main/ts/model/changes.js +6 -0
  19. package/target/main/ts/model/churn.d.ts +11 -0
  20. package/target/main/ts/model/churn.js +6 -0
  21. package/target/main/ts/model/clone-source.d.ts +19 -0
  22. package/target/main/ts/model/clone-source.js +20 -0
  23. package/target/main/ts/model/code-structure.d.ts +45 -0
  24. package/target/main/ts/model/code-structure.js +63 -0
  25. package/target/main/ts/model/comparison.d.ts +24 -0
  26. package/target/main/ts/model/comparison.js +2 -0
  27. package/target/main/ts/model/coverage-input.d.ts +12 -0
  28. package/target/main/ts/model/coverage-input.js +11 -0
  29. package/target/main/ts/model/diff-coverage.d.ts +25 -0
  30. package/target/main/ts/model/diff-coverage.js +10 -0
  31. package/target/main/ts/model/file-types.d.ts +20 -0
  32. package/target/main/ts/model/file-types.js +50 -0
  33. package/target/main/ts/model/finding-ignore.d.ts +8 -0
  34. package/target/main/ts/model/finding-ignore.js +36 -0
  35. package/target/main/ts/model/finding.d.ts +34 -0
  36. package/target/main/ts/model/finding.js +45 -0
  37. package/target/main/ts/model/ignore-rule.d.ts +11 -0
  38. package/target/main/ts/model/ignore-rule.js +2 -0
  39. package/target/main/ts/model/language.d.ts +44 -0
  40. package/target/main/ts/model/language.js +31 -0
  41. package/target/main/ts/model/line-coverage.d.ts +15 -0
  42. package/target/main/ts/model/line-coverage.js +43 -0
  43. package/target/main/ts/model/measurement.d.ts +34 -0
  44. package/target/main/ts/model/measurement.js +42 -0
  45. package/target/main/ts/model/metric-descriptor.d.ts +17 -0
  46. package/target/main/ts/model/metric-descriptor.js +2 -0
  47. package/target/main/ts/model/plugin-data.d.ts +32 -0
  48. package/target/main/ts/model/plugin-data.js +16 -0
  49. package/target/main/ts/model/pull-review.d.ts +70 -0
  50. package/target/main/ts/model/pull-review.js +4 -0
  51. package/target/main/ts/model/quality-summary.d.ts +46 -0
  52. package/target/main/ts/model/quality-summary.js +92 -0
  53. package/target/main/ts/model/report.d.ts +45 -0
  54. package/target/main/ts/model/report.js +5 -0
  55. package/target/main/ts/model/scanner-import.d.ts +39 -0
  56. package/target/main/ts/model/scanner-import.js +29 -0
  57. package/target/main/ts/model/snapshot.d.ts +14 -0
  58. package/target/main/ts/model/snapshot.js +49 -0
  59. package/target/main/ts/model/source-locator.d.ts +7 -0
  60. package/target/main/ts/model/source-locator.js +2 -0
  61. package/target/main/ts/model/source.d.ts +31 -0
  62. package/target/main/ts/model/source.js +20 -0
  63. package/target/main/ts/ports/report.d.ts +9 -0
  64. package/target/main/ts/ports/report.js +2 -0
  65. package/target/main/ts/ports/source-provider.d.ts +14 -0
  66. package/target/main/ts/ports/source-provider.js +5 -0
  67. package/target/main/ts/ports/tool-runner.d.ts +18 -0
  68. package/target/main/ts/ports/tool-runner.js +2 -0
  69. package/target/main/ts/profile/exclusions.d.ts +11 -0
  70. package/target/main/ts/profile/exclusions.js +58 -0
  71. package/target/main/ts/profile/maintainability.d.ts +31 -0
  72. package/target/main/ts/profile/maintainability.js +10 -0
  73. package/target/main/ts/profile/profile.d.ts +4 -0
  74. package/target/main/ts/profile/profile.js +11 -0
  75. package/target/main/ts/usecases/diff-coverage-policy.d.ts +6 -0
  76. package/target/main/ts/usecases/diff-coverage-policy.js +11 -0
  77. package/target/main/ts/usecases/diff-coverage.d.ts +40 -0
  78. package/target/main/ts/usecases/diff-coverage.js +16 -0
  79. package/target/main/ts/usecases/inspect.d.ts +37 -0
  80. package/target/main/ts/usecases/inspect.js +42 -0
  81. package/target/main/ts/usecases/review-effect.d.ts +18 -0
  82. package/target/main/ts/usecases/review-effect.js +37 -0
  83. package/target/main/ts/usecases/review-match.d.ts +14 -0
  84. package/target/main/ts/usecases/review-match.js +72 -0
  85. package/target/main/ts/usecases/review-position.d.ts +14 -0
  86. package/target/main/ts/usecases/review-position.js +53 -0
  87. package/target/main/ts/usecases/review-scope.d.ts +21 -0
  88. package/target/main/ts/usecases/review-scope.js +41 -0
  89. package/target/main/ts/usecases/review.d.ts +42 -0
  90. package/target/main/ts/usecases/review.js +112 -0
  91. package/README.md +0 -4
@@ -0,0 +1,76 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { findingResult } from '../model/finding.js';
3
+ import { measurements } from '../model/measurement.js';
4
+ import { isJsonValue } from '../model/plugin-data.js';
5
+ import { isRecord } from './plugin.js';
6
+ export class ReportProducts {
7
+ metrics = new Map();
8
+ measured = new Set();
9
+ privateMetrics = new Set();
10
+ products = new Map();
11
+ contracts = new Map();
12
+ rules;
13
+ declared;
14
+ constructor(plugins) {
15
+ this.declared = plugins.some(plugin => plugin.produces !== undefined);
16
+ this.rules = plugins.flatMap(({ id, rules }) => rules?.length ? [{ plugin: id, rules }] : []);
17
+ for (const plugin of plugins) {
18
+ for (const product of plugin.produces ?? []) {
19
+ if (product.persistence !== 'report')
20
+ continue;
21
+ if (product.schema !== undefined) {
22
+ const previous = this.contracts.get(product.contract);
23
+ if (previous !== undefined && !isDeepStrictEqual(previous, product.schema)) {
24
+ throw new Error(`Conflicting product schemas: ${product.contract}`);
25
+ }
26
+ this.contracts.set(product.contract, product.schema);
27
+ }
28
+ for (const metric of product.metrics ?? []) {
29
+ const existing = this.metrics.get(metric.id);
30
+ if (existing && !isDeepStrictEqual(existing, metric))
31
+ throw new Error(`Conflicting metric declaration: ${metric.id}`);
32
+ this.metrics.set(metric.id, metric);
33
+ if (plugin.kinds?.includes('security'))
34
+ this.privateMetrics.add(metric.id);
35
+ }
36
+ }
37
+ }
38
+ }
39
+ record(task, { contract, value }, path) {
40
+ if (task.declaration?.persistence !== 'report')
41
+ return undefined;
42
+ const rows = measurements.accepts(value) ? { measurements: value, findings: [] }
43
+ : findingResult.accepts(value) ? value
44
+ : isRecord(value) && measurements.accepts(value.measurements) ? { measurements: value.measurements, findings: [] } : undefined;
45
+ if (rows) {
46
+ const declared = new Set(task.declaration.metrics?.map(metric => metric.id));
47
+ const unknown = rows.measurements.find(row => !declared.has(row.definition));
48
+ if (unknown)
49
+ throw new Error(`Undeclared metric from ${task.key}: ${unknown.definition}`);
50
+ }
51
+ if (task.declaration.schema === undefined && !rows)
52
+ throw new Error(`Report product ${contract} from ${task.key} has no schema and no rows`);
53
+ if (task.declaration.schema !== undefined) {
54
+ if (!isJsonValue(value))
55
+ throw new Error(`Report product ${contract} is not JSON data`);
56
+ const record = { operation: task.key, ...(path === undefined ? {} : { path }), value };
57
+ const existing = this.products.get(contract);
58
+ if (existing)
59
+ existing.push(record);
60
+ else
61
+ this.products.set(contract, [record]);
62
+ }
63
+ for (const metric of task.declaration.metrics ?? [])
64
+ this.measured.add(metric.id);
65
+ return rows;
66
+ }
67
+ result() {
68
+ if (!this.declared)
69
+ return undefined;
70
+ return { metrics: [...this.metrics.values()], measured: [...this.measured],
71
+ ...(this.privateMetrics.size ? { privateMetrics: [...this.privateMetrics] } : {}),
72
+ ...(this.contracts.size ? { contracts: Object.fromEntries(this.contracts) } : {}),
73
+ rules: this.rules, products: Object.fromEntries(this.products) };
74
+ }
75
+ }
76
+ //# sourceMappingURL=report-products.js.map
@@ -0,0 +1,20 @@
1
+ export { pluginApi } from './engine/plugin.js';
2
+ export { plan } from './engine/plan.js';
3
+ export type { InputBinding, PlanRequest, PlannedOperation } from './engine/plan.js';
4
+ export { execute } from './engine/execute.js';
5
+ export type { Outcome } from './engine/execute.js';
6
+ export type { DataContract, InspectionInputs, Operation, Plugin, PluginConfigSchema, Product, RuleDescriptor } from './engine/plugin.js';
7
+ export type { FileClaims, MetricDescriptor, MetricScope, PluginKind, ProductDeclaration } from './engine/plugin.js';
8
+ export type { OperationCache, OperationCacheOptions } from './engine/operation-cache.js';
9
+ export { codeStructure, codeStructures } from './model/code-structure.js';
10
+ export type { CodeStructure, FunctionComplexity, StructureMeasure, StructuralCheck, StructuralObservation } from './model/code-structure.js';
11
+ export type { LanguageDisplay, LanguageSyntax, ProvidedLanguage } from './model/language.js';
12
+ export type { Candidate, CloneSource } from './model/clone-source.js';
13
+ export { sourceFile, sourceFiles } from './model/snapshot.js';
14
+ export type { InventoryFile, SourceFile, SourceSnapshot } from './model/source.js';
15
+ export { measurements } from './model/measurement.js';
16
+ export type { Measurement } from './model/measurement.js';
17
+ export { findingResult } from './model/finding.js';
18
+ export type { Finding, FindingLocation, FindingResult } from './model/finding.js';
19
+ export type { SourceContext, SourcePlugin, SourceProvider } from './ports/source-provider.js';
20
+ export type { ToolInvocation, ToolResult, ToolRunner } from './ports/tool-runner.js';
@@ -0,0 +1,8 @@
1
+ export { pluginApi } from './engine/plugin.js';
2
+ export { plan } from './engine/plan.js';
3
+ export { execute } from './engine/execute.js';
4
+ export { codeStructure, codeStructures } from './model/code-structure.js';
5
+ export { sourceFile, sourceFiles } from './model/snapshot.js';
6
+ export { measurements } from './model/measurement.js';
7
+ export { findingResult } from './model/finding.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,39 @@
1
+ import type { DataContract } from '../engine/plugin.js';
2
+ export interface LineRange {
3
+ readonly first: number;
4
+ readonly last: number;
5
+ }
6
+ /** One file's change between two commits, with the changed lines on each side. */
7
+ export interface FileLineChange {
8
+ /** The head path; null when the file was deleted. */
9
+ readonly path: string | null;
10
+ /** The base path; null when the file was added. */
11
+ readonly previous: string | null;
12
+ /** Head side: added and modified lines. */
13
+ readonly added: readonly LineRange[];
14
+ /** Base side: modified and removed lines. */
15
+ readonly removed: readonly LineRange[];
16
+ /** Binary or undecodable content: the file changed, but its lines are unknown. */
17
+ readonly whole: boolean;
18
+ /** The diff's hunks, which place unchanged base lines on the head side. Empty for added, deleted and whole files. */
19
+ readonly hunks: readonly LineHunk[];
20
+ }
21
+ /** One diff hunk: `count` lines from `first` on each side; a count of 0 is an insertion or removal after line `first`. */
22
+ export interface LineHunk {
23
+ readonly base: {
24
+ readonly first: number;
25
+ readonly count: number;
26
+ };
27
+ readonly head: {
28
+ readonly first: number;
29
+ readonly count: number;
30
+ };
31
+ }
32
+ export interface LineChanges {
33
+ readonly files: readonly FileLineChange[];
34
+ }
35
+ export interface GitChanges {
36
+ readonly files: ReadonlyMap<string, readonly LineRange[]>;
37
+ readonly gaps: ReadonlyMap<string, string>;
38
+ }
39
+ export declare const changesInput: DataContract<GitChanges>;
@@ -0,0 +1,6 @@
1
+ import { isRecord } from './plugin-data.js';
2
+ export const changesInput = {
3
+ id: 'repometry.git-line-changes/v1',
4
+ accepts: (value) => isRecord(value) && value.files instanceof Map && value.gaps instanceof Map,
5
+ };
6
+ //# sourceMappingURL=changes.js.map
@@ -0,0 +1,11 @@
1
+ export declare const churnSettings: {
2
+ readonly method: 'first-parent-path-touches/v1';
3
+ readonly lookbackDays: 90;
4
+ readonly maxCommits: 512;
5
+ };
6
+ export interface ChurnWindow {
7
+ readonly endingAt: string;
8
+ readonly commits: number;
9
+ readonly shallow: boolean;
10
+ readonly capReached: boolean;
11
+ }
@@ -0,0 +1,6 @@
1
+ export const churnSettings = {
2
+ method: 'first-parent-path-touches/v1',
3
+ lookbackDays: 90,
4
+ maxCommits: 512,
5
+ };
6
+ //# sourceMappingURL=churn.js.map
@@ -0,0 +1,19 @@
1
+ import type { DataContract } from '../engine/plugin.js';
2
+ export interface Candidate {
3
+ readonly start: number;
4
+ readonly end: number;
5
+ readonly line: number;
6
+ readonly endLine: number;
7
+ readonly codeLines: number;
8
+ readonly nodes: number;
9
+ readonly exact: string;
10
+ readonly similar: string;
11
+ }
12
+ export interface CloneSource {
13
+ readonly path: string;
14
+ readonly scheme?: string;
15
+ readonly codeLines: readonly number[];
16
+ readonly candidates: readonly Candidate[];
17
+ }
18
+ export declare function isCloneSource(value: unknown): value is CloneSource;
19
+ export declare const cloneSources: DataContract<readonly CloneSource[]>;
@@ -0,0 +1,20 @@
1
+ import { isRecord } from './plugin-data.js';
2
+ function isCandidate(value) {
3
+ return isRecord(value) && isCount(value.start) && isCount(value.end) && value.start < value.end
4
+ && isCount(value.line) && value.line > 0 && isCount(value.endLine) && value.endLine >= value.line
5
+ && isCount(value.codeLines) && isCount(value.nodes) && typeof value.exact === 'string' && typeof value.similar === 'string';
6
+ }
7
+ function isCount(value) {
8
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
9
+ }
10
+ export function isCloneSource(value) {
11
+ return isRecord(value) && typeof value.path === 'string' && Array.isArray(value.codeLines)
12
+ && (value.scheme === undefined || typeof value.scheme === 'string' && value.scheme.length > 0)
13
+ && value.codeLines.every((line, index, lines) => isCount(line) && line > (lines[index - 1] ?? 0))
14
+ && Array.isArray(value.candidates) && value.candidates.every(isCandidate);
15
+ }
16
+ export const cloneSources = {
17
+ id: 'repometry.clone-sources/v1',
18
+ accepts: (value) => Array.isArray(value) && value.every(isCloneSource),
19
+ };
20
+ //# sourceMappingURL=clone-source.js.map
@@ -0,0 +1,45 @@
1
+ import type { DataContract } from '../engine/plugin.js';
2
+ import type { CloneSource } from './clone-source.js';
3
+ import type { SourceLineRange } from './source.js';
4
+ declare const structuralCheckIds: readonly ['function-parameters', 'return-statements', 'boolean-logic', 'nested-control-flow', 'function-complexity', 'file-complexity'];
5
+ export type StructuralCheck = typeof structuralCheckIds[number];
6
+ export declare const structureMeasures: readonly ['functions', 'cyclomaticComplexity', 'cognitiveComplexity', 'classes', 'commentLines', 'codeLines', 'duplication', 'structuralRules'];
7
+ export type StructureMeasure = typeof structureMeasures[number];
8
+ export interface FunctionComplexity {
9
+ /** Functions without a name omit this field. Reports display them as (anonymous). */
10
+ readonly name?: string;
11
+ readonly line?: number;
12
+ readonly column?: number;
13
+ readonly value: number;
14
+ }
15
+ export interface StructuralObservation {
16
+ readonly rule: StructuralCheck;
17
+ readonly value: number;
18
+ readonly label: string;
19
+ readonly line?: number;
20
+ readonly endLine?: number;
21
+ /** The qualified name of the function the observation is about or sits in. File and module observations omit it. */
22
+ readonly anchor?: string;
23
+ }
24
+ export interface CodeStructure {
25
+ readonly path: string;
26
+ readonly lines: number;
27
+ readonly functions?: number;
28
+ readonly classes?: number;
29
+ readonly cognitiveComplexity?: number;
30
+ readonly commentLines?: number;
31
+ readonly cyclomaticFunctions?: readonly FunctionComplexity[];
32
+ readonly cognitiveFunctions?: readonly FunctionComplexity[];
33
+ /** Sorted, merged lines containing code inside a function body. An empty list means the provider found none. */
34
+ readonly functionBodies?: readonly SourceLineRange[];
35
+ readonly observations?: readonly StructuralObservation[];
36
+ readonly codeLines?: readonly number[];
37
+ readonly clones?: CloneSource;
38
+ }
39
+ export declare const codeStructure: DataContract<CodeStructure>;
40
+ export declare function structureCodeLines(value: CodeStructure): readonly number[] | undefined;
41
+ /** A repository provider returns at most one structure per input path. */
42
+ export declare const codeStructures: DataContract<readonly CodeStructure[]>;
43
+ /** The structure measure that rules of a finding category need. Without it, a file skips those rules. */
44
+ export declare const ruleCategoryMeasures: Readonly<Partial<Record<string, StructureMeasure>>>;
45
+ export {};
@@ -0,0 +1,63 @@
1
+ import { isRecord } from './plugin-data.js';
2
+ import { isCloneSource } from './clone-source.js';
3
+ import { isMergedLineRanges } from './source.js';
4
+ const structuralCheckIds = [
5
+ 'function-parameters', 'return-statements', 'boolean-logic', 'nested-control-flow',
6
+ 'function-complexity', 'file-complexity',
7
+ ];
8
+ export const structureMeasures = ['functions', 'cyclomaticComplexity', 'cognitiveComplexity', 'classes',
9
+ 'commentLines', 'codeLines', 'duplication', 'structuralRules'];
10
+ const checkIds = new Set(structuralCheckIds);
11
+ function isCount(value) {
12
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
13
+ }
14
+ function isPosition(value) {
15
+ return value === undefined || (isCount(value) && value > 0);
16
+ }
17
+ function isFunctionComplexity(value) {
18
+ return isRecord(value) && (value.name === undefined || typeof value.name === 'string') && isCount(value.value)
19
+ && isPosition(value.line) && isPosition(value.column);
20
+ }
21
+ function isObservation(value) {
22
+ return isRecord(value) && typeof value.rule === 'string' && checkIds.has(value.rule) && typeof value.label === 'string'
23
+ && observedAt(value);
24
+ }
25
+ function observedAt(value) {
26
+ return isCount(value.value) && isPosition(value.line) && isPosition(value.endLine) && optionalName(value.anchor);
27
+ }
28
+ function optionalName(value) {
29
+ return value === undefined || (typeof value === 'string' && value.length > 0);
30
+ }
31
+ export const codeStructure = {
32
+ id: 'repometry.code-structure/v1',
33
+ accepts: (value) => isRecord(value)
34
+ && typeof value.path === 'string' && isCount(value.lines)
35
+ && [value.functions, value.classes, value.cognitiveComplexity, value.commentLines].every(count => count === undefined || isCount(count))
36
+ && (value.cyclomaticFunctions === undefined || Array.isArray(value.cyclomaticFunctions) && value.cyclomaticFunctions.every(isFunctionComplexity))
37
+ && (value.cognitiveFunctions === undefined || Array.isArray(value.cognitiveFunctions) && value.cognitiveFunctions.every(isFunctionComplexity))
38
+ && (value.functionBodies === undefined || isMergedLineRanges(value.functionBodies) && (value.functionBodies.at(-1)?.[1] ?? 0) <= value.lines)
39
+ && (value.observations === undefined || Array.isArray(value.observations) && value.observations.every(isObservation))
40
+ && (value.codeLines === undefined || Array.isArray(value.codeLines) && isCodeLines(value.codeLines, value.lines))
41
+ && (value.clones === undefined || isCloneSource(value.clones) && value.clones.path === value.path),
42
+ };
43
+ function isCodeLines(lines, lastLine) {
44
+ let previous = 0;
45
+ for (const line of lines) {
46
+ if (!isCount(line) || line <= previous || line > lastLine)
47
+ return false;
48
+ previous = line;
49
+ }
50
+ return true;
51
+ }
52
+ export function structureCodeLines(value) {
53
+ return value.codeLines ?? value.clones?.codeLines;
54
+ }
55
+ /** A repository provider returns at most one structure per input path. */
56
+ export const codeStructures = {
57
+ id: 'repometry.code-structures/v1',
58
+ accepts: (value) => Array.isArray(value) && value.every(codeStructure.accepts)
59
+ && new Set(value.map(({ path }) => path)).size === value.length,
60
+ };
61
+ /** The structure measure that rules of a finding category need. Without it, a file skips those rules. */
62
+ export const ruleCategoryMeasures = { structure: 'structuralRules', duplication: 'duplication' };
63
+ //# sourceMappingURL=code-structure.js.map
@@ -0,0 +1,24 @@
1
+ import type { Report } from './report.js';
2
+ export declare const comparisonSchema = "urn:repometry:schema:comparison:1";
3
+ export interface Observation {
4
+ readonly status: 'complete' | 'partial' | 'not-applicable' | 'unavailable';
5
+ readonly value: number | null;
6
+ readonly covered?: number;
7
+ readonly total?: number;
8
+ }
9
+ export interface MetricComparison {
10
+ readonly definition: string;
11
+ readonly unit: 'count' | 'percent';
12
+ readonly baseline: Observation;
13
+ readonly current: Observation;
14
+ readonly status: 'comparable' | 'incompatible' | 'unavailable';
15
+ readonly reason: 'observations-unavailable' | 'source-scope-unknown' | 'source-scope-changed' | 'method-unknown' | 'method-changed' | null;
16
+ readonly delta: number | null;
17
+ }
18
+ export type ComparisonSubject = Pick<Report, 'subject' | 'generatedAt' | 'status' | 'scope'>;
19
+ export interface InspectionComparison {
20
+ readonly schema: typeof comparisonSchema;
21
+ readonly baseline: ComparisonSubject;
22
+ readonly current: ComparisonSubject;
23
+ readonly metrics: Readonly<Record<'physicalLines' | 'functions' | 'maxCyclomaticComplexity' | 'lineCoverage', MetricComparison>>;
24
+ }
@@ -0,0 +1,2 @@
1
+ export const comparisonSchema = 'urn:repometry:schema:comparison:1';
2
+ //# sourceMappingURL=comparison.js.map
@@ -0,0 +1,12 @@
1
+ import type { DataContract } from '../engine/plugin.js';
2
+ import type { SourceLineRange } from './source.js';
3
+ export interface CoverageInput {
4
+ readonly text: string;
5
+ readonly root: string;
6
+ readonly sourceLines: ReadonlyMap<string, number>;
7
+ readonly codeLines?: ReadonlyMap<string, ReadonlySet<number>>;
8
+ readonly unclassified?: ReadonlySet<string>;
9
+ readonly functionBodies?: ReadonlyMap<string, readonly SourceLineRange[]>;
10
+ readonly excludes?: (path: string) => boolean;
11
+ }
12
+ export declare const lcovInput: DataContract<CoverageInput>;
@@ -0,0 +1,11 @@
1
+ import { isRecord } from './plugin-data.js';
2
+ export const lcovInput = {
3
+ id: 'repometry.lcov-input/v1',
4
+ accepts: (value) => isRecord(value) && typeof value.text === 'string'
5
+ && typeof value.root === 'string' && value.sourceLines instanceof Map
6
+ && (value.codeLines === undefined || value.codeLines instanceof Map)
7
+ && (value.unclassified === undefined || value.unclassified instanceof Set)
8
+ && (value.functionBodies === undefined || value.functionBodies instanceof Map)
9
+ && (value.excludes === undefined || typeof value.excludes === 'function'),
10
+ };
11
+ //# sourceMappingURL=coverage-input.js.map
@@ -0,0 +1,25 @@
1
+ import type { DataContract } from '../engine/plugin.js';
2
+ export interface FileCoverage {
3
+ readonly path: string;
4
+ readonly addedLines: number;
5
+ readonly covered: number | null;
6
+ readonly total: number | null;
7
+ }
8
+ export interface DiffCoverage {
9
+ readonly status: 'complete' | 'partial' | 'not-applicable';
10
+ readonly covered: number;
11
+ readonly total: number;
12
+ readonly percent: number | null;
13
+ readonly files: readonly FileCoverage[];
14
+ readonly gaps: readonly {
15
+ readonly path: string;
16
+ readonly reason: string;
17
+ }[];
18
+ }
19
+ export interface DiffCoverageResult extends DiffCoverage {
20
+ readonly uncovered: readonly {
21
+ readonly path: string;
22
+ readonly lines: readonly number[];
23
+ }[];
24
+ }
25
+ export declare const diffCoverageResult: DataContract<DiffCoverageResult>;
@@ -0,0 +1,10 @@
1
+ import { isRecord } from './plugin-data.js';
2
+ export const diffCoverageResult = {
3
+ id: 'repometry.diff-coverage-result/v1',
4
+ accepts: (value) => isRecord(value) && Array.isArray(value.files) && Array.isArray(value.gaps)
5
+ && Array.isArray(value.uncovered)
6
+ && (value.status === 'complete' || value.status === 'partial' || value.status === 'not-applicable')
7
+ && typeof value.covered === 'number' && typeof value.total === 'number'
8
+ && (value.percent === null || typeof value.percent === 'number'),
9
+ };
10
+ //# sourceMappingURL=diff-coverage.js.map
@@ -0,0 +1,20 @@
1
+ import type { ProvidedLanguage } from './language.js';
2
+ interface FileType extends ProvidedLanguage {
3
+ readonly names?: readonly string[];
4
+ readonly exactNames?: readonly string[];
5
+ }
6
+ export declare const javascriptType: {
7
+ readonly id: 'javascript';
8
+ readonly label: 'JavaScript';
9
+ readonly color: '#f1e05a';
10
+ readonly extensions: readonly ['.js', '.mjs', '.cjs', '.jsx'];
11
+ };
12
+ export declare const typescriptType: {
13
+ readonly id: 'typescript';
14
+ readonly label: 'TypeScript';
15
+ readonly color: '#3178c6';
16
+ readonly extensions: readonly ['.ts', '.mts', '.cts', '.tsx'];
17
+ };
18
+ export declare const fileTypes: readonly FileType[];
19
+ export declare function fileTypeId(path: string, fallback?: string): string;
20
+ export {};
@@ -0,0 +1,50 @@
1
+ import { posix } from 'node:path';
2
+ export const javascriptType = { id: 'javascript', label: 'JavaScript', color: '#f1e05a', extensions: ['.js', '.mjs', '.cjs', '.jsx'] };
3
+ export const typescriptType = { id: 'typescript', label: 'TypeScript', color: '#3178c6', extensions: ['.ts', '.mts', '.cts', '.tsx'] };
4
+ export const fileTypes = [
5
+ javascriptType, typescriptType,
6
+ { id: 'markdown', label: 'Markdown', color: '#768390', extensions: ['.md', '.mdx', '.markdown'] },
7
+ { id: 'yaml', label: 'YAML', color: '#c47d84', extensions: ['.yaml', '.yml'] },
8
+ { id: 'json', label: 'JSON', color: '#9b86b5', extensions: ['.json'] },
9
+ { id: 'css', label: 'CSS', color: '#663399', extensions: ['.css'] },
10
+ { id: 'scss', label: 'SCSS', color: '#c6538c', extensions: ['.scss'] },
11
+ { id: 'less', label: 'Less', color: '#1d365d', extensions: ['.less'] },
12
+ { id: 'html', label: 'HTML', color: '#e34c26', extensions: ['.html', '.htm'] },
13
+ { id: 'shell', label: 'Shell', color: '#89e051', extensions: ['.sh', '.bash', '.zsh', '.fish'], names: ['.bashrc', '.bash_profile'] },
14
+ { id: 'batch', label: 'Batch', color: '#788f32', extensions: ['.bat'] },
15
+ { id: 'dockerfile', label: 'Dockerfile', color: '#4f9a94', names: ['dockerfile', 'containerfile'], extensions: ['.dockerfile'] },
16
+ { id: 'python', label: 'Python', color: '#3572a5', extensions: ['.py'] },
17
+ { id: 'go', label: 'Go', color: '#00add8', extensions: ['.go'] },
18
+ { id: 'go-module', label: 'Go module', color: '#008ba8', exactNames: ['go.mod'] },
19
+ { id: 'go-checksums', label: 'Go checksums', color: '#487b91', exactNames: ['go.sum'] },
20
+ { id: 'rust', label: 'Rust', color: '#dea584', extensions: ['.rs'] },
21
+ { id: 'java', label: 'Java', color: '#b07219', extensions: ['.java'] },
22
+ { id: 'kotlin', label: 'Kotlin', color: '#a97bff', extensions: ['.kt', '.kts'] },
23
+ { id: 'ruby', label: 'Ruby', color: '#701516', extensions: ['.rb'] },
24
+ { id: 'php', label: 'PHP', color: '#4f5d95', extensions: ['.php'] },
25
+ { id: 'c-sharp', label: 'C#', color: '#178600', extensions: ['.cs'] },
26
+ { id: 'c', label: 'C', color: '#555555', extensions: ['.c', '.h'] },
27
+ { id: 'cpp', label: 'C++', color: '#f34b7d', extensions: ['.cc', '.cpp', '.cxx', '.hpp', '.hh'] },
28
+ { id: 'swift', label: 'Swift', color: '#f05138', extensions: ['.swift'] },
29
+ { id: 'scala', label: 'Scala', color: '#c22d40', extensions: ['.scala'] },
30
+ { id: 'vue', label: 'Vue', color: '#41b883', extensions: ['.vue'] },
31
+ { id: 'svelte', label: 'Svelte', color: '#ff3e00', extensions: ['.svelte'] },
32
+ { id: 'text', label: 'Plain text', color: '#7b8794', extensions: ['.txt'] },
33
+ { id: 'lockfile', label: 'Lockfile', color: '#d2c3a3', exactNames: [
34
+ 'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lock', 'bun.lockb', 'deno.lock',
35
+ 'Cargo.lock', 'Gemfile.lock', 'composer.lock', 'poetry.lock', 'Pipfile.lock', 'uv.lock', 'flake.lock',
36
+ 'mix.lock', 'pubspec.lock', 'packages.lock.json', 'gradle.lockfile',
37
+ ] },
38
+ { id: 'other', label: 'Other', exactNames: ['py.typed'] },
39
+ ];
40
+ const extensions = new Map(fileTypes.flatMap(({ id, extensions }) => extensions?.map(ext => [ext, id]) ?? []));
41
+ const names = new Map(fileTypes.flatMap(({ id, names }) => names?.map(name => [name, id]) ?? []));
42
+ const exactNames = new Map(fileTypes.flatMap(({ id, exactNames }) => exactNames?.map(name => [name, id]) ?? []));
43
+ export function fileTypeId(path, fallback) {
44
+ const basename = posix.basename(path);
45
+ const name = basename.toLowerCase();
46
+ const extension = posix.extname(name);
47
+ return exactNames.get(basename) ?? names.get(name) ?? names.get(name.split('.', 1)[0]) ?? extensions.get(extension)
48
+ ?? fallback ?? (extension.slice(1) || 'other');
49
+ }
50
+ //# sourceMappingURL=file-types.js.map
@@ -0,0 +1,8 @@
1
+ import type { Finding } from './finding.js';
2
+ import type { FindingIgnoreRule, IgnoredFinding } from './ignore-rule.js';
3
+ export type { FindingIgnoreRule, IgnoredFinding } from './ignore-rule.js';
4
+ export declare function normalizeFindingIgnore(value: unknown): readonly FindingIgnoreRule[];
5
+ export declare function partitionFindings(items: readonly Finding[], ignore: readonly FindingIgnoreRule[]): {
6
+ findings: readonly Finding[];
7
+ ignoredFindings: readonly IgnoredFinding[];
8
+ };
@@ -0,0 +1,36 @@
1
+ import { isRecord } from './plugin-data.js';
2
+ import { exclusionMatcher, normalizeExclusions } from '../profile/exclusions.js';
3
+ const fields = new Set(['tool', 'rule', 'path', 'reason']);
4
+ export function normalizeFindingIgnore(value) {
5
+ if (!Array.isArray(value))
6
+ throw new Error('Profile ignore must be an array of finding rules');
7
+ return value.map((item) => {
8
+ if (!isRecord(item) || Object.entries(item).some(([key, value]) => !fields.has(key) || typeof value !== 'string' || value.trim() === '' || /[\0\r\n]/.test(value))) {
9
+ throw new Error('Finding ignore rules accept tool, rule, path and reason strings');
10
+ }
11
+ const { tool, rule, path, reason } = item;
12
+ if (tool === undefined && rule === undefined && path === undefined) {
13
+ throw new Error('Choose at least one of tool, rule or path for a finding ignore rule');
14
+ }
15
+ return { ...(tool !== undefined && { tool }), ...(rule !== undefined && { rule }),
16
+ ...(path !== undefined && { path: normalizeExclusions([path])[0] }), ...(reason !== undefined && { reason }) };
17
+ });
18
+ }
19
+ export function partitionFindings(items, ignore) {
20
+ const findings = [];
21
+ const ignoredFindings = [];
22
+ const matches = ignore.map(({ tool, rule, path }) => {
23
+ const matchesPath = path === undefined ? undefined : exclusionMatcher([path]);
24
+ return (item) => (tool === undefined || tool === item.tool) && (rule === undefined || rule === item.rule)
25
+ && (matchesPath === undefined || (item.path !== undefined && matchesPath(item.path)));
26
+ });
27
+ for (const finding of items) {
28
+ const matchedRule = matches.findIndex(match => match(finding));
29
+ if (matchedRule < 0)
30
+ findings.push(finding);
31
+ else
32
+ ignoredFindings.push({ finding, matchedRule });
33
+ }
34
+ return { findings, ignoredFindings };
35
+ }
36
+ //# sourceMappingURL=finding-ignore.js.map
@@ -0,0 +1,34 @@
1
+ import type { DataContract } from '../engine/plugin.js';
2
+ import type { Measurement } from './measurement.js';
3
+ export declare const findingCategories: readonly ['structure', 'duplication', 'lint', 'security', 'dependency', 'secret', 'infrastructure'];
4
+ export declare const findingLevels: readonly ['low', 'medium', 'high', 'unknown'];
5
+ export interface FindingLocation {
6
+ readonly path: string;
7
+ readonly line: number;
8
+ readonly endLine: number;
9
+ }
10
+ export interface Finding {
11
+ readonly tool: string;
12
+ readonly rule: string;
13
+ readonly category: typeof findingCategories[number];
14
+ readonly level: typeof findingLevels[number];
15
+ readonly message: string;
16
+ readonly path?: string;
17
+ readonly line?: number;
18
+ readonly endLine?: number;
19
+ readonly effortMinutes?: number;
20
+ readonly related?: readonly FindingLocation[];
21
+ /** The measured value the rule judged, such as a function's cognitive complexity or a duplicate's copy count. */
22
+ readonly value?: number;
23
+ /** The value the rule allows. */
24
+ readonly limit?: number;
25
+ /** What the issue is about across commits: a function's qualified name, `(file)`, or a duplicate's fingerprint. */
26
+ readonly anchor?: string;
27
+ }
28
+ export declare function isSensitiveFinding(category: Finding['category']): boolean;
29
+ export declare function isFinding(value: unknown): value is Finding;
30
+ export interface FindingResult {
31
+ readonly measurements: readonly Measurement[];
32
+ readonly findings: readonly Finding[];
33
+ }
34
+ export declare const findingResult: DataContract<FindingResult>;
@@ -0,0 +1,45 @@
1
+ import { isRecord } from './plugin-data.js';
2
+ import { measurements } from './measurement.js';
3
+ export const findingCategories = ['structure', 'duplication', 'lint', 'security', 'dependency', 'secret', 'infrastructure'];
4
+ export const findingLevels = ['low', 'medium', 'high', 'unknown'];
5
+ export function isSensitiveFinding(category) {
6
+ return category === 'security' || category === 'dependency' || category === 'secret' || category === 'infrastructure';
7
+ }
8
+ function count(value, minimum) {
9
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= minimum;
10
+ }
11
+ function isLocation(value) {
12
+ return isRecord(value) && typeof value.path === 'string' && value.path.length > 0
13
+ && count(value.line, 1) && count(value.endLine, value.line);
14
+ }
15
+ export function isFinding(value) {
16
+ return isRecord(value) && namesIssue(value) && placesIssue(value) && measuresIssue(value);
17
+ }
18
+ function namesIssue(value) {
19
+ return text(value.tool) && text(value.rule) && text(value.message)
20
+ && findingCategories.some(category => category === value.category) && findingLevels.some(level => level === value.level);
21
+ }
22
+ function placesIssue(value) {
23
+ return optional(value.path, text) && optional(value.line, line => value.path !== undefined && count(line, 1))
24
+ && optional(value.endLine, endLine => typeof value.line === 'number' && count(endLine, value.line))
25
+ && optional(value.related, related => Array.isArray(related) && related.every(isLocation));
26
+ }
27
+ function measuresIssue(value) {
28
+ return optional(value.effortMinutes, minutes => count(minutes, 0)) && optional(value.value, measure)
29
+ && optional(value.limit, measure) && optional(value.anchor, text);
30
+ }
31
+ function optional(value, test) {
32
+ return value === undefined || test(value);
33
+ }
34
+ function text(value) {
35
+ return typeof value === 'string' && value.length > 0;
36
+ }
37
+ function measure(value) {
38
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0;
39
+ }
40
+ export const findingResult = {
41
+ id: 'repometry.findings-and-measurements/v1',
42
+ accepts: (value) => isRecord(value) && measurements.accepts(value.measurements)
43
+ && Array.isArray(value.findings) && value.findings.every(isFinding),
44
+ };
45
+ //# sourceMappingURL=finding.js.map
@@ -0,0 +1,11 @@
1
+ import type { Finding } from './finding.js';
2
+ export interface FindingIgnoreRule {
3
+ readonly tool?: string;
4
+ readonly rule?: string;
5
+ readonly path?: string;
6
+ readonly reason?: string;
7
+ }
8
+ export interface IgnoredFinding {
9
+ readonly finding: Finding;
10
+ readonly matchedRule: number;
11
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ignore-rule.js.map