repometry 0.7.0 → 0.8.1
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 +23 -20
- package/package.json +1 -1
- package/target/main/resources/config/process-plugins-v1.schema.json +4 -0
- package/target/main/resources/languages/go/parser.go +602 -0
- package/target/main/resources/languages/python/parser.py +312 -0
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +2 -1
- package/target/main/resources/viewer/files.css +1 -0
- package/target/main/ts/api/git/git-reader.d.ts +10 -2
- package/target/main/ts/api/git/git-reader.js +74 -35
- package/target/main/ts/api/git/git.d.ts +19 -1
- package/target/main/ts/api/git/git.js +97 -7
- package/target/main/ts/api/import/go-cover.d.ts +13 -0
- package/target/main/ts/api/import/go-cover.js +150 -0
- package/target/main/ts/api/import/lcov-files.d.ts +6 -1
- package/target/main/ts/api/import/lcov-files.js +27 -7
- package/target/main/ts/api/process/docker-tool-runner.js +5 -21
- package/target/main/ts/api/process/host-language-runner.d.ts +13 -0
- package/target/main/ts/api/process/host-language-runner.js +176 -0
- package/target/main/ts/api/process/plugin.d.ts +4 -1
- package/target/main/ts/api/process/plugin.js +7 -3
- package/target/main/ts/api/process/tool-snapshot.d.ts +3 -0
- package/target/main/ts/api/process/tool-snapshot.js +26 -0
- package/target/main/ts/cli/imports.d.ts +1 -0
- package/target/main/ts/cli/imports.js +5 -2
- package/target/main/ts/cli/main.js +46 -15
- package/target/main/ts/compose/analysis-files.d.ts +2 -1
- package/target/main/ts/compose/analysis-files.js +19 -5
- package/target/main/ts/compose/analysis-imports.js +2 -1
- package/target/main/ts/compose/analysis-report.d.ts +1 -0
- package/target/main/ts/compose/analysis-report.js +13 -12
- package/target/main/ts/compose/analysis-repository.d.ts +2 -1
- package/target/main/ts/compose/analysis-repository.js +42 -4
- package/target/main/ts/compose/analysis-sources.d.ts +5 -0
- package/target/main/ts/compose/analysis-sources.js +10 -3
- package/target/main/ts/compose/analyze-snapshot.d.ts +2 -1
- package/target/main/ts/compose/analyze-snapshot.js +5 -3
- package/target/main/ts/compose/diff-coverage.d.ts +2 -1
- package/target/main/ts/compose/diff-coverage.js +8 -6
- package/target/main/ts/compose/history-cache.d.ts +29 -0
- package/target/main/ts/compose/history-cache.js +57 -0
- package/target/main/ts/compose/inspect.d.ts +6 -1
- package/target/main/ts/compose/inspect.js +10 -10
- package/target/main/ts/compose/inspection-coverage.d.ts +9 -0
- package/target/main/ts/compose/inspection-coverage.js +9 -0
- package/target/main/ts/compose/languages.d.ts +6 -1
- package/target/main/ts/compose/languages.js +19 -6
- package/target/main/ts/compose/native-language-plugins.d.ts +6 -0
- package/target/main/ts/compose/native-language-plugins.js +40 -0
- package/target/main/ts/compose/plugin-list.d.ts +3 -8
- package/target/main/ts/compose/plugin-list.js +12 -5
- package/target/main/ts/compose/prepare-metabranch.js +1 -1
- package/target/main/ts/compose/process-plugins.js +6 -5
- package/target/main/ts/compose/review.d.ts +1 -2
- package/target/main/ts/compose/review.js +2 -2
- package/target/main/ts/core/engine/plan.js +5 -6
- package/target/main/ts/core/engine/plugin.d.ts +2 -0
- package/target/main/ts/core/model/file-types.d.ts +1 -0
- package/target/main/ts/core/model/file-types.js +14 -3
- package/target/main/ts/core/model/quality-summary.js +2 -0
- package/target/main/ts/core/model/source.d.ts +2 -0
- package/target/main/ts/core/usecases/inspect.d.ts +1 -1
- package/target/main/ts/core/usecases/inspect.js +1 -1
- package/target/main/ts/plugins/security/dockerfile.js +6 -15
- package/target/main/ts/report/html/app/viewer-language-bar.d.ts +2 -0
- package/target/main/ts/report/html/app/viewer-language-bar.js +5 -1
- package/target/main/ts/report/html/app/viewer-profile.js +9 -2
- package/target/main/ts/report/json/projections/commit-summary.d.ts +1 -0
- package/target/main/ts/report/json/projections/commit-summary.js +5 -0
- package/target/main/ts/report/json/projections/file-metrics.js +39 -44
- package/target/main/ts/report/json/projections/inspection-details.js +3 -2
- package/target/main/ts/report/json/store/directory.d.ts +3 -0
- package/target/main/ts/report/json/store/directory.js +19 -0
- package/target/main/ts/report/json/store/local-store.d.ts +14 -2
- package/target/main/ts/report/json/store/local-store.js +74 -60
- package/target/main/ts/report/json/store/object-store.d.ts +14 -0
- package/target/main/ts/report/json/store/object-store.js +73 -0
- package/target/main/ts/report/json/store/report-tree.d.ts +46 -0
- package/target/main/ts/report/json/store/report-tree.js +290 -0
- package/target/main/ts/report/json/store/store-check.d.ts +32 -0
- package/target/main/ts/report/json/store/store-check.js +144 -0
- package/target/main/ts/report/json/validation/report.d.ts +6 -1
- package/target/main/ts/report/json/validation/report.js +10 -4
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +1 -0
|
@@ -5,6 +5,7 @@ import type { FindingIgnoreRule } from '../core/model/finding-ignore.js';
|
|
|
5
5
|
import type { Report } from '../core/model/report.js';
|
|
6
6
|
import type { FindingInput } from '../core/model/scanner-import.js';
|
|
7
7
|
import type { AnalysisExecutor, InspectionPorts } from '../core/usecases/inspect.js';
|
|
8
|
+
import type { HistoryCache } from './history-cache.js';
|
|
8
9
|
export { analyzeSnapshot } from './analyze-snapshot.js';
|
|
9
10
|
export type { AnalysisExecutor, AnalysisInput, InspectionPorts } from '../core/usecases/inspect.js';
|
|
10
11
|
export interface InspectRequest {
|
|
@@ -16,6 +17,7 @@ export interface InspectRequest {
|
|
|
16
17
|
readonly revision: string;
|
|
17
18
|
};
|
|
18
19
|
readonly lcov?: LcovFiles;
|
|
20
|
+
readonly goCover?: LcovFiles;
|
|
19
21
|
readonly exclude?: readonly string[];
|
|
20
22
|
readonly findingInputs?: readonly FindingInput[];
|
|
21
23
|
readonly findingRoot?: string;
|
|
@@ -24,5 +26,8 @@ export interface InspectRequest {
|
|
|
24
26
|
readonly plugins?: readonly Plugin[];
|
|
25
27
|
readonly operationCache?: OperationCacheOptions;
|
|
26
28
|
}
|
|
27
|
-
export declare function inspect(request: InspectRequest, overrides?: AnalysisExecutor | Partial<InspectionPorts
|
|
29
|
+
export declare function inspect(request: InspectRequest, overrides?: AnalysisExecutor | Partial<InspectionPorts>, { history, deferSummary }?: {
|
|
30
|
+
history?: HistoryCache;
|
|
31
|
+
deferSummary?: boolean;
|
|
32
|
+
}): Promise<Report>;
|
|
28
33
|
export declare function attachFindings(report: Report, inputs: readonly FindingInput[], root: string, findingRoot: string, excludes: (path: string) => boolean): Promise<Report>;
|
|
@@ -2,37 +2,37 @@ import { resolve } from 'node:path';
|
|
|
2
2
|
import { gitTreeFiles } from '../api/git/git.js';
|
|
3
3
|
import { readInspectionSource } from '../api/git/inspection-source.js';
|
|
4
4
|
import { importFindings } from '../api/import/finding-import.js';
|
|
5
|
-
import {
|
|
5
|
+
import { readInspectionCoverage } from './inspection-coverage.js';
|
|
6
6
|
import { reportSchema } from '../core/model/report.js';
|
|
7
7
|
import { isExcludedDirectory } from '../core/model/snapshot.js';
|
|
8
8
|
import { executeInspection } from '../core/usecases/inspect.js';
|
|
9
9
|
import { LocalReportStore } from '../report/json/store/local-store.js';
|
|
10
10
|
import { analyzeSnapshot, inspectionFileMatcher } from './analyze-snapshot.js';
|
|
11
11
|
import { attachChurn } from './attach-churn.js';
|
|
12
|
-
import {
|
|
12
|
+
import { languageRegistry } from './languages.js';
|
|
13
13
|
export { analyzeSnapshot } from './analyze-snapshot.js';
|
|
14
|
-
export async function inspect(request, overrides) {
|
|
15
|
-
const { lcov, findingInputs = [], plugins = [], operationCache } = request;
|
|
14
|
+
export async function inspect(request, overrides, { history, deferSummary = false } = {}) {
|
|
15
|
+
const { lcov, goCover, findingInputs = [], plugins = [], operationCache } = request;
|
|
16
16
|
if ((plugins.length || operationCache) && (typeof overrides === 'function' || overrides?.analyze)) {
|
|
17
17
|
throw new Error('Configure plugins and the operation cache on the custom executor');
|
|
18
18
|
}
|
|
19
|
-
const languages =
|
|
19
|
+
const languages = languageRegistry(plugins);
|
|
20
20
|
const claims = inspectionFileMatcher(plugins, languages);
|
|
21
21
|
const { isSource } = languages;
|
|
22
22
|
const ports = {
|
|
23
|
-
readSource: excludes => readSource(request, excludes, isSource, claims),
|
|
24
|
-
analyze: input => analyzeSnapshot(input, plugins, operationCache),
|
|
25
|
-
...(lcov === undefined ? {} : { readCoverage:
|
|
23
|
+
readSource: excludes => readSource(request, excludes, isSource, claims, deferSummary),
|
|
24
|
+
analyze: input => analyzeSnapshot(input, plugins, operationCache, history),
|
|
25
|
+
...(lcov === undefined && goCover === undefined ? {} : { readCoverage: source => readInspectionCoverage({ lcov, goCover }, source) }),
|
|
26
26
|
...(findingInputs.length === 0 ? {} : { importFindings: (report, root, excludes) => attachFindings(report, findingInputs, root, request.findingRoot === undefined ? root : resolve(request.findingRoot), excludes) }),
|
|
27
27
|
recordChurn: (report, root, paths) => attachChurn(report, root, paths.filter(isSource)),
|
|
28
28
|
...(typeof overrides === 'function' ? { analyze: overrides } : overrides),
|
|
29
29
|
};
|
|
30
30
|
return executeInspection(request, ports);
|
|
31
31
|
}
|
|
32
|
-
async function readSource(request, excludes, isSource, claims) {
|
|
32
|
+
async function readSource(request, excludes, isSource, claims, deferSummary) {
|
|
33
33
|
const source = await readInspectionSource(request, excludes, isSource, claims);
|
|
34
34
|
const store = new LocalReportStore(source.output);
|
|
35
|
-
return { ...source, save: (report) => store.save(report) };
|
|
35
|
+
return { ...source, save: (report) => store.save(report, { deferSummary }) };
|
|
36
36
|
}
|
|
37
37
|
export async function attachFindings(report, inputs, root, findingRoot, excludes) {
|
|
38
38
|
const known = report.subject.kind === 'commit'
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CoverageInputs } from '../api/import/lcov-files.js';
|
|
2
|
+
import type { SourceSnapshot } from '../core/model/source.js';
|
|
3
|
+
export declare function readInspectionCoverage(inputs: CoverageInputs, { root, snapshot }: {
|
|
4
|
+
root: string;
|
|
5
|
+
snapshot: SourceSnapshot;
|
|
6
|
+
}): Promise<{
|
|
7
|
+
text: string;
|
|
8
|
+
inputDigests: string[];
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { gitText } from '../api/git/git.js';
|
|
2
|
+
import { readCoverageFiles } from '../api/import/lcov-files.js';
|
|
3
|
+
export function readInspectionCoverage(inputs, { root, snapshot }) {
|
|
4
|
+
const { subject } = snapshot;
|
|
5
|
+
const readCommittedManifest = subject.kind === 'commit'
|
|
6
|
+
? (path) => gitText(root, ['cat-file', 'blob', `${subject.id}:${path}`]) : undefined;
|
|
7
|
+
return readCoverageFiles(inputs, { root, snapshot, readCommittedManifest });
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=inspection-coverage.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { FileClaims, Operation, Plugin } from '../core/engine/plugin.js';
|
|
2
2
|
import { fileTypeId } from '../core/model/file-types.js';
|
|
3
3
|
import type { LanguageDisplay } from '../core/model/language.js';
|
|
4
|
+
import type { NativeLanguagePlugin } from './native-language-plugins.js';
|
|
4
5
|
export interface LanguageProvider {
|
|
5
6
|
readonly plugin: Plugin;
|
|
6
7
|
readonly operation: Operation;
|
|
@@ -16,8 +17,10 @@ export declare const defaultLanguages: {
|
|
|
16
17
|
readonly globs: readonly string[];
|
|
17
18
|
readonly catalog: readonly LanguageDisplay[];
|
|
18
19
|
readonly providers: readonly LanguageProvider[];
|
|
20
|
+
readonly native: readonly NativeLanguagePlugin[];
|
|
21
|
+
skipped(path: string): boolean;
|
|
19
22
|
};
|
|
20
|
-
export declare function languageRegistry(plugins: readonly Plugin[]): {
|
|
23
|
+
export declare function languageRegistry(plugins: readonly Plugin[], includeNative?: boolean): {
|
|
21
24
|
select(path: string): LanguageProvider | undefined;
|
|
22
25
|
isSource(path: string): boolean;
|
|
23
26
|
id(path: string): string;
|
|
@@ -25,5 +28,7 @@ export declare function languageRegistry(plugins: readonly Plugin[]): {
|
|
|
25
28
|
readonly globs: readonly string[];
|
|
26
29
|
readonly catalog: readonly LanguageDisplay[];
|
|
27
30
|
readonly providers: readonly LanguageProvider[];
|
|
31
|
+
readonly native: readonly NativeLanguagePlugin[];
|
|
32
|
+
skipped(path: string): boolean;
|
|
28
33
|
};
|
|
29
34
|
export declare function claimMatcher(claims: FileClaims | undefined, identify?: typeof fileTypeId): (path: string) => boolean;
|
|
@@ -3,11 +3,19 @@ import { fileTypeId } from '../core/model/file-types.js';
|
|
|
3
3
|
import { codeStructure, codeStructures } from '../core/model/code-structure.js';
|
|
4
4
|
import { isExcludedDirectory } from '../core/model/snapshot.js';
|
|
5
5
|
import { exclusionMatcher } from '../core/profile/exclusions.js';
|
|
6
|
+
import { nativeLanguagePlugins } from './native-language-plugins.js';
|
|
6
7
|
import { restrictStructureMeasures } from './structure-measures.js';
|
|
7
8
|
import { babelProvider } from '../plugins/language-js/babel-provider.js';
|
|
8
|
-
export const defaultLanguages = languageRegistry([]);
|
|
9
|
-
export function languageRegistry(plugins) {
|
|
10
|
-
const
|
|
9
|
+
export const defaultLanguages = languageRegistry([], false);
|
|
10
|
+
export function languageRegistry(plugins, includeNative = true) {
|
|
11
|
+
const languagePlugins = plugins.filter(plugin => plugin.kinds?.includes('language'));
|
|
12
|
+
const configured = new Set(languagePlugins.flatMap(plugin => plugin.providesLanguages?.map(language => language.id) ?? []));
|
|
13
|
+
const native = includeNative ? nativeLanguagePlugins().filter(plugin => plugin.providesLanguages?.every(language => !configured.has(language.id))) : [];
|
|
14
|
+
const nativeIds = new Set(native.map(({ id }) => id));
|
|
15
|
+
const unavailable = native.filter(plugin => plugin.unavailableReason !== undefined).flatMap(plugin => plugin.providesLanguages ?? []);
|
|
16
|
+
const skippedClaims = unavailable.map(claim => claimMatcher(claim));
|
|
17
|
+
const enabled = native.filter(plugin => plugin.unavailableReason === undefined);
|
|
18
|
+
const entries = [babelProvider, ...languagePlugins, ...enabled].map(plugin => {
|
|
11
19
|
const operations = plugin.operations.filter(operation => operation.role === 'provider'
|
|
12
20
|
&& operation.output.id === (operation.scope === 'repository' ? codeStructures.id : codeStructure.id));
|
|
13
21
|
const [operation] = operations;
|
|
@@ -33,7 +41,7 @@ export function languageRegistry(plugins) {
|
|
|
33
41
|
const claims = declared.length ? declared : [plugin.claims];
|
|
34
42
|
return { provider, claims, matches: declared.length ? (path) => language(path) !== undefined : claimMatcher(plugin.claims) };
|
|
35
43
|
});
|
|
36
|
-
const claims = entries.flatMap(entry => entry.claims);
|
|
44
|
+
const claims = [...entries.flatMap(entry => entry.claims), ...unavailable];
|
|
37
45
|
const extensions = [...new Set(claims.flatMap(entry => entry.extensions ?? []))];
|
|
38
46
|
const globs = [...new Set(claims.flatMap(entry => entry.globs ?? []))];
|
|
39
47
|
const providers = entries.map(({ provider }) => provider);
|
|
@@ -42,8 +50,11 @@ export function languageRegistry(plugins) {
|
|
|
42
50
|
})));
|
|
43
51
|
if (new Set(catalog.map(({ id }) => id)).size !== catalog.length)
|
|
44
52
|
throw new Error('Duplicate provided language ID');
|
|
45
|
-
return { select, isSource: path => select(path) !== undefined, id: path => select(path)?.language(path) ?? fileTypeId(path), extensions, globs,
|
|
46
|
-
catalog, providers };
|
|
53
|
+
return { select, isSource: path => select(path) !== undefined || skipped(path), id: path => select(path)?.language(path) ?? fileTypeId(path), extensions, globs,
|
|
54
|
+
catalog, providers, native, skipped };
|
|
55
|
+
function skipped(path) {
|
|
56
|
+
return skippedClaims.some(matches => matches(path)) && !path.split('/').slice(0, -1).some(isExcludedDirectory);
|
|
57
|
+
}
|
|
47
58
|
function select(path) {
|
|
48
59
|
let selected;
|
|
49
60
|
for (const { provider, matches } of entries) {
|
|
@@ -51,6 +62,8 @@ export function languageRegistry(plugins) {
|
|
|
51
62
|
continue;
|
|
52
63
|
if (!selected && path.split('/').slice(0, -1).some(isExcludedDirectory))
|
|
53
64
|
return undefined;
|
|
65
|
+
if (selected && nativeIds.has(provider.plugin.id))
|
|
66
|
+
continue;
|
|
54
67
|
if (selected)
|
|
55
68
|
throw new Error(`Multiple language providers claim ${path}: ${selected.plugin.id}, ${provider.plugin.id}`);
|
|
56
69
|
selected = provider;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Plugin } from '../core/engine/plugin.js';
|
|
2
|
+
export interface NativeLanguagePlugin extends Plugin {
|
|
3
|
+
readonly unavailableReason?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const nativeLanguageIds: ("go-ast" | "python-ast")[];
|
|
6
|
+
export declare function nativeLanguagePlugins(): readonly NativeLanguagePlugin[];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { HostLanguageRunner, hostToolPath, hostToolVersion } from '../api/process/host-language-runner.js';
|
|
4
|
+
import { bindProcessPlugin } from '../api/process/plugin.js';
|
|
5
|
+
import { pluginApi } from '../core/engine/plugin.js';
|
|
6
|
+
import { codeStructures } from '../core/model/code-structure.js';
|
|
7
|
+
import { fileTypes } from '../core/model/file-types.js';
|
|
8
|
+
import { duplicationSettings } from '../core/profile/maintainability.js';
|
|
9
|
+
import { digest, sourceFiles } from '../core/model/snapshot.js';
|
|
10
|
+
const measures = ['functions', 'cyclomaticComplexity', 'cognitiveComplexity', 'commentLines', 'codeLines',
|
|
11
|
+
'structuralRules', 'duplication'];
|
|
12
|
+
const descriptors = [
|
|
13
|
+
{ id: 'go-ast', language: 'go', binary: 'go', args: ['run'], versionArgs: ['version'], script: 'go/parser.go', measures },
|
|
14
|
+
{ id: 'python-ast', language: 'python', binary: 'python3', args: ['-I', '-S'], versionArgs: ['--version'],
|
|
15
|
+
script: 'python/parser.py', measures: [...measures, 'classes'] },
|
|
16
|
+
];
|
|
17
|
+
export const nativeLanguageIds = descriptors.map(({ id }) => id);
|
|
18
|
+
let cached;
|
|
19
|
+
export function nativeLanguagePlugins() {
|
|
20
|
+
const path = hostToolPath();
|
|
21
|
+
if (cached?.path !== path)
|
|
22
|
+
cached = { path, plugins: descriptors.map(descriptor => createPlugin(descriptor, path)) };
|
|
23
|
+
return cached.plugins;
|
|
24
|
+
}
|
|
25
|
+
function createPlugin({ id, language, binary, args, versionArgs, script, measures }, path) {
|
|
26
|
+
const declaration = { ...fileTypes.find(type => type.id === language), measures };
|
|
27
|
+
const manifest = { id, version: '1.1.0', api: pluginApi, kinds: ['language'],
|
|
28
|
+
settings: { duplication: duplicationSettings },
|
|
29
|
+
providesLanguages: [declaration], produces: [{ contract: codeStructures.id, persistence: 'transient' }] };
|
|
30
|
+
const version = hostToolVersion(binary, versionArgs, path)?.match(/\b(?:go|Python\s+)(\d+(?:\.\d+)+(?:[a-z][\w.-]*)?)/i)?.[1];
|
|
31
|
+
if (version === undefined) {
|
|
32
|
+
return { ...manifest, operations: [], unavailableReason: `${binary} not found on PATH` };
|
|
33
|
+
}
|
|
34
|
+
const parser = fileURLToPath(new URL(`../resources/languages/${script}`, import.meta.resolve('repometry/plugin')));
|
|
35
|
+
return bindProcessPlugin({ ...manifest, tools: { [binary]: version }, operations: [{ id: 'parse', role: 'provider',
|
|
36
|
+
scope: 'repository', fileIndependent: true, inputs: { files: sourceFiles }, output: codeStructures,
|
|
37
|
+
argv: [binary, ...args], timeoutMs: 90_000, maxOutputBytes: 16 * 1024 * 1024, implementation: digest(readFileSync(parser)),
|
|
38
|
+
}] }, new HostLanguageRunner(path, parser));
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=native-language-plugins.js.map
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import type { Plugin } from '../core/engine/plugin.js';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const builtInPluginIds: Set<string>;
|
|
3
|
+
export declare function effectivePlugins(additional: readonly Plugin[]): {
|
|
3
4
|
id: string;
|
|
4
5
|
version: string;
|
|
5
6
|
kinds: readonly import("../core/engine/plugin.js").PluginKind[];
|
|
6
7
|
claims?: import("../core/engine/plugin.js").FileClaims | undefined;
|
|
7
8
|
providesLanguages?: readonly import("../plugin.js").ProvidedLanguage[] | undefined;
|
|
9
|
+
unavailableReason?: string | undefined;
|
|
8
10
|
}[];
|
|
9
|
-
export declare function describePlugin({ id, version, kinds, claims, providesLanguages }: Pick<Plugin, 'id' | 'version' | 'kinds' | 'claims' | 'providesLanguages'>): {
|
|
10
|
-
id: string;
|
|
11
|
-
version: string;
|
|
12
|
-
kinds: readonly import("../core/engine/plugin.js").PluginKind[];
|
|
13
|
-
claims?: import("../core/engine/plugin.js").FileClaims | undefined;
|
|
14
|
-
providesLanguages?: readonly import("../plugin.js").ProvidedLanguage[] | undefined;
|
|
15
|
-
};
|
|
@@ -3,12 +3,19 @@ import { diffCoverage } from '../plugins/coverage/diff-coverage.js';
|
|
|
3
3
|
import { duplication } from '../plugins/duplication/duplication.js';
|
|
4
4
|
import { maintainability } from '../plugins/maintainability/maintainability.js';
|
|
5
5
|
import { structure } from '../plugins/structure/structure.js';
|
|
6
|
-
import {
|
|
6
|
+
import { nativeLanguageIds } from './native-language-plugins.js';
|
|
7
|
+
import { defaultLanguages, languageRegistry } from './languages.js';
|
|
7
8
|
import { sourceProviders } from './sources.js';
|
|
8
9
|
import { securityPlugins } from './security-plugins.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
|
|
10
|
+
const builtInPlugins = [...defaultLanguages.providers.map(({ plugin }) => plugin), structure, maintainability, duplication, coverage,
|
|
11
|
+
diffCoverage, ...securityPlugins, ...sourceProviders];
|
|
12
|
+
export const builtInPluginIds = new Set([...builtInPlugins.map(({ id }) => id), ...nativeLanguageIds]);
|
|
13
|
+
export function effectivePlugins(additional) {
|
|
14
|
+
const native = languageRegistry(additional).native.map(plugin => ({ ...describePlugin(plugin), ...(plugin.tools ? { tools: plugin.tools } : {}) }));
|
|
15
|
+
return [...builtInPlugins.map(describePlugin), ...native, ...additional.map(describePlugin)];
|
|
16
|
+
}
|
|
17
|
+
function describePlugin({ id, version, kinds, claims, providesLanguages, unavailableReason }) {
|
|
18
|
+
return { id, version, kinds, ...(claims ? { claims } : {}), ...(providesLanguages ? { providesLanguages } : {}),
|
|
19
|
+
...(unavailableReason ? { unavailableReason } : {}) };
|
|
13
20
|
}
|
|
14
21
|
//# sourceMappingURL=plugin-list.js.map
|
|
@@ -12,6 +12,6 @@ export async function prepareMetabranch({ repository, worktree, branch, report }
|
|
|
12
12
|
}
|
|
13
13
|
const target = await openMetabranchWorktree(repository, worktree, branch, report.subject.id);
|
|
14
14
|
await new LocalReportStore(target).save(report);
|
|
15
|
-
return ['manifest.json', 'summary.json', `commits/${report.subject.id}/report.json`];
|
|
15
|
+
return ['manifest.json', 'summary.json', 'objects', `commits/${report.subject.id}/report.json`];
|
|
16
16
|
}
|
|
17
17
|
//# sourceMappingURL=prepare-metabranch.js.map
|
|
@@ -6,7 +6,7 @@ import { pluginApi } from '../core/engine/plugin.js';
|
|
|
6
6
|
import { codeStructure, codeStructures } from '../core/model/code-structure.js';
|
|
7
7
|
import { sourceFile, sourceFiles } from '../core/model/snapshot.js';
|
|
8
8
|
import { languageRegistry } from './languages.js';
|
|
9
|
-
import {
|
|
9
|
+
import { builtInPluginIds } from './plugin-list.js';
|
|
10
10
|
let check;
|
|
11
11
|
export function readProcessPlugins(value) {
|
|
12
12
|
if (value === undefined)
|
|
@@ -16,17 +16,18 @@ export function readProcessPlugins(value) {
|
|
|
16
16
|
const error = validate.errors?.[0];
|
|
17
17
|
throw new Error(`Config plugins${error?.instancePath ?? ''} ${error?.message ?? 'is invalid'}`);
|
|
18
18
|
}
|
|
19
|
-
const ids = new Set(
|
|
19
|
+
const ids = new Set(builtInPluginIds);
|
|
20
20
|
const plugins = value.map((definition, index) => {
|
|
21
21
|
if (ids.has(definition.id))
|
|
22
22
|
throw new Error(`Config plugins/${index}/id duplicates plugin ${definition.id}`);
|
|
23
23
|
ids.add(definition.id);
|
|
24
24
|
return configuredPlugin(definition, index);
|
|
25
25
|
});
|
|
26
|
-
languageRegistry(plugins);
|
|
26
|
+
languageRegistry(plugins, false);
|
|
27
27
|
return plugins;
|
|
28
28
|
}
|
|
29
|
-
function configuredPlugin(
|
|
29
|
+
function configuredPlugin(definition, index) {
|
|
30
|
+
const { id, version, image, command, scope, fileIndependent, claims, limits = {}, tools, settings, providesLanguages } = definition;
|
|
30
31
|
const base = `Config plugins/${index}`;
|
|
31
32
|
if (!command[0]?.trim())
|
|
32
33
|
throw new Error(`${base}/command/0 must name an executable`);
|
|
@@ -43,7 +44,7 @@ function configuredPlugin({ id, version, image, command, scope, claims, limits =
|
|
|
43
44
|
return processPlugin({ id, version, api: pluginApi, kinds: ['language'], tools, claims: effective, providesLanguages: languages,
|
|
44
45
|
...(settings === undefined ? {} : { settings }),
|
|
45
46
|
produces: [{ contract: output.id, persistence: 'transient' }],
|
|
46
|
-
operations: [{ id: 'parse', role: 'provider', scope, inputs: repository ? { files: sourceFiles } : { source: sourceFile },
|
|
47
|
+
operations: [{ id: 'parse', role: 'provider', scope, fileIndependent, inputs: repository ? { files: sourceFiles } : { source: sourceFile },
|
|
47
48
|
output, argv: command, timeoutMs: limits.timeoutMs ?? 30_000, maxOutputBytes: limits.maxOutputBytes ?? 8 * 1024 * 1024 }],
|
|
48
49
|
}, new DockerToolRunner(image, { memoryBytes: limits.memoryBytes ?? 512 * 1024 * 1024, pidsLimit: limits.pidsLimit ?? 128 }));
|
|
49
50
|
}
|
|
@@ -3,8 +3,7 @@ import type { ReportReader } from '../core/ports/report.js';
|
|
|
3
3
|
import type { ReviewPorts } from '../core/usecases/review.js';
|
|
4
4
|
import type { DiffCoverageRequest } from './diff-coverage.js';
|
|
5
5
|
export { projectReview, reviewExitCode } from '../core/usecases/review.js';
|
|
6
|
-
export interface ReviewRequest extends
|
|
7
|
-
readonly lcov?: DiffCoverageRequest['lcov'];
|
|
6
|
+
export interface ReviewRequest extends DiffCoverageRequest {
|
|
8
7
|
readonly number?: number;
|
|
9
8
|
readonly minimumLines?: number;
|
|
10
9
|
readonly maxCoverageDrop?: number;
|
|
@@ -13,7 +13,7 @@ export async function reviewPull(request, current, baseline = current) {
|
|
|
13
13
|
}
|
|
14
14
|
export async function review(request, overrides) {
|
|
15
15
|
const store = new LocalReportStore(resolve(request.output ?? resolve(request.directory, '.repometry')));
|
|
16
|
-
const { lcov } = request;
|
|
16
|
+
const { lcov, goCover } = request;
|
|
17
17
|
return executeReview(request, {
|
|
18
18
|
readHead: id => readIfAvailable(store, id),
|
|
19
19
|
readBase: id => readIfAvailable(store, id),
|
|
@@ -22,7 +22,7 @@ export async function review(request, overrides) {
|
|
|
22
22
|
const [head, base] = await Promise.all([resolveGitCommit(directory, request.revision), resolveGitCommit(directory, request.base)]);
|
|
23
23
|
return { head, base, mergeBase: () => findMergeBase(directory, base, head) };
|
|
24
24
|
},
|
|
25
|
-
...(lcov === undefined ? {} : { measureChanged: () => measureChangedLines(
|
|
25
|
+
...(lcov === undefined && goCover === undefined ? {} : { measureChanged: () => measureChangedLines(request) }),
|
|
26
26
|
...overrides,
|
|
27
27
|
});
|
|
28
28
|
}
|
|
@@ -74,12 +74,11 @@ function indexOperations(plugins) {
|
|
|
74
74
|
throw new Error(`Invalid or duplicate plugin ID: ${plugin.id}`);
|
|
75
75
|
ids.add(plugin.id);
|
|
76
76
|
const products = manifestProducts(plugin);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
77
|
+
const hasSettings = plugin.settings !== undefined;
|
|
78
|
+
if (hasSettings && !isJsonValue(plugin.settings))
|
|
79
|
+
throw new Error(`Plugin settings must be JSON data: ${plugin.id}`);
|
|
80
|
+
if (hasSettings && plugin.config !== undefined && !new Ajv2020().validate(plugin.config, plugin.settings)) {
|
|
81
|
+
throw new Error(`Plugin settings violate the configuration schema: ${plugin.id}`);
|
|
83
82
|
}
|
|
84
83
|
for (const declaration of products.values()) {
|
|
85
84
|
for (const metric of declaration.metrics ?? []) {
|
|
@@ -20,6 +20,8 @@ export interface Operation {
|
|
|
20
20
|
readonly id: string;
|
|
21
21
|
readonly role: 'provider' | 'inspection';
|
|
22
22
|
readonly scope?: 'file' | 'repository';
|
|
23
|
+
/** A repository provider produces the same results and diagnostics for each file regardless of which siblings it receives. */
|
|
24
|
+
readonly fileIndependent?: boolean;
|
|
23
25
|
readonly inputs: Readonly<Record<string, DataContract>>;
|
|
24
26
|
readonly output: DataContract;
|
|
25
27
|
/** Fingerprint for executable details that the declared versions and inputs do not carry. */
|
|
@@ -10,10 +10,13 @@ export const fileTypes = [
|
|
|
10
10
|
{ id: 'scss', label: 'SCSS', color: '#c6538c', extensions: ['.scss'] },
|
|
11
11
|
{ id: 'less', label: 'Less', color: '#1d365d', extensions: ['.less'] },
|
|
12
12
|
{ id: 'html', label: 'HTML', color: '#e34c26', extensions: ['.html', '.htm'] },
|
|
13
|
-
{ id: 'shell', label: 'Shell', color: '#89e051', extensions: ['.sh', '.bash'], names: ['.bashrc', '.bash_profile'] },
|
|
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'] },
|
|
14
15
|
{ id: 'dockerfile', label: 'Dockerfile', color: '#4f9a94', names: ['dockerfile', 'containerfile'], extensions: ['.dockerfile'] },
|
|
15
16
|
{ id: 'python', label: 'Python', color: '#3572a5', extensions: ['.py'] },
|
|
16
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'] },
|
|
17
20
|
{ id: 'rust', label: 'Rust', color: '#dea584', extensions: ['.rs'] },
|
|
18
21
|
{ id: 'java', label: 'Java', color: '#b07219', extensions: ['.java'] },
|
|
19
22
|
{ id: 'kotlin', label: 'Kotlin', color: '#a97bff', extensions: ['.kt', '.kts'] },
|
|
@@ -27,13 +30,21 @@ export const fileTypes = [
|
|
|
27
30
|
{ id: 'vue', label: 'Vue', color: '#41b883', extensions: ['.vue'] },
|
|
28
31
|
{ id: 'svelte', label: 'Svelte', color: '#ff3e00', extensions: ['.svelte'] },
|
|
29
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'] },
|
|
30
39
|
];
|
|
31
40
|
const extensions = new Map(fileTypes.flatMap(({ id, extensions }) => extensions?.map(ext => [ext, id]) ?? []));
|
|
32
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]) ?? []));
|
|
33
43
|
export function fileTypeId(path, fallback) {
|
|
34
|
-
const
|
|
44
|
+
const basename = posix.basename(path);
|
|
45
|
+
const name = basename.toLowerCase();
|
|
35
46
|
const extension = posix.extname(name);
|
|
36
|
-
return names.get(name) ?? names.get(name.split('.', 1)[0]) ?? extensions.get(extension)
|
|
47
|
+
return exactNames.get(basename) ?? names.get(name) ?? names.get(name.split('.', 1)[0]) ?? extensions.get(extension)
|
|
37
48
|
?? fallback ?? (extension.slice(1) || 'other');
|
|
38
49
|
}
|
|
39
50
|
//# sourceMappingURL=file-types.js.map
|
|
@@ -44,6 +44,8 @@ function gradeMeasuredFiles(report, code, duplication) {
|
|
|
44
44
|
const skipped = new Set(report.ruleSkips?.filter(({ plugin }) => plugin === 'maintainability' || plugin === 'duplication')
|
|
45
45
|
.map(({ path }) => path));
|
|
46
46
|
const measured = new Map([...code].filter(([path]) => duplication?.has(path) && !skipped.has(path)));
|
|
47
|
+
if (measured.size === 0)
|
|
48
|
+
return null;
|
|
47
49
|
const smells = report.findings.filter(finding => finding.category === 'duplication' || finding.category === 'structure');
|
|
48
50
|
const totalFiles = report.scope.files;
|
|
49
51
|
const complete = measured.size === totalFiles;
|
|
@@ -23,6 +23,8 @@ export interface InventoryFile {
|
|
|
23
23
|
export interface SourceSnapshot {
|
|
24
24
|
readonly subject: Subject;
|
|
25
25
|
readonly files: readonly SourceFile[];
|
|
26
|
+
/** Object IDs from the immutable Git tree, keyed by repository-relative path. */
|
|
27
|
+
readonly blobIds?: ReadonlyMap<string, string>;
|
|
26
28
|
readonly inventory?: readonly InventoryFile[];
|
|
27
29
|
readonly generatedExcluded?: readonly string[];
|
|
28
30
|
readonly oversizedClaims?: readonly string[];
|
|
@@ -26,7 +26,7 @@ interface InspectionCoverage {
|
|
|
26
26
|
export interface InspectionPorts {
|
|
27
27
|
readSource(excludes: Excludes): Promise<InspectionSource>;
|
|
28
28
|
readonly analyze: AnalysisExecutor;
|
|
29
|
-
readCoverage?(): Promise<InspectionCoverage>;
|
|
29
|
+
readCoverage?(source: Pick<InspectionSource, 'root' | 'snapshot'>): Promise<InspectionCoverage>;
|
|
30
30
|
importFindings?(report: Report, root: string, excludes: Excludes): Promise<Report>;
|
|
31
31
|
recordChurn?(report: Report, root: string, paths: readonly string[]): Promise<Report>;
|
|
32
32
|
}
|
|
@@ -9,7 +9,7 @@ export async function executeInspection(options, ports) {
|
|
|
9
9
|
const ignore = normalizeFindingIgnore(options.ignore ?? []);
|
|
10
10
|
const source = await ports.readSource(sourceExclusionMatcher(excludedPaths));
|
|
11
11
|
const { snapshot, root, excludedOutput } = source;
|
|
12
|
-
const lcov = await ports.readCoverage?.();
|
|
12
|
+
const lcov = await ports.readCoverage?.(source);
|
|
13
13
|
const report = await ports.analyze({
|
|
14
14
|
snapshot, excludedOutput, excludedPaths,
|
|
15
15
|
coverage: lcov === undefined ? undefined : { text: lcov.text, sourceRoot: root },
|
|
@@ -392,6 +392,7 @@ function pipelines(script) {
|
|
|
392
392
|
const char = script[index];
|
|
393
393
|
const previous = script[index - 1];
|
|
394
394
|
const next = script[index + 1];
|
|
395
|
+
const controlOperator = (char === '&' || char === '|') && previous !== '>' && previous !== '<' && next !== '>';
|
|
395
396
|
if (quote !== '') {
|
|
396
397
|
if (char === quote)
|
|
397
398
|
quote = '';
|
|
@@ -419,25 +420,15 @@ function pipelines(script) {
|
|
|
419
420
|
else if (char === '\n' || char === ';') {
|
|
420
421
|
endPipeline();
|
|
421
422
|
}
|
|
422
|
-
else if (
|
|
423
|
-
word += char;
|
|
424
|
-
started = true;
|
|
425
|
-
}
|
|
426
|
-
else if (char === '&') {
|
|
423
|
+
else if (controlOperator && char === '|' && next !== '|') {
|
|
427
424
|
if (next === '&')
|
|
428
425
|
index++;
|
|
429
|
-
|
|
426
|
+
endCommand();
|
|
430
427
|
}
|
|
431
|
-
else if (
|
|
432
|
-
if (next ===
|
|
428
|
+
else if (controlOperator) {
|
|
429
|
+
if (next === char)
|
|
433
430
|
index++;
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
else {
|
|
437
|
-
if (next === '&')
|
|
438
|
-
index++;
|
|
439
|
-
endCommand();
|
|
440
|
-
}
|
|
431
|
+
endPipeline();
|
|
441
432
|
}
|
|
442
433
|
else if (/\s/.test(char) || char === '(' || char === ')') {
|
|
443
434
|
endWord();
|
|
@@ -2,6 +2,8 @@ import type { Clause } from './viewer-filter.js';
|
|
|
2
2
|
import type { Metrics } from './viewer-inspection.js';
|
|
3
3
|
/** The query with a language's chip pressed or released. */
|
|
4
4
|
export declare function toggleLanguage(clauses: readonly Clause[], language: string): Clause[];
|
|
5
|
+
/** A share too small to round to 0.1% still reads as present, not as 0%. */
|
|
6
|
+
export declare function shareText(ratio: number): string;
|
|
5
7
|
/**
|
|
6
8
|
* The languages of the selection as one bar, with a legend whose names toggle their chips in the query. Nothing shows
|
|
7
9
|
* for a single language or no weight at all.
|
|
@@ -27,6 +27,10 @@ export function toggleLanguage(clauses, language) {
|
|
|
27
27
|
return clauses.filter(other => other.kind !== clause.kind);
|
|
28
28
|
return clauses.filter(other => !(other.kind === 'lang' && other.value.toLowerCase() === language.toLowerCase()));
|
|
29
29
|
}
|
|
30
|
+
/** A share too small to round to 0.1% still reads as present, not as 0%. */
|
|
31
|
+
export function shareText(ratio) {
|
|
32
|
+
return ratio > 0 && ratio < 0.0005 ? `<${percent(0.001)}` : percent(ratio);
|
|
33
|
+
}
|
|
30
34
|
function chip(language, share, color, pressed) {
|
|
31
35
|
const category = categories.get(language);
|
|
32
36
|
const toggle = element('button', category ? `fx-language ${category.className}` : 'fx-language');
|
|
@@ -62,7 +66,7 @@ export function renderLanguages(container, files, clauses, set) {
|
|
|
62
66
|
segment.style.flexGrow = String(weight);
|
|
63
67
|
segment.style.background = color;
|
|
64
68
|
bar.append(segment);
|
|
65
|
-
const toggle = chip(language,
|
|
69
|
+
const toggle = chip(language, shareText(weight / total), color, pressed);
|
|
66
70
|
toggle.addEventListener('click', () => set(toggleLanguage(clauses, language)));
|
|
67
71
|
legend.append(toggle);
|
|
68
72
|
}
|
|
@@ -50,7 +50,10 @@ function identity(profile) {
|
|
|
50
50
|
section.append(facts);
|
|
51
51
|
return section;
|
|
52
52
|
}
|
|
53
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* The languages the plugins claim, each with the patterns of the files it reads; an older inspection did not record
|
|
55
|
+
* them. A language whose tool could not run says why, e.g. "go not found on PATH": its files were not analysed.
|
|
56
|
+
*/
|
|
54
57
|
function claims(languages) {
|
|
55
58
|
if (!languages)
|
|
56
59
|
return none('Not recorded for this inspection');
|
|
@@ -59,7 +62,11 @@ function claims(languages) {
|
|
|
59
62
|
const list = element('ul', 'profile-claims');
|
|
60
63
|
list.append(...languages.map(language => {
|
|
61
64
|
const item = element('li');
|
|
62
|
-
|
|
65
|
+
const patterns = element('div', 'profile-claim-patterns');
|
|
66
|
+
patterns.append(chips([...language.extensions.map(extension => `**/*${extension}`), ...language.globs]));
|
|
67
|
+
if (language.unavailableReason)
|
|
68
|
+
patterns.append(none(`Not analysed: ${language.unavailableReason}`));
|
|
69
|
+
item.append(element('span', 'profile-claim', language.label), patterns);
|
|
63
70
|
return item;
|
|
64
71
|
}));
|
|
65
72
|
return list;
|
|
@@ -2,6 +2,7 @@ import type { PublicHistoryEntry } from '../wire/public-history-model.js';
|
|
|
2
2
|
import type { Report } from '../validation/report.js';
|
|
3
3
|
import type { CommitSummary, RepositorySummary } from '../wire/summary-model.js';
|
|
4
4
|
export declare function commitSummary(report: Report): CommitSummary;
|
|
5
|
+
export declare function needsMaintainabilityRefresh(row: CommitSummary): boolean;
|
|
5
6
|
export declare function orderSummaries(rows: readonly CommitSummary[]): CommitSummary[];
|
|
6
7
|
export type CommitMetadata = Pick<PublicHistoryEntry, 'subject' | 'author' | 'tags' | 'committedAt'>;
|
|
7
8
|
export type ReadCommitMetadata = (revisions: readonly string[]) => Promise<ReadonlyMap<string, CommitMetadata>>;
|
|
@@ -29,6 +29,11 @@ export function commitSummary(report) {
|
|
|
29
29
|
...(metrics.privateMetrics === undefined ? {} : { privateMetrics: metrics.privateMetrics }) }),
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
// Earlier indices recorded zero effort before any file supplied all inputs for a grade.
|
|
33
|
+
export function needsMaintainabilityRefresh(row) {
|
|
34
|
+
const summary = row.quality.maintainability;
|
|
35
|
+
return summary?.grade === null && summary.debtRatio === null && summary.smells === 0 && summary.effortMinutes === 0;
|
|
36
|
+
}
|
|
32
37
|
export function orderSummaries(rows) {
|
|
33
38
|
return [...rows].sort(compareHistoryEntries);
|
|
34
39
|
}
|