@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.
- package/LICENSE +21 -0
- package/package.json +37 -2
- package/target/main/ts/engine/execute.d.ts +15 -0
- package/target/main/ts/engine/execute.js +63 -0
- package/target/main/ts/engine/manifest.d.ts +3 -0
- package/target/main/ts/engine/manifest.js +129 -0
- package/target/main/ts/engine/operation-cache.d.ts +14 -0
- package/target/main/ts/engine/operation-cache.js +66 -0
- package/target/main/ts/engine/plan.d.ts +21 -0
- package/target/main/ts/engine/plan.js +123 -0
- package/target/main/ts/engine/plugin.d.ts +71 -0
- package/target/main/ts/engine/plugin.js +3 -0
- package/target/main/ts/engine/report-products.d.ts +16 -0
- package/target/main/ts/engine/report-products.js +76 -0
- package/target/main/ts/index.d.ts +20 -0
- package/target/main/ts/index.js +8 -0
- package/target/main/ts/model/changes.d.ts +39 -0
- package/target/main/ts/model/changes.js +6 -0
- package/target/main/ts/model/churn.d.ts +11 -0
- package/target/main/ts/model/churn.js +6 -0
- package/target/main/ts/model/clone-source.d.ts +19 -0
- package/target/main/ts/model/clone-source.js +20 -0
- package/target/main/ts/model/code-structure.d.ts +45 -0
- package/target/main/ts/model/code-structure.js +63 -0
- package/target/main/ts/model/comparison.d.ts +24 -0
- package/target/main/ts/model/comparison.js +2 -0
- package/target/main/ts/model/coverage-input.d.ts +12 -0
- package/target/main/ts/model/coverage-input.js +11 -0
- package/target/main/ts/model/diff-coverage.d.ts +25 -0
- package/target/main/ts/model/diff-coverage.js +10 -0
- package/target/main/ts/model/file-types.d.ts +20 -0
- package/target/main/ts/model/file-types.js +50 -0
- package/target/main/ts/model/finding-ignore.d.ts +8 -0
- package/target/main/ts/model/finding-ignore.js +36 -0
- package/target/main/ts/model/finding.d.ts +34 -0
- package/target/main/ts/model/finding.js +45 -0
- package/target/main/ts/model/ignore-rule.d.ts +11 -0
- package/target/main/ts/model/ignore-rule.js +2 -0
- package/target/main/ts/model/language.d.ts +44 -0
- package/target/main/ts/model/language.js +31 -0
- package/target/main/ts/model/line-coverage.d.ts +15 -0
- package/target/main/ts/model/line-coverage.js +43 -0
- package/target/main/ts/model/measurement.d.ts +34 -0
- package/target/main/ts/model/measurement.js +42 -0
- package/target/main/ts/model/metric-descriptor.d.ts +17 -0
- package/target/main/ts/model/metric-descriptor.js +2 -0
- package/target/main/ts/model/plugin-data.d.ts +32 -0
- package/target/main/ts/model/plugin-data.js +16 -0
- package/target/main/ts/model/pull-review.d.ts +70 -0
- package/target/main/ts/model/pull-review.js +4 -0
- package/target/main/ts/model/quality-summary.d.ts +46 -0
- package/target/main/ts/model/quality-summary.js +92 -0
- package/target/main/ts/model/report.d.ts +45 -0
- package/target/main/ts/model/report.js +5 -0
- package/target/main/ts/model/scanner-import.d.ts +39 -0
- package/target/main/ts/model/scanner-import.js +29 -0
- package/target/main/ts/model/snapshot.d.ts +14 -0
- package/target/main/ts/model/snapshot.js +49 -0
- package/target/main/ts/model/source-locator.d.ts +7 -0
- package/target/main/ts/model/source-locator.js +2 -0
- package/target/main/ts/model/source.d.ts +31 -0
- package/target/main/ts/model/source.js +20 -0
- package/target/main/ts/ports/report.d.ts +9 -0
- package/target/main/ts/ports/report.js +2 -0
- package/target/main/ts/ports/source-provider.d.ts +14 -0
- package/target/main/ts/ports/source-provider.js +5 -0
- package/target/main/ts/ports/tool-runner.d.ts +18 -0
- package/target/main/ts/ports/tool-runner.js +2 -0
- package/target/main/ts/profile/exclusions.d.ts +11 -0
- package/target/main/ts/profile/exclusions.js +58 -0
- package/target/main/ts/profile/maintainability.d.ts +31 -0
- package/target/main/ts/profile/maintainability.js +10 -0
- package/target/main/ts/profile/profile.d.ts +4 -0
- package/target/main/ts/profile/profile.js +11 -0
- package/target/main/ts/usecases/diff-coverage-policy.d.ts +6 -0
- package/target/main/ts/usecases/diff-coverage-policy.js +11 -0
- package/target/main/ts/usecases/diff-coverage.d.ts +40 -0
- package/target/main/ts/usecases/diff-coverage.js +16 -0
- package/target/main/ts/usecases/inspect.d.ts +37 -0
- package/target/main/ts/usecases/inspect.js +42 -0
- package/target/main/ts/usecases/review-effect.d.ts +18 -0
- package/target/main/ts/usecases/review-effect.js +37 -0
- package/target/main/ts/usecases/review-match.d.ts +14 -0
- package/target/main/ts/usecases/review-match.js +72 -0
- package/target/main/ts/usecases/review-position.d.ts +14 -0
- package/target/main/ts/usecases/review-position.js +53 -0
- package/target/main/ts/usecases/review-scope.d.ts +21 -0
- package/target/main/ts/usecases/review-scope.js +41 -0
- package/target/main/ts/usecases/review.d.ts +42 -0
- package/target/main/ts/usecases/review.js +112 -0
- package/README.md +0 -4
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { StructureMeasure } from './code-structure.js';
|
|
2
|
+
export interface LanguageDisplay {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly label: string;
|
|
5
|
+
readonly color?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface LanguageLookup {
|
|
8
|
+
readonly catalog: readonly LanguageDisplay[];
|
|
9
|
+
id(path: string): string;
|
|
10
|
+
syntax?(id: string): LanguageSyntax | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* How the viewer colours a language's source: data for a scanner, not a grammar. Every field is optional; a language
|
|
14
|
+
* with no syntax shows as plain text.
|
|
15
|
+
*/
|
|
16
|
+
export interface LanguageSyntax {
|
|
17
|
+
/** Markers that start a comment running to the end of the line, such as `//` or `#`. */
|
|
18
|
+
readonly lineComments?: readonly string[];
|
|
19
|
+
/** Start and end markers of comments that may span lines, such as slash-star and star-slash. They do not nest. */
|
|
20
|
+
readonly blockComments?: readonly (readonly [start: string, end: string])[];
|
|
21
|
+
/**
|
|
22
|
+
* String forms. A string ends at the same quote that opened it. A backslash escapes the next character unless the form
|
|
23
|
+
* is raw. A form that is not multi-line ends at the end of the line.
|
|
24
|
+
*/
|
|
25
|
+
readonly strings?: readonly {
|
|
26
|
+
readonly quote: string;
|
|
27
|
+
readonly multiline?: boolean;
|
|
28
|
+
readonly raw?: boolean;
|
|
29
|
+
}[];
|
|
30
|
+
/** Letters that may stand right before a quote and belong to the string, compared without case: `r`, `b`, `f`, `rb`. */
|
|
31
|
+
readonly stringPrefixes?: readonly string[];
|
|
32
|
+
/** Words coloured as keywords, literals such as `true` and `nil` among them. Compared with case. */
|
|
33
|
+
readonly keywords?: readonly string[];
|
|
34
|
+
/** Words after which a slash opens a regular-expression literal, as in JavaScript. Without this field a slash is plain. */
|
|
35
|
+
readonly regexAfter?: readonly string[];
|
|
36
|
+
}
|
|
37
|
+
export interface ProvidedLanguage extends LanguageDisplay {
|
|
38
|
+
readonly extensions?: readonly string[];
|
|
39
|
+
readonly globs?: readonly string[];
|
|
40
|
+
readonly measures?: readonly StructureMeasure[];
|
|
41
|
+
readonly syntax?: LanguageSyntax;
|
|
42
|
+
}
|
|
43
|
+
export declare function isLanguageDisplay(value: unknown): value is LanguageDisplay;
|
|
44
|
+
export declare function isLanguageSyntax(value: unknown): value is LanguageSyntax;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isJsonValue, isRecord } from './plugin-data.js';
|
|
2
|
+
export function isLanguageDisplay(value) {
|
|
3
|
+
return isRecord(value) && typeof value.id === 'string' && /^[a-z][a-z0-9-]*$/.test(value.id)
|
|
4
|
+
&& typeof value.label === 'string' && value.label.trim().length > 0
|
|
5
|
+
&& (value.color === undefined || typeof value.color === 'string' && /^#[a-f\d]{6}$/i.test(value.color));
|
|
6
|
+
}
|
|
7
|
+
const syntaxChecks = {
|
|
8
|
+
lineComments: value => entries(value, marker),
|
|
9
|
+
blockComments: value => entries(value, pair => Array.isArray(pair) && pair.length === 2 && marker(pair[0]) && marker(pair[1])),
|
|
10
|
+
strings: value => entries(value, stringForm),
|
|
11
|
+
stringPrefixes: value => entries(value, word),
|
|
12
|
+
keywords: value => entries(value, word, 512),
|
|
13
|
+
regexAfter: value => entries(value, word),
|
|
14
|
+
};
|
|
15
|
+
export function isLanguageSyntax(value) {
|
|
16
|
+
return isRecord(value) && isJsonValue(value)
|
|
17
|
+
&& Object.entries(value).every(([key, item]) => Object.hasOwn(syntaxChecks, key) && syntaxChecks[key](item));
|
|
18
|
+
}
|
|
19
|
+
function entries(value, valid, maximum = Infinity) {
|
|
20
|
+
return Array.isArray(value) && value.length <= maximum && Array.from(value).every(valid);
|
|
21
|
+
}
|
|
22
|
+
function marker(value) {
|
|
23
|
+
return typeof value === 'string' && /^\S{1,8}$/u.test(value);
|
|
24
|
+
}
|
|
25
|
+
function word(value) {
|
|
26
|
+
return typeof value === 'string' && /^[A-Za-z_$][\w$]*$/.test(value);
|
|
27
|
+
}
|
|
28
|
+
function stringForm(value) {
|
|
29
|
+
return isRecord(value) && marker(value.quote) && Object.entries(value).every(([key, item]) => key === 'quote' || ((key === 'multiline' || key === 'raw') && typeof item === 'boolean'));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=language.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DataContract } from '../engine/plugin.js';
|
|
2
|
+
import type { SourceLineRange } from './source.js';
|
|
3
|
+
export type CoveredLineRange = SourceLineRange;
|
|
4
|
+
export type HitRun = readonly [first: number, last: number, count: number];
|
|
5
|
+
export type FunctionCallCount = readonly [line: number, calls: number];
|
|
6
|
+
export interface FileLineCoverage {
|
|
7
|
+
readonly covered: readonly CoveredLineRange[];
|
|
8
|
+
readonly uncovered: readonly CoveredLineRange[];
|
|
9
|
+
readonly partial?: readonly CoveredLineRange[];
|
|
10
|
+
readonly hits?: readonly HitRun[];
|
|
11
|
+
readonly functionCalls?: readonly FunctionCallCount[];
|
|
12
|
+
readonly functionBodies?: readonly SourceLineRange[];
|
|
13
|
+
}
|
|
14
|
+
export type LineCoverage = Readonly<Record<string, FileLineCoverage>>;
|
|
15
|
+
export declare const lcovLines: DataContract<LineCoverage>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isRecord } from './plugin-data.js';
|
|
2
|
+
import { isMergedLineRanges } from './source.js';
|
|
3
|
+
export const lcovLines = {
|
|
4
|
+
id: 'repometry.lcov-lines/v1',
|
|
5
|
+
accepts: (value) => isRecord(value) && Object.values(value).every(file => isRecord(file) && isMergedLineRanges(file.covered) && isMergedLineRanges(file.uncovered)
|
|
6
|
+
&& (file.partial === undefined || isMergedLineRanges(file.partial)) && (file.hits === undefined || isMergedHits(file.hits))
|
|
7
|
+
&& (file.functionCalls === undefined || isOrderedCallCounts(file.functionCalls))
|
|
8
|
+
&& (file.functionBodies === undefined || isMergedLineRanges(file.functionBodies))),
|
|
9
|
+
};
|
|
10
|
+
function isOrderedCallCounts(value) {
|
|
11
|
+
if (!Array.isArray(value))
|
|
12
|
+
return false;
|
|
13
|
+
let previous = 1;
|
|
14
|
+
for (const call of value) {
|
|
15
|
+
if (!Array.isArray(call) || call.length !== 2)
|
|
16
|
+
return false;
|
|
17
|
+
const [line, count] = call;
|
|
18
|
+
if (typeof line !== 'number' || typeof count !== 'number' || !Number.isSafeInteger(line) || !Number.isSafeInteger(count)
|
|
19
|
+
|| line < previous || count < 0)
|
|
20
|
+
return false;
|
|
21
|
+
previous = line;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
function isMergedHits(value) {
|
|
26
|
+
if (!Array.isArray(value))
|
|
27
|
+
return false;
|
|
28
|
+
let previousEnd = 0;
|
|
29
|
+
let previousCount = -1;
|
|
30
|
+
for (const run of value) {
|
|
31
|
+
if (!Array.isArray(run) || run.length !== 3)
|
|
32
|
+
return false;
|
|
33
|
+
const [first, last, count] = run;
|
|
34
|
+
if (typeof first !== 'number' || typeof last !== 'number' || typeof count !== 'number' || !Number.isSafeInteger(first)
|
|
35
|
+
|| !Number.isSafeInteger(last) || !Number.isSafeInteger(count) || first <= previousEnd || last < first || count < 0
|
|
36
|
+
|| (first === previousEnd + 1 && count === previousCount))
|
|
37
|
+
return false;
|
|
38
|
+
previousEnd = last;
|
|
39
|
+
previousCount = count;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=line-coverage.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DataContract } from '../engine/plugin.js';
|
|
2
|
+
export declare const definitions: {
|
|
3
|
+
readonly lines: 'repometry.physical-lines/v1';
|
|
4
|
+
readonly functions: 'repometry.functions/v1';
|
|
5
|
+
readonly complexity: 'repometry.cyclomatic-complexity/v1';
|
|
6
|
+
readonly coverage: 'repometry.lcov-line-coverage/v1';
|
|
7
|
+
readonly coveredLines: 'repometry.lcov-covered-lines/v1';
|
|
8
|
+
readonly coverableLines: 'repometry.lcov-coverable-lines/v1';
|
|
9
|
+
readonly branchCoverage: 'repometry.lcov-branch-coverage/v1';
|
|
10
|
+
readonly coveredBranches: 'repometry.lcov-covered-branches/v1';
|
|
11
|
+
readonly coverableBranches: 'repometry.lcov-coverable-branches/v1';
|
|
12
|
+
readonly functionCoverage: 'repometry.lcov-function-coverage/v1';
|
|
13
|
+
readonly coveredFunctions: 'repometry.lcov-covered-functions/v1';
|
|
14
|
+
readonly coverableFunctions: 'repometry.lcov-coverable-functions/v1';
|
|
15
|
+
readonly codeLines: 'repometry.code-lines/v1';
|
|
16
|
+
readonly comments: 'repometry.comment-lines/v1';
|
|
17
|
+
readonly classes: 'repometry.classes/v1';
|
|
18
|
+
readonly cognitiveComplexity: 'repometry.cognitive-complexity/v1';
|
|
19
|
+
readonly duplicatedLines: 'repometry.duplicated-lines/v1';
|
|
20
|
+
readonly churn: 'repometry.git-change-frequency/v1';
|
|
21
|
+
};
|
|
22
|
+
export declare function canonicalMetricId(id: string): string;
|
|
23
|
+
export interface Measurement {
|
|
24
|
+
readonly definition: string;
|
|
25
|
+
readonly target: 'repository' | 'file' | 'function';
|
|
26
|
+
readonly value: number | null;
|
|
27
|
+
readonly path?: string;
|
|
28
|
+
readonly line?: number;
|
|
29
|
+
readonly column?: number;
|
|
30
|
+
readonly name?: string;
|
|
31
|
+
readonly covered?: number;
|
|
32
|
+
readonly total?: number;
|
|
33
|
+
}
|
|
34
|
+
export declare const measurements: DataContract<readonly Measurement[]>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isRecord } from './plugin-data.js';
|
|
2
|
+
export const definitions = {
|
|
3
|
+
lines: 'repometry.physical-lines/v1',
|
|
4
|
+
functions: 'repometry.functions/v1',
|
|
5
|
+
complexity: 'repometry.cyclomatic-complexity/v1',
|
|
6
|
+
coverage: 'repometry.lcov-line-coverage/v1',
|
|
7
|
+
coveredLines: 'repometry.lcov-covered-lines/v1',
|
|
8
|
+
coverableLines: 'repometry.lcov-coverable-lines/v1',
|
|
9
|
+
branchCoverage: 'repometry.lcov-branch-coverage/v1',
|
|
10
|
+
coveredBranches: 'repometry.lcov-covered-branches/v1',
|
|
11
|
+
coverableBranches: 'repometry.lcov-coverable-branches/v1',
|
|
12
|
+
functionCoverage: 'repometry.lcov-function-coverage/v1',
|
|
13
|
+
coveredFunctions: 'repometry.lcov-covered-functions/v1',
|
|
14
|
+
coverableFunctions: 'repometry.lcov-coverable-functions/v1',
|
|
15
|
+
codeLines: 'repometry.code-lines/v1',
|
|
16
|
+
comments: 'repometry.comment-lines/v1',
|
|
17
|
+
classes: 'repometry.classes/v1',
|
|
18
|
+
cognitiveComplexity: 'repometry.cognitive-complexity/v1',
|
|
19
|
+
duplicatedLines: 'repometry.duplicated-lines/v1',
|
|
20
|
+
churn: 'repometry.git-change-frequency/v1',
|
|
21
|
+
};
|
|
22
|
+
const earlierMetricIds = new Map([
|
|
23
|
+
['repometry.cyclomatic-babel/v1', definitions.complexity],
|
|
24
|
+
['repometry.code-lines-babel/v1', definitions.codeLines],
|
|
25
|
+
['repometry.comment-lines-babel/v1', definitions.comments],
|
|
26
|
+
['repometry.classes-babel/v1', definitions.classes],
|
|
27
|
+
['repometry.cognitive-babel/v1', definitions.cognitiveComplexity],
|
|
28
|
+
['repometry.duplicated-lines-babel/v1', definitions.duplicatedLines],
|
|
29
|
+
]);
|
|
30
|
+
export function canonicalMetricId(id) {
|
|
31
|
+
return earlierMetricIds.get(id) ?? id;
|
|
32
|
+
}
|
|
33
|
+
function isMeasurement(value) {
|
|
34
|
+
return isRecord(value) && typeof value.definition === 'string'
|
|
35
|
+
&& (value.target === 'repository' || value.target === 'file' || value.target === 'function')
|
|
36
|
+
&& (value.value === null || (typeof value.value === 'number' && Number.isFinite(value.value)));
|
|
37
|
+
}
|
|
38
|
+
export const measurements = {
|
|
39
|
+
id: 'repometry.measurements/v1',
|
|
40
|
+
accepts: (value) => Array.isArray(value) && value.every(isMeasurement),
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=measurement.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type MetricScope = 'repository' | 'file' | 'function';
|
|
2
|
+
export interface MetricDescriptor {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly label: string;
|
|
5
|
+
readonly short?: string;
|
|
6
|
+
readonly description?: string;
|
|
7
|
+
readonly unit: 'count' | 'ratio' | 'minutes';
|
|
8
|
+
readonly scope: MetricScope;
|
|
9
|
+
readonly aggregate: 'sum' | 'max' | 'none';
|
|
10
|
+
readonly ratio?: {
|
|
11
|
+
readonly of: string;
|
|
12
|
+
readonly over: string;
|
|
13
|
+
};
|
|
14
|
+
readonly better: 'lower' | 'higher' | 'none';
|
|
15
|
+
readonly bands?: readonly [number, number, number, number];
|
|
16
|
+
readonly group?: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { StructureMeasure } from './code-structure.js';
|
|
2
|
+
import type { MetricDescriptor, PluginConfigSchema, RuleDescriptor } from '../engine/plugin.js';
|
|
3
|
+
import type { InventoryFile } from './source.js';
|
|
4
|
+
import type { LanguageDisplay } from './language.js';
|
|
5
|
+
export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
|
|
6
|
+
readonly [key: string]: JsonValue;
|
|
7
|
+
};
|
|
8
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
9
|
+
export declare function isJsonValue(value: unknown, depth?: number): value is JsonValue;
|
|
10
|
+
export interface PersistedProduct {
|
|
11
|
+
readonly operation: string;
|
|
12
|
+
readonly path?: string;
|
|
13
|
+
readonly value: JsonValue;
|
|
14
|
+
}
|
|
15
|
+
export interface PluginData {
|
|
16
|
+
readonly metrics: readonly MetricDescriptor[];
|
|
17
|
+
readonly measured: readonly string[];
|
|
18
|
+
readonly privateMetrics?: readonly string[];
|
|
19
|
+
readonly rules: readonly {
|
|
20
|
+
readonly plugin: string;
|
|
21
|
+
readonly rules: readonly RuleDescriptor[];
|
|
22
|
+
}[];
|
|
23
|
+
readonly products: Readonly<Record<string, readonly PersistedProduct[]>>;
|
|
24
|
+
readonly contracts?: Readonly<Record<string, PluginConfigSchema>>;
|
|
25
|
+
readonly languages?: readonly LanguageDisplay[];
|
|
26
|
+
readonly inventory?: readonly (InventoryFile & {
|
|
27
|
+
readonly language: string;
|
|
28
|
+
readonly analysed: boolean;
|
|
29
|
+
readonly provider?: string;
|
|
30
|
+
readonly unmeasured?: readonly StructureMeasure[];
|
|
31
|
+
})[];
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function isRecord(value) {
|
|
2
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
export function isJsonValue(value, depth = 0) {
|
|
5
|
+
if (depth > 512)
|
|
6
|
+
return false;
|
|
7
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'string')
|
|
8
|
+
return true;
|
|
9
|
+
if (typeof value === 'number')
|
|
10
|
+
return Number.isFinite(value);
|
|
11
|
+
if (Array.isArray(value))
|
|
12
|
+
return value.every(item => isJsonValue(item, depth + 1));
|
|
13
|
+
return isRecord(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)
|
|
14
|
+
&& Object.values(value).every(item => isJsonValue(item, depth + 1));
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=plugin-data.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Finding, FindingLocation } from './finding.js';
|
|
2
|
+
export declare const pullReviewSchema = "urn:repometry:schema:pull-review:2";
|
|
3
|
+
/** GitHub shows at most this many annotations of each kind per step. */
|
|
4
|
+
export declare const annotationLimit = 10;
|
|
5
|
+
export type IssueEffect = 'new' | 'worsened' | 'improved' | 'touched';
|
|
6
|
+
/** What a change did to one issue on the lines it changed. */
|
|
7
|
+
export interface ReviewedIssue {
|
|
8
|
+
readonly effect: IssueEffect;
|
|
9
|
+
/** The head finding, or the base finding when the change fixed it. A duplicate is placed on a changed copy. */
|
|
10
|
+
readonly finding: Finding;
|
|
11
|
+
/** The base value of a matched issue. */
|
|
12
|
+
readonly before: number | null;
|
|
13
|
+
/** The base had the issue and the head doesn't. */
|
|
14
|
+
readonly fixed: boolean;
|
|
15
|
+
/** A duplicate's other copies. */
|
|
16
|
+
readonly context: readonly FindingLocation[];
|
|
17
|
+
/** Effort minutes this change added (positive) or removed (negative). */
|
|
18
|
+
readonly debtMinutes: number;
|
|
19
|
+
}
|
|
20
|
+
export interface ReviewReason {
|
|
21
|
+
readonly message: string;
|
|
22
|
+
readonly path?: string;
|
|
23
|
+
readonly operation?: string;
|
|
24
|
+
}
|
|
25
|
+
/** What a change did on the lines it changed: issues by effect, changed-line coverage, and the two gates. */
|
|
26
|
+
export interface PullReview {
|
|
27
|
+
readonly schema: typeof pullReviewSchema;
|
|
28
|
+
readonly number: number | null;
|
|
29
|
+
readonly generatedAt: string;
|
|
30
|
+
/** The base as requested, such as `origin/main`. */
|
|
31
|
+
readonly base: string;
|
|
32
|
+
readonly mergeBase: string;
|
|
33
|
+
readonly head: string;
|
|
34
|
+
/** Files the change added, edited, renamed or deleted. */
|
|
35
|
+
readonly changedFiles: number;
|
|
36
|
+
readonly verdict: 'passed' | 'failed' | 'unmeasured';
|
|
37
|
+
readonly issues: readonly ReviewedIssue[];
|
|
38
|
+
readonly debt: {
|
|
39
|
+
readonly added: number;
|
|
40
|
+
readonly removed: number;
|
|
41
|
+
};
|
|
42
|
+
readonly coverage: {
|
|
43
|
+
readonly imported: boolean;
|
|
44
|
+
readonly covered: number;
|
|
45
|
+
readonly total: number;
|
|
46
|
+
readonly percent: number | null;
|
|
47
|
+
readonly uncovered: readonly {
|
|
48
|
+
readonly path: string;
|
|
49
|
+
readonly first: number;
|
|
50
|
+
readonly last: number;
|
|
51
|
+
}[];
|
|
52
|
+
readonly unmapped: readonly {
|
|
53
|
+
readonly path: string;
|
|
54
|
+
readonly reason: string;
|
|
55
|
+
}[];
|
|
56
|
+
readonly gate: {
|
|
57
|
+
readonly minimumPercent: number;
|
|
58
|
+
readonly minimumLines: number;
|
|
59
|
+
readonly status: 'passed' | 'failed' | 'not-applicable';
|
|
60
|
+
} | null;
|
|
61
|
+
};
|
|
62
|
+
readonly issueGate: {
|
|
63
|
+
readonly maximum: number;
|
|
64
|
+
readonly count: number;
|
|
65
|
+
readonly status: 'passed' | 'failed';
|
|
66
|
+
};
|
|
67
|
+
/** Measurements the check needs that the head lacks: the review can't vouch for the change. */
|
|
68
|
+
readonly unmeasured: readonly ReviewReason[];
|
|
69
|
+
readonly notes: readonly ReviewReason[];
|
|
70
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Report } from './report.js';
|
|
2
|
+
export type Grade = 'A' | 'B' | 'C' | 'D' | 'F';
|
|
3
|
+
export interface QualitySummary {
|
|
4
|
+
readonly codeLines: number | null;
|
|
5
|
+
readonly comments: number | null;
|
|
6
|
+
readonly classes: number | null;
|
|
7
|
+
readonly cognitiveComplexity: number | null;
|
|
8
|
+
readonly duplication: {
|
|
9
|
+
readonly duplicatedLines: number;
|
|
10
|
+
readonly codeLines: number;
|
|
11
|
+
readonly ratio: number | null;
|
|
12
|
+
} | null;
|
|
13
|
+
readonly maintainability: {
|
|
14
|
+
readonly smells: number;
|
|
15
|
+
readonly effortMinutes: number;
|
|
16
|
+
readonly debtRatio: number | null;
|
|
17
|
+
readonly grade: Grade | null;
|
|
18
|
+
readonly gradeCoverage?: {
|
|
19
|
+
readonly measuredFiles: number;
|
|
20
|
+
readonly totalFiles: number;
|
|
21
|
+
};
|
|
22
|
+
} | null;
|
|
23
|
+
}
|
|
24
|
+
interface DebtModel {
|
|
25
|
+
readonly name: 'basic-cocomo-organic';
|
|
26
|
+
readonly scale: number;
|
|
27
|
+
readonly exponent: number;
|
|
28
|
+
readonly minutesPerPersonMonth: number;
|
|
29
|
+
}
|
|
30
|
+
export declare const debtModel: DebtModel;
|
|
31
|
+
export declare function qualitySummary(report: Report): QualitySummary;
|
|
32
|
+
export declare function technicalDebtRatio(effortMinutes: number, codeLines: number, model?: DebtModel): number | null;
|
|
33
|
+
export declare function maintainabilityGrade(debtRatio: number): Grade;
|
|
34
|
+
export declare function coverageGrade(ratio: number): Grade;
|
|
35
|
+
/**
|
|
36
|
+
* Security as a grade, not a risk level: A with no findings, then B, C, D and F by the worst severity found
|
|
37
|
+
* (low or unclassified, medium, high, critical). A high risk is a low grade.
|
|
38
|
+
*/
|
|
39
|
+
export declare function securityGrade(counts: {
|
|
40
|
+
readonly critical?: number;
|
|
41
|
+
readonly high: number;
|
|
42
|
+
readonly medium: number;
|
|
43
|
+
readonly low: number;
|
|
44
|
+
readonly unknown: number;
|
|
45
|
+
}): Grade;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { isRecord } from './plugin-data.js';
|
|
2
|
+
import { canonicalMetricId, definitions } from './measurement.js';
|
|
3
|
+
export const debtModel = { name: 'basic-cocomo-organic', scale: 2.4, exponent: 1.05, minutesPerPersonMonth: 9600 };
|
|
4
|
+
export function qualitySummary(report) {
|
|
5
|
+
const files = collectFileMeasures(report);
|
|
6
|
+
const totalFiles = report.scope.files;
|
|
7
|
+
const completeTotal = (id) => totalMeasured(files.get(id), totalFiles);
|
|
8
|
+
const codeLines = completeTotal(definitions.codeLines);
|
|
9
|
+
const duplicatedLines = completeTotal(definitions.duplicatedLines);
|
|
10
|
+
return {
|
|
11
|
+
codeLines,
|
|
12
|
+
comments: completeTotal(definitions.comments),
|
|
13
|
+
classes: completeTotal(definitions.classes),
|
|
14
|
+
cognitiveComplexity: completeTotal(definitions.cognitiveComplexity),
|
|
15
|
+
duplication: duplicatedLines === null || codeLines === null ? null
|
|
16
|
+
: { duplicatedLines, codeLines, ratio: codeLines === 0 || duplicatedLines > codeLines ? null : duplicatedLines / codeLines },
|
|
17
|
+
maintainability: gradeMeasuredFiles(report, files.get(definitions.codeLines), files.get(definitions.duplicatedLines)),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function collectFileMeasures(report) {
|
|
21
|
+
const files = new Map();
|
|
22
|
+
for (const { target, path, definition, value } of report.measurements) {
|
|
23
|
+
if (target !== 'file' || path === undefined || value === null || !Number.isSafeInteger(value) || value < 0)
|
|
24
|
+
continue;
|
|
25
|
+
const id = canonicalMetricId(definition);
|
|
26
|
+
let measured = files.get(id);
|
|
27
|
+
if (!measured)
|
|
28
|
+
files.set(id, measured = new Map());
|
|
29
|
+
measured.set(path, (measured.get(path) ?? 0) + value);
|
|
30
|
+
}
|
|
31
|
+
return files;
|
|
32
|
+
}
|
|
33
|
+
function totalMeasured(values, expected) {
|
|
34
|
+
if (values?.size !== expected)
|
|
35
|
+
return null;
|
|
36
|
+
let total = 0;
|
|
37
|
+
for (const value of values.values())
|
|
38
|
+
total += value;
|
|
39
|
+
return total;
|
|
40
|
+
}
|
|
41
|
+
function gradeMeasuredFiles(report, code, duplication) {
|
|
42
|
+
if (report.findings === undefined || code === undefined)
|
|
43
|
+
return null;
|
|
44
|
+
const skipped = new Set(report.ruleSkips?.filter(({ reason }) => reason === 'unmeasured')
|
|
45
|
+
.map(({ path }) => path));
|
|
46
|
+
const measured = new Map([...code].filter(([path]) => duplication?.has(path) && !skipped.has(path)));
|
|
47
|
+
if (measured.size === 0)
|
|
48
|
+
return null;
|
|
49
|
+
const smells = report.findings.filter(finding => finding.category === 'duplication' || finding.category === 'structure');
|
|
50
|
+
const totalFiles = report.scope.files;
|
|
51
|
+
const complete = measured.size === totalFiles;
|
|
52
|
+
const eligible = complete ? smells : smells.filter(({ path }) => path !== undefined && measured.has(path));
|
|
53
|
+
const effortMinutes = eligible.reduce((sum, finding) => sum + (finding.effortMinutes ?? 0), 0);
|
|
54
|
+
const config = report.appliedConfig.maintainability;
|
|
55
|
+
const model = isRecord(config) ? readDebtModel(config.debtModel) : null;
|
|
56
|
+
const sized = totalMeasured(measured, measured.size);
|
|
57
|
+
const canGrade = complete || (report.scope.parsed === totalFiles
|
|
58
|
+
&& measured.size + skipped.size === totalFiles);
|
|
59
|
+
const debtRatio = !canGrade || !sized || model === null || eligible.some(finding => finding.effortMinutes === undefined)
|
|
60
|
+
? null : technicalDebtRatio(effortMinutes, sized, model);
|
|
61
|
+
return { smells: smells.length, effortMinutes, debtRatio, grade: debtRatio === null ? null : maintainabilityGrade(debtRatio),
|
|
62
|
+
...(!complete && debtRatio !== null ? { gradeCoverage: { measuredFiles: measured.size, totalFiles } } : {}) };
|
|
63
|
+
}
|
|
64
|
+
export function technicalDebtRatio(effortMinutes, codeLines, model = debtModel) {
|
|
65
|
+
if (codeLines <= 0)
|
|
66
|
+
return null;
|
|
67
|
+
const ratio = effortMinutes / (model.scale * (codeLines / 1000) ** model.exponent * model.minutesPerPersonMonth);
|
|
68
|
+
return Number.isFinite(ratio) ? ratio : null;
|
|
69
|
+
}
|
|
70
|
+
export function maintainabilityGrade(debtRatio) {
|
|
71
|
+
return debtRatio < 0.05 ? 'A' : debtRatio < 0.1 ? 'B' : debtRatio < 0.2 ? 'C' : debtRatio < 0.5 ? 'D' : 'F';
|
|
72
|
+
}
|
|
73
|
+
export function coverageGrade(ratio) {
|
|
74
|
+
return ratio >= 0.9 ? 'A' : ratio >= 0.8 ? 'B' : ratio >= 0.7 ? 'C' : ratio >= 0.6 ? 'D' : 'F';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Security as a grade, not a risk level: A with no findings, then B, C, D and F by the worst severity found
|
|
78
|
+
* (low or unclassified, medium, high, critical). A high risk is a low grade.
|
|
79
|
+
*/
|
|
80
|
+
export function securityGrade(counts) {
|
|
81
|
+
return counts.critical ? 'F' : counts.high ? 'D' : counts.medium ? 'C' : counts.low || counts.unknown ? 'B' : 'A';
|
|
82
|
+
}
|
|
83
|
+
function readDebtModel(model) {
|
|
84
|
+
if (!isRecord(model) || model.name !== 'basic-cocomo-organic' || !positiveNumber(model.scale)
|
|
85
|
+
|| !positiveNumber(model.exponent) || !positiveNumber(model.minutesPerPersonMonth))
|
|
86
|
+
return null;
|
|
87
|
+
return { name: model.name, scale: model.scale, exponent: model.exponent, minutesPerPersonMonth: model.minutesPerPersonMonth };
|
|
88
|
+
}
|
|
89
|
+
function positiveNumber(value) {
|
|
90
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=quality-summary.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Measurement } from './measurement.js';
|
|
2
|
+
import type { Finding } from './finding.js';
|
|
3
|
+
import type { IgnoredFinding } from './ignore-rule.js';
|
|
4
|
+
import type { PluginData } from './plugin-data.js';
|
|
5
|
+
import type { Subject } from './source.js';
|
|
6
|
+
export declare const reportSchema = "urn:repometry:schema:report:2";
|
|
7
|
+
export interface Diagnostic {
|
|
8
|
+
readonly operation: string;
|
|
9
|
+
readonly state: 'failed' | 'blocked' | 'partial';
|
|
10
|
+
readonly message: string;
|
|
11
|
+
readonly path?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface Report {
|
|
14
|
+
readonly schema: typeof reportSchema;
|
|
15
|
+
readonly subject: Subject;
|
|
16
|
+
readonly generatedAt: string;
|
|
17
|
+
readonly committedAt?: string;
|
|
18
|
+
/** The inspected commit's message title and author, recorded at analysis so the store alone can describe it. */
|
|
19
|
+
readonly commit?: {
|
|
20
|
+
readonly subject: string;
|
|
21
|
+
readonly author: {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly email: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
readonly appliedConfig: Readonly<Record<string, unknown>>;
|
|
27
|
+
readonly definitions: Readonly<Record<string, string>>;
|
|
28
|
+
readonly scope: {
|
|
29
|
+
readonly files: number;
|
|
30
|
+
readonly parsed: number;
|
|
31
|
+
};
|
|
32
|
+
readonly status: 'complete' | 'partial' | 'not-applicable';
|
|
33
|
+
readonly measurements: readonly Measurement[];
|
|
34
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
35
|
+
readonly findings?: readonly Finding[];
|
|
36
|
+
readonly ruleSkips?: readonly {
|
|
37
|
+
readonly path: string;
|
|
38
|
+
readonly plugin: string;
|
|
39
|
+
readonly rules: readonly string[];
|
|
40
|
+
readonly reason: 'unmeasured';
|
|
41
|
+
}[];
|
|
42
|
+
readonly ignoredFindings?: readonly IgnoredFinding[];
|
|
43
|
+
readonly pluginData?: PluginData;
|
|
44
|
+
}
|
|
45
|
+
export declare function validSubjectId(kind: Subject['kind'], id: string): boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Finding } from './finding.js';
|
|
2
|
+
export type FindingInput = {
|
|
3
|
+
readonly file: string;
|
|
4
|
+
readonly toolVersion?: string;
|
|
5
|
+
readonly settingsDigest?: string;
|
|
6
|
+
readonly scope?: string;
|
|
7
|
+
} & ({
|
|
8
|
+
readonly format: 'sarif';
|
|
9
|
+
readonly category: 'lint' | 'security' | 'secret';
|
|
10
|
+
} | {
|
|
11
|
+
readonly format: 'eslint';
|
|
12
|
+
readonly category: 'lint';
|
|
13
|
+
} | {
|
|
14
|
+
readonly format: 'osv';
|
|
15
|
+
readonly category: 'dependency';
|
|
16
|
+
});
|
|
17
|
+
export interface Scanner {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly version: string | null;
|
|
20
|
+
}
|
|
21
|
+
interface ImportMethod {
|
|
22
|
+
readonly format: FindingInput['format'];
|
|
23
|
+
readonly category: Finding['category'];
|
|
24
|
+
readonly tools: readonly Scanner[];
|
|
25
|
+
readonly settingsDigest: string | null;
|
|
26
|
+
readonly scope: string | null;
|
|
27
|
+
}
|
|
28
|
+
export interface ImportMetadata extends ImportMethod {
|
|
29
|
+
readonly inputDigest: string;
|
|
30
|
+
readonly reported: number;
|
|
31
|
+
readonly imported: number;
|
|
32
|
+
readonly unmapped: number;
|
|
33
|
+
readonly units: number;
|
|
34
|
+
}
|
|
35
|
+
/** Keep scanner identity in profile comparisons while dropping the per-snapshot inputs and counts. */
|
|
36
|
+
export declare function findingImportMethods(value: unknown): readonly ImportMethod[];
|
|
37
|
+
export declare function uniqueScanners(tools: readonly Scanner[]): Scanner[];
|
|
38
|
+
export declare function scannerText(value: unknown): string | undefined;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isRecord } from './plugin-data.js';
|
|
2
|
+
import { findingCategories } from './finding.js';
|
|
3
|
+
/** Keep scanner identity in profile comparisons while dropping the per-snapshot inputs and counts. */
|
|
4
|
+
export function findingImportMethods(value) {
|
|
5
|
+
if (!Array.isArray(value))
|
|
6
|
+
return [];
|
|
7
|
+
const methods = new Map();
|
|
8
|
+
for (const item of value) {
|
|
9
|
+
if (!isRecord(item) || (item.format !== 'sarif' && item.format !== 'eslint' && item.format !== 'osv'))
|
|
10
|
+
continue;
|
|
11
|
+
const category = findingCategories.find(candidate => candidate === item.category);
|
|
12
|
+
if (!category || !Array.isArray(item.tools))
|
|
13
|
+
continue;
|
|
14
|
+
const tools = item.tools.filter((tool) => isRecord(tool) && typeof tool.name === 'string'
|
|
15
|
+
&& (tool.version === null || typeof tool.version === 'string'));
|
|
16
|
+
const method = { category, format: item.format, tools: uniqueScanners(tools),
|
|
17
|
+
settingsDigest: scannerText(item.settingsDigest) ?? null, scope: scannerText(item.scope) ?? null };
|
|
18
|
+
methods.set(JSON.stringify(method), method);
|
|
19
|
+
}
|
|
20
|
+
return [...methods].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([, value]) => value);
|
|
21
|
+
}
|
|
22
|
+
export function uniqueScanners(tools) {
|
|
23
|
+
return [...new Map(tools.map(({ name, version }) => [JSON.stringify([name, version]), { name, version }]))]
|
|
24
|
+
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([, tool]) => tool);
|
|
25
|
+
}
|
|
26
|
+
export function scannerText(value) {
|
|
27
|
+
return typeof value === 'string' && value.trim() !== '' ? value : undefined;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=scanner-import.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DataContract } from '../engine/plugin.js';
|
|
2
|
+
import type { SourceFile, SourceSnapshot } from './source.js';
|
|
3
|
+
export type { Subject, SourceFile, SourceSnapshot } from './source.js';
|
|
4
|
+
export declare const sourceFile: DataContract<SourceFile>;
|
|
5
|
+
export declare const sourceFiles: DataContract<readonly SourceFile[]>;
|
|
6
|
+
export declare const sourceDirectoriesExcluded: readonly ['.git', '.repometry', 'node_modules', 'target'];
|
|
7
|
+
export declare function isExcludedDirectory(name: string): boolean;
|
|
8
|
+
export declare function digest(bytes: Uint8Array | string): string;
|
|
9
|
+
export declare function utf8(bytes: Uint8Array): string;
|
|
10
|
+
export declare function physicalLines(text: string): number;
|
|
11
|
+
export declare function sourceLineCounts(files: readonly SourceFile[]): ReadonlyMap<string, number>;
|
|
12
|
+
export declare function textLineCount(bytes: Uint8Array): number | null;
|
|
13
|
+
export declare function comparePaths(left: string, right: string): number;
|
|
14
|
+
export declare function workingSnapshot(files: SourceFile[]): SourceSnapshot;
|