@repometry/core 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repometry/core",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "The Repometry plugin API and inspection engine",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -20,7 +20,12 @@ export declare const codeStructure: DataContract<CodeStructure>;
20
20
  export declare const codeStructures: DataContract<readonly CodeStructure[]>;
21
21
  export declare const findingResult: DataContract<FindingResult>;
22
22
  export declare function writeStructure(value: unknown): unknown;
23
- export declare function writeFindings(value: unknown, id?: string, dimension?: PluginCategory): unknown;
23
+ export interface BundledFindingEncoding {
24
+ readonly tool: string;
25
+ readonly category: StoredFinding['category'];
26
+ readonly categoryBeforeRule?: true;
27
+ }
28
+ export declare function writeFindings(value: unknown, id?: string, dimension?: PluginCategory, encoding?: BundledFindingEncoding): unknown;
24
29
  export declare function readStructure(value: StoredStructure): CodeStructure;
25
30
  export declare function readFindings(value: StoredFindings): FindingResult;
26
31
  export declare function findingCategory(dimension: PluginCategory | undefined, chargesEffort: boolean): StoredFinding['category'];
@@ -19,12 +19,12 @@ function writeObservation(value) {
19
19
  const { check, ...fields } = value;
20
20
  return { ...fields, rule: check };
21
21
  }
22
- export function writeFindings(value, id, dimension) {
22
+ export function writeFindings(value, id, dimension, encoding) {
23
23
  if (!isRecord(value) || !Array.isArray(value.findings))
24
24
  return value;
25
- return { ...value, findings: value.findings.map(finding => writeFinding(finding, id, dimension)) };
25
+ return { ...value, findings: value.findings.map(finding => writeFinding(finding, id, dimension, encoding)) };
26
26
  }
27
- function writeFinding(value, id, dimension) {
27
+ function writeFinding(value, id, dimension, encoding) {
28
28
  if (!isRecord(value))
29
29
  return value;
30
30
  const { plugin, check, ...fields } = value;
@@ -33,6 +33,11 @@ function writeFinding(value, id, dimension) {
33
33
  if (dimension !== undefined && dimension !== category.maintainability && dimension !== category.security) {
34
34
  throw new Error('Plugins in ' + dimension + ' do not produce findings');
35
35
  }
36
+ if (encoding) {
37
+ const { tool, category } = encoding;
38
+ const identity = encoding.categoryBeforeRule ? { tool, category, rule: check } : { tool, rule: check, category };
39
+ return { ...identity, ...fields, ...identity };
40
+ }
36
41
  const group = findingCategory(dimension, fields.effortMinutes !== undefined);
37
42
  return { ...fields, tool: plugin ?? id ?? 'plugin', rule: check, category: group };
38
43
  }
@@ -1,3 +1,4 @@
1
1
  import type { PluginCategory } from '../model/inspection-category.js';
2
2
  import type { Operation } from './plugin.js';
3
- export declare function authorOperation(id: string, category: PluginCategory, operation: Operation): Operation;
3
+ import type { BundledFindingEncoding } from './author-contracts.js';
4
+ export declare function authorOperation(id: string, category: PluginCategory, operation: Operation, encoding?: BundledFindingEncoding): Operation;
@@ -1,17 +1,17 @@
1
1
  import { readFindings, readStructure, writeFindings, writeStructure } from './author-contracts.js';
2
2
  import { findingResult } from '../model/finding.js';
3
3
  import { codeStructure, codeStructures } from '../model/code-structure.js';
4
- export function authorOperation(id, category, operation) {
4
+ export function authorOperation(id, category, operation, encoding) {
5
5
  const { output } = operation;
6
6
  const inputs = Object.fromEntries(Object.entries(operation.inputs).map(([port, contract]) => [port, storedContract(contract)]));
7
7
  return { ...operation, inputs, output: storedContract(output), async execute(context) {
8
8
  const result = await operation.execute({ ...context, read: (port, contract) => readValue(context, port, contract) });
9
- return authorResult(id, category, output.id, result);
9
+ return authorResult(id, category, output.id, result, encoding);
10
10
  } };
11
11
  }
12
- function authorResult(id, category, output, result) {
12
+ function authorResult(id, category, output, result, encoding) {
13
13
  if (output === findingResult.id)
14
- return writeFindings(result, id, category);
14
+ return writeFindings(result, id, category, encoding);
15
15
  if (output === codeStructure.id)
16
16
  return writeStructure(result);
17
17
  if (output === codeStructures.id && Array.isArray(result))
@@ -2,6 +2,7 @@ import type { LanguageDisplay, LanguageSyntax } from '../model/language.js';
2
2
  import type { StructureMeasure } from '../model/code-structure.js';
3
3
  import type { PluginCategory } from '../model/inspection-category.js';
4
4
  import type { JsonValue } from '../model/plugin-data.js';
5
+ import type { BundledFindingEncoding } from './author-contracts.js';
5
6
  import type { Operation, Plugin, ProductDeclaration, RuleDescriptor } from './plugin.js';
6
7
  export declare const pluginManifestSchema = "urn:repometry:schema:plugin:1";
7
8
  export type { PluginCategory } from '../model/inspection-category.js';
@@ -38,7 +39,7 @@ interface PluginOperations {
38
39
  readonly operations: readonly Operation[];
39
40
  readonly produces: readonly ProductOutput[];
40
41
  }
41
- export declare function manifestOperations({ id, category }: Pick<PluginManifest, 'id' | 'category'>, { operations, produces }: PluginOperations): {
42
+ export declare function manifestOperations({ id, category }: Pick<PluginManifest, 'id' | 'category'>, { operations, produces }: PluginOperations, encoding?: BundledFindingEncoding): {
42
43
  operations: Operation[];
43
44
  produces: ({
44
45
  contract: string;
@@ -55,6 +56,6 @@ export type BundledManifest = PluginManifest & {
55
56
  readonly version: string;
56
57
  create(): PluginOperations;
57
58
  };
58
- export declare function bundledPlugin(manifest: BundledManifest): Plugin;
59
+ export declare function bundledPlugin(manifest: BundledManifest, encoding?: BundledFindingEncoding): Plugin;
59
60
  export declare function pluginCategory(plugin: Plugin): PluginCategory;
60
61
  export declare function manifestPlugin({ id, category, languages, optionsSchema, tools, checks }: Omit<PluginManifest, 'create'>, version: string): Omit<Plugin, 'operations' | 'produces' | 'settings'>;
@@ -3,12 +3,16 @@ import { findingCategory } from './author-contracts.js';
3
3
  import { authorOperation } from './author-operation.js';
4
4
  import { pluginApi } from './plugin.js';
5
5
  export const pluginManifestSchema = 'urn:repometry:schema:plugin:1';
6
- export function manifestOperations({ id, category }, { operations, produces }) {
7
- return { operations: operations.map(operation => authorOperation(id, category, operation)),
6
+ export function manifestOperations({ id, category }, { operations, produces }, encoding) {
7
+ return { operations: operations.map(operation => authorOperation(id, category, operation, encoding)),
8
8
  produces: produces.map(({ valueSchema, ...product }) => valueSchema === undefined ? product : { ...product, schema: valueSchema }) };
9
9
  }
10
- export function bundledPlugin(manifest) {
11
- return { ...manifestPlugin(manifest, manifest.version), ...manifestOperations(manifest, manifest.create()) };
10
+ export function bundledPlugin(manifest, encoding) {
11
+ const plugin = manifestPlugin(manifest, manifest.version);
12
+ const rules = encoding
13
+ ? manifest.checks?.map(({ id, ...check }) => ({ id, category: encoding.category, ...check }))
14
+ : plugin.rules;
15
+ return { ...plugin, ...(rules === undefined ? {} : { rules }), ...manifestOperations(manifest, manifest.create(), encoding) };
12
16
  }
13
17
  export function pluginCategory(plugin) {
14
18
  const categories = [category.language, category.source, category.security, category.coverage];
@@ -46,7 +46,7 @@ export interface CodeStructure {
46
46
  readonly clones?: CloneSource;
47
47
  }
48
48
  export declare const codeStructure: DataContract<CodeStructure>;
49
- export declare function structureCodeLines(value: CodeStructure): readonly number[] | undefined;
49
+ export declare function structureCodeLines(value: Pick<CodeStructure, 'codeLines' | 'clones'>): readonly number[] | undefined;
50
50
  /** A repository provider returns at most one structure per input path. */
51
51
  export declare const codeStructures: DataContract<readonly CodeStructure[]>;
52
52
  /** The structure measure that rules of a finding category need. Without it, a file skips those rules. */
@@ -28,9 +28,14 @@ export const fileTypes = [
28
28
  { id: 'csharp', label: 'C#', color: '#178600', extensions: ['.cs'] },
29
29
  { id: 'c', label: 'C', color: '#555555', extensions: ['.c', '.h'], syntax: cSyntax },
30
30
  { id: 'cpp', label: 'C++', color: '#f34b7d', extensions: ['.cc', '.cpp', '.cxx', '.hpp', '.hh'], syntax: cppSyntax },
31
+ { id: 'dart', label: 'Dart', color: '#00b4ab', extensions: ['.dart'] },
31
32
  { id: 'swift', label: 'Swift', color: '#f05138', extensions: ['.swift'] },
32
33
  { id: 'scala', label: 'Scala', color: '#c22d40', extensions: ['.scala'] },
33
34
  { id: 'elixir', label: 'Elixir', color: '#6e4a7e', extensions: ['.ex', '.exs'] },
35
+ { id: 'r', label: 'R', color: '#198ce7', extensions: ['.r', '.R'] },
36
+ { id: 'zig', label: 'Zig', color: '#ec915c', extensions: ['.zig'] },
37
+ { id: 'ocaml', label: 'OCaml', color: '#ef7a08', extensions: ['.ml', '.mli'] },
38
+ { id: 'perl', label: 'Perl', color: '#0298c3', extensions: ['.pl', '.pm'] },
34
39
  { id: 'vue', label: 'Vue', color: '#41b883', extensions: ['.vue'] },
35
40
  { id: 'svelte', label: 'Svelte', color: '#ff3e00', extensions: ['.svelte'] },
36
41
  { id: 'text', label: 'Plain text', color: '#7b8794', extensions: ['.txt'] },