@repometry/cli 0.2.0 → 0.3.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 (26) hide show
  1. package/README.md +2 -2
  2. package/package.json +2 -2
  3. package/target/main/resources/language-catalog.json +54 -0
  4. package/target/main/ts/compose/language-discovery.js +3 -1
  5. package/target/main/ts/plugins/duplication/duplication.d.ts +1 -2
  6. package/target/main/ts/plugins/duplication/duplication.js +18 -17
  7. package/target/main/ts/plugins/language-js/babel-provider.d.ts +34 -2
  8. package/target/main/ts/plugins/language-js/babel-provider.js +39 -35
  9. package/target/main/ts/plugins/language-js/js-security.d.ts +17 -2
  10. package/target/main/ts/plugins/language-js/js-security.js +24 -23
  11. package/target/main/ts/plugins/language-js/structural-observations.d.ts +2 -1
  12. package/target/main/ts/plugins/language-js/structural-observations.js +2 -2
  13. package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -2
  14. package/target/main/ts/plugins/maintainability/maintainability.js +34 -33
  15. package/target/main/ts/plugins/maintainability/structural-smells.d.ts +1 -2
  16. package/target/main/ts/plugins/maintainability/structural-smells.js +5 -5
  17. package/target/main/ts/plugins/security/actions-security.d.ts +17 -2
  18. package/target/main/ts/plugins/security/actions-security.js +21 -16
  19. package/target/main/ts/plugins/security/dockerfile.d.ts +17 -2
  20. package/target/main/ts/plugins/security/dockerfile.js +23 -18
  21. package/target/main/ts/plugins/security/npm-supply-chain.d.ts +17 -2
  22. package/target/main/ts/plugins/security/npm-supply-chain.js +30 -24
  23. package/target/main/ts/plugins/security/secrets.d.ts +18 -6
  24. package/target/main/ts/plugins/security/secrets.js +27 -23
  25. package/target/main/ts/plugins/source/forges.js +25 -32
  26. package/target/main/ts/report/html/app/viewer-tokenizer.js +2 -1
package/README.md CHANGED
@@ -22,7 +22,7 @@ Git can serve as a project’s single source of truth for code, tests, docs, and
22
22
 
23
23
  Node.js >=24
24
24
 
25
- Repometry analyses JavaScript, TypeScript, Go, Python, Java and PHP with no extra tools. Ruby, Kotlin, HCL (Terraform), Lua, Scala, Elixir and Rust come with `@repometry/all` or as plugins. C#, C, C++ and Swift are separate plugins. See [Languages](docs/native-languages.md). Generating coverage uses your project's own test tools.
25
+ Repometry analyses JavaScript, TypeScript, Go, Python, Java and PHP with no extra tools. Ruby, Kotlin, HCL (Terraform), Lua, Scala, Elixir, Rust, R, Zig, OCaml and Perl come with `@repometry/all` or as plugins. C#, C, C++, Swift, Bash and Dart are separate plugins. See [Languages](docs/native-languages.md). Generating coverage uses your project's own test tools.
26
26
 
27
27
  ## Install
28
28
 
@@ -40,7 +40,7 @@ npm install --global repometry
40
40
  | --- | --- | --- | --- |
41
41
  | `@repometry/cli` | `repometry-cli` | JavaScript, TypeScript | about 8 MB |
42
42
  | `repometry` | `repometry` | The above, Go, Python, Java, PHP | about 15 MB |
43
- | `@repometry/all` | `repometry-all` | The above, Ruby, Kotlin, HCL, Lua, Scala, Elixir, Rust | about 28 MB |
43
+ | `@repometry/all` | `repometry-all` | The above, Ruby, Kotlin, HCL, Lua, Scala, Elixir, Rust, R, Zig, OCaml, Perl | about 33 MB |
44
44
 
45
45
  To add a language to `@repometry/cli`, install its `@repometry/language-*` package with your package manager and list it in `plugins`. Repometry never installs a plugin. See [Packages](docs/cli.md#packages).
46
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repometry/cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Track repository metrics without SaaS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -67,7 +67,7 @@
67
67
  "dependencies": {
68
68
  "@babel/parser": "7.29.15",
69
69
  "@babel/types": "7.29.15",
70
- "@repometry/core": "0.5.0",
70
+ "@repometry/core": "0.6.0",
71
71
  "ajv": "8.20.0",
72
72
  "semver": "7.8.6"
73
73
  },
@@ -1,4 +1,14 @@
1
1
  [
2
+ {
3
+ "language": "bash",
4
+ "label": "Bash",
5
+ "package": "@repometry/language-bash",
6
+ "experimental": true,
7
+ "extensions": [
8
+ ".sh",
9
+ ".bash"
10
+ ]
11
+ },
2
12
  {
3
13
  "language": "c",
4
14
  "label": "C",
@@ -30,6 +40,15 @@
30
40
  ".cs"
31
41
  ]
32
42
  },
43
+ {
44
+ "language": "dart",
45
+ "label": "Dart",
46
+ "package": "@repometry/language-dart",
47
+ "experimental": true,
48
+ "extensions": [
49
+ ".dart"
50
+ ]
51
+ },
33
52
  {
34
53
  "language": "elixir",
35
54
  "label": "Elixir",
@@ -82,6 +101,24 @@
82
101
  ".lua"
83
102
  ]
84
103
  },
104
+ {
105
+ "language": "ocaml",
106
+ "label": "OCaml",
107
+ "package": "@repometry/language-ocaml",
108
+ "extensions": [
109
+ ".ml",
110
+ ".mli"
111
+ ]
112
+ },
113
+ {
114
+ "language": "perl",
115
+ "label": "Perl",
116
+ "package": "@repometry/language-perl",
117
+ "extensions": [
118
+ ".pl",
119
+ ".pm"
120
+ ]
121
+ },
85
122
  {
86
123
  "language": "php",
87
124
  "label": "PHP",
@@ -98,6 +135,15 @@
98
135
  ".py"
99
136
  ]
100
137
  },
138
+ {
139
+ "language": "r",
140
+ "label": "R",
141
+ "package": "@repometry/language-r",
142
+ "extensions": [
143
+ ".r",
144
+ ".R"
145
+ ]
146
+ },
101
147
  {
102
148
  "language": "ruby",
103
149
  "label": "Ruby",
@@ -130,5 +176,13 @@
130
176
  "extensions": [
131
177
  ".swift"
132
178
  ]
179
+ },
180
+ {
181
+ "language": "zig",
182
+ "label": "Zig",
183
+ "package": "@repometry/language-zig",
184
+ "extensions": [
185
+ ".zig"
186
+ ]
133
187
  }
134
188
  ]
@@ -13,7 +13,9 @@ for (const entry of catalog) {
13
13
  packages.add(entry.package);
14
14
  packagesByLanguage.set(entry.language, packages);
15
15
  for (const extension of entry.extensions) {
16
- if (fileTypesByExtension.get(extension) === entry.language)
16
+ // Uninspected shell files keep their report language ID.
17
+ const fileType = entry.language === 'bash' ? 'shell' : entry.language;
18
+ if (fileTypesByExtension.get(extension) === fileType)
17
19
  officialByExtension.set(extension, entry.language);
18
20
  }
19
21
  }
@@ -1,2 +1 @@
1
- import type { Plugin } from '@repometry/core/internal/engine/plugin.js';
2
- export declare const duplication: Plugin;
1
+ export declare const duplication: import("@repometry/core/internal/engine/plugin.js").Plugin;
@@ -1,22 +1,23 @@
1
- import { pluginApi } from '@repometry/core/internal/engine/plugin.js';
1
+ import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
2
+ import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
2
3
  import { comparePaths } from '@repometry/core/internal/model/snapshot.js';
3
- import { findingResult } from '@repometry/core/internal/model/finding.js';
4
4
  import { definitions } from '@repometry/core/internal/model/measurement.js';
5
5
  import { cloneSources } from '@repometry/core/internal/model/clone-source.js';
6
6
  import { duplicationSettings } from '@repometry/core/internal/profile/maintainability.js';
7
- export const duplication = {
8
- id: 'duplication', version: '1.0.0', api: pluginApi,
9
- kinds: ['analysis'],
10
- rules: [{ id: 'identical-code', category: 'duplication' }, { id: 'similar-code', category: 'duplication' }],
11
- produces: [{ contract: findingResult.id, persistence: 'report', metrics: [
12
- { id: definitions.duplicatedLines, label: 'Duplicated lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'lower',
13
- group: 'Maintainability' },
14
- ] }],
15
- operations: [{
16
- id: 'detect', role: 'inspection', inputs: { sources: cloneSources }, output: findingResult,
17
- execute(inputs) { return detectClones(inputs.read('sources', cloneSources)); },
18
- }],
19
- };
7
+ export const duplication = bundledPlugin({
8
+ schema: pluginManifestSchema, id: 'duplication', version: '1.0.0', category: 'maintainability',
9
+ checks: [{ id: 'identical-code' }, { id: 'similar-code' }],
10
+ create: () => ({
11
+ produces: [{ contract: findingResult.id, persistence: 'report', metrics: [
12
+ { id: definitions.duplicatedLines, label: 'Duplicated lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'lower',
13
+ group: 'Maintainability' },
14
+ ] }],
15
+ operations: [{
16
+ id: 'detect', role: 'inspection', inputs: { sources: cloneSources }, output: findingResult,
17
+ execute(inputs) { return detectClones(inputs.read('sources', cloneSources)); },
18
+ }],
19
+ }),
20
+ }, { tool: 'repometry', category: 'duplication' });
20
21
  function detectClones(sources) {
21
22
  const schemes = new Map();
22
23
  for (const { path, candidates, scheme } of sources) {
@@ -53,9 +54,9 @@ function detectClones(sources) {
53
54
  const selected = matched.get(occurrence.path);
54
55
  selected.splice(insertionIndex(selected, occurrence.start), 0, occurrence);
55
56
  }
56
- const rule = identical ? 'identical-code' : 'similar-code';
57
+ const check = identical ? 'identical-code' : 'similar-code';
57
58
  const effortMinutes = fresh.slice(1).reduce((total, occurrence) => total + occurrence.codeLines, 0) * duplicationSettings.minutesPerRepeatedLine;
58
- findings.push({ tool: 'repometry', rule, category: 'duplication', level: 'medium',
59
+ findings.push({ check, level: 'medium',
59
60
  message: `${identical ? 'Identical' : 'Similar'} code in ${fresh.length} locations`, ...location(first),
60
61
  related: fresh.slice(1).map(location), effortMinutes, value: fresh.length, anchor: first.similar });
61
62
  }
@@ -1,4 +1,3 @@
1
- import type { Plugin } from '@repometry/core/internal/engine/plugin.js';
2
1
  export declare const parserDefaults: {
3
2
  readonly sourceType: 'unambiguous';
4
3
  readonly errorRecovery: false;
@@ -7,4 +6,37 @@ export declare const parserDefaults: {
7
6
  export declare const babelTypes: {
8
7
  '@babel/types': string;
9
8
  };
10
- export declare const babelProvider: Plugin;
9
+ export declare const babelProvider: {
10
+ id: string;
11
+ version: string;
12
+ api: string;
13
+ tools?: Readonly<Record<string, string>>;
14
+ operations: readonly import("@repometry/core").Operation[];
15
+ rules?: readonly import("@repometry/core/internal/engine/plugin.js").RuleDescriptor[];
16
+ config?: import("@repometry/core/internal/engine/plugin.js").PluginConfigSchema;
17
+ kinds: readonly import("@repometry/core/internal/engine/plugin.js").PluginKind[];
18
+ languageProvenanceRequiresSource?: true;
19
+ produces: readonly import("@repometry/core/internal/engine/plugin.js").ProductDeclaration[];
20
+ claims: {
21
+ extensions: readonly [".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".tsx"];
22
+ languages: ("javascript" | "typescript")[];
23
+ };
24
+ providesLanguages: ({
25
+ id: 'javascript';
26
+ label: 'JavaScript';
27
+ color: '#f1e05a';
28
+ extensions: readonly ['.js', '.mjs', '.cjs', '.jsx'];
29
+ syntax: import("@repometry/core").LanguageSyntax;
30
+ } | {
31
+ id: 'typescript';
32
+ label: 'TypeScript';
33
+ color: '#3178c6';
34
+ extensions: readonly ['.ts', '.mts', '.cts', '.tsx'];
35
+ syntax: import("@repometry/core").LanguageSyntax;
36
+ })[];
37
+ settings: {
38
+ readonly sourceType: 'unambiguous';
39
+ readonly errorRecovery: false;
40
+ readonly attachComment: false;
41
+ };
42
+ };
@@ -1,9 +1,9 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { extname } from 'node:path';
3
3
  import { parse } from '@babel/parser';
4
- import { pluginApi } from '@repometry/core/internal/engine/plugin.js';
4
+ import { codeStructure } from '@repometry/core/internal/engine/author-contracts.js';
5
+ import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
5
6
  import { javascriptType, typescriptType } from '@repometry/core/internal/model/file-types.js';
6
- import { codeStructure } from '@repometry/core/internal/model/code-structure.js';
7
7
  import { physicalLines, sourceFile, utf8 } from '@repometry/core/internal/model/snapshot.js';
8
8
  import { cloneCandidates } from './clone-candidates.js';
9
9
  import { classifyLines } from './code-lines.js';
@@ -15,40 +15,44 @@ import { jsSyntax } from './syntax.js';
15
15
  const require = createRequire(import.meta.url);
16
16
  export const parserDefaults = { sourceType: 'unambiguous', errorRecovery: false, attachComment: false };
17
17
  export const babelTypes = { '@babel/types': require('@babel/types/package.json').version };
18
+ const languages = [{ ...javascriptType, syntax: jsSyntax }, { ...typescriptType, syntax: jsSyntax }];
18
19
  export const babelProvider = {
19
- id: 'babel-syntax',
20
- version: '1.1.0',
21
- api: pluginApi,
22
- kinds: ['language'],
23
- claims: { extensions: jsTsExtensions, languages: ['javascript', 'typescript'] },
24
- providesLanguages: [{ ...javascriptType, syntax: jsSyntax }, { ...typescriptType, syntax: jsSyntax }],
20
+ ...bundledPlugin({
21
+ schema: pluginManifestSchema, id: 'babel-syntax', version: '1.1.0', category: 'language',
22
+ languages: languages.map(({ extensions, ...language }) => ({ ...language, include: extensions.map(extension => '**/*' + extension) })),
23
+ tools: { '@babel/parser': require('@babel/parser/package.json').version, ...babelTypes },
24
+ create: () => ({
25
+ produces: [{ contract: codeStructure.id, persistence: 'transient' }],
26
+ operations: [{
27
+ id: 'parse',
28
+ role: 'provider',
29
+ inputs: { source: sourceFile },
30
+ output: codeStructure,
31
+ execute(inputs) {
32
+ const file = inputs.read('source', sourceFile);
33
+ const source = utf8(file.bytes);
34
+ const ext = extname(file.path);
35
+ const plugins = [];
36
+ if (typescriptType.extensions.includes(ext)) {
37
+ plugins.push(['typescript', { dts: /\.d\.[cm]?ts$/.test(file.path), disallowAmbiguousJSXLike: ext === '.mts' || ext === '.cts' }]);
38
+ }
39
+ if (ext === '.jsx' || ext === '.tsx')
40
+ plugins.push('jsx');
41
+ const sourceType = ext === '.mjs' || ext === '.mts' ? 'module'
42
+ : ext === '.cjs' || ext === '.cts' ? 'commonjs' : parserDefaults.sourceType;
43
+ const ast = parse(source, { ...parserDefaults, sourceType, plugins });
44
+ const lines = physicalLines(source);
45
+ const { code, comments } = classifyLines(source, ast, lines);
46
+ const names = qualifiedNames(ast);
47
+ return { path: file.path, lines, commentLines: comments, ...functionFacts(ast, names),
48
+ ...structuralObservations(ast, names), clones: cloneCandidates(file.path, ast, code) };
49
+ },
50
+ }],
51
+ }),
52
+ }),
53
+ claims: { extensions: jsTsExtensions, languages: languages.map(({ id }) => id) },
54
+ // Existing reports record suffix selectors and the effective Babel settings.
55
+ providesLanguages: languages,
25
56
  settings: parserDefaults,
26
- produces: [{ contract: codeStructure.id, persistence: 'transient' }],
27
- tools: { '@babel/parser': require('@babel/parser/package.json').version, ...babelTypes },
28
- operations: [{
29
- id: 'parse',
30
- role: 'provider',
31
- inputs: { source: sourceFile },
32
- output: codeStructure,
33
- execute(inputs) {
34
- const file = inputs.read('source', sourceFile);
35
- const source = utf8(file.bytes);
36
- const ext = extname(file.path);
37
- const plugins = [];
38
- if (typescriptType.extensions.includes(ext)) {
39
- plugins.push(['typescript', { dts: /\.d\.[cm]?ts$/.test(file.path), disallowAmbiguousJSXLike: ext === '.mts' || ext === '.cts' }]);
40
- }
41
- if (ext === '.jsx' || ext === '.tsx')
42
- plugins.push('jsx');
43
- const sourceType = ext === '.mjs' || ext === '.mts' ? 'module'
44
- : ext === '.cjs' || ext === '.cts' ? 'commonjs' : parserDefaults.sourceType;
45
- const ast = parse(source, { ...parserDefaults, sourceType, plugins });
46
- const lines = physicalLines(source);
47
- const { code, comments } = classifyLines(source, ast, lines);
48
- const names = qualifiedNames(ast);
49
- return { path: file.path, lines, commentLines: comments, ...functionFacts(ast, names),
50
- ...structuralObservations(ast, names), clones: cloneCandidates(file.path, ast, code) };
51
- },
52
- }],
53
57
  };
54
58
  //# sourceMappingURL=babel-provider.js.map
@@ -1,4 +1,19 @@
1
- import type { Plugin } from '@repometry/core/internal/engine/plugin.js';
2
- export declare const jsSecurity: Plugin;
1
+ export declare const jsSecurity: {
2
+ id: string;
3
+ version: string;
4
+ api: string;
5
+ tools?: Readonly<Record<string, string>>;
6
+ operations: readonly import("@repometry/core").Operation[];
7
+ rules?: readonly import("@repometry/core/internal/engine/plugin.js").RuleDescriptor[];
8
+ config?: import("@repometry/core/internal/engine/plugin.js").PluginConfigSchema;
9
+ settings?: import("@repometry/core/internal/model/plugin-data.js").JsonValue;
10
+ kinds: readonly import("@repometry/core/internal/engine/plugin.js").PluginKind[];
11
+ providesLanguages?: readonly import("@repometry/core/internal/model/language.js").ProvidedLanguage[];
12
+ languageProvenanceRequiresSource?: true;
13
+ produces: readonly import("@repometry/core/internal/engine/plugin.js").ProductDeclaration[];
14
+ claims: {
15
+ extensions: readonly [".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".tsx"];
16
+ };
17
+ };
3
18
  /** Splits camelCase, PascalCase and snake_case names into words and looks for secret-bearing ones. */
4
19
  export declare function isSecretName(name: string): boolean;
@@ -1,8 +1,8 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { extname } from 'node:path';
3
3
  import { parse } from '@babel/parser';
4
- import { pluginApi } from '@repometry/core/internal/engine/plugin.js';
5
- import { findingResult } from '@repometry/core/internal/model/finding.js';
4
+ import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
5
+ import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
6
6
  import { sourceFile, utf8 } from '@repometry/core/internal/model/snapshot.js';
7
7
  import { jsTsExtensions } from './extensions.js';
8
8
  import { babelTypes, parserDefaults } from './babel-provider.js';
@@ -36,28 +36,29 @@ const wrappers = new Set(['TSAsExpression', 'TSSatisfiesExpression', 'TSNonNullE
36
36
  'ParenthesizedExpression', 'TypeCastExpression']);
37
37
  const functionTypes = new Set(['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression', 'ObjectMethod',
38
38
  'ClassMethod', 'ClassPrivateMethod']);
39
- const jsSecurityRules = Object.entries(catalog)
40
- .map(([id, { description }]) => ({ id, category: 'security', description }));
39
+ const jsSecurityRules = Object.entries(catalog).map(([id, { description }]) => ({ id, description }));
41
40
  export const jsSecurity = {
42
- id: 'js-security',
43
- version: '1.0.0',
44
- api: pluginApi,
45
- kinds: ['security'],
41
+ ...bundledPlugin({
42
+ schema: pluginManifestSchema, id: 'js-security', version: '1.0.0', category: 'security',
43
+ include: jsTsExtensions.map(extension => '**/*' + extension),
44
+ tools: { '@babel/parser': require('@babel/parser/package.json').version, ...babelTypes },
45
+ checks: jsSecurityRules,
46
+ create: () => ({
47
+ produces: [{ contract: findingResult.id, persistence: 'report' }],
48
+ operations: [{
49
+ id: 'scan',
50
+ role: 'inspection',
51
+ inputs: { source: sourceFile },
52
+ output: findingResult,
53
+ execute(inputs) {
54
+ const file = inputs.read('source', sourceFile);
55
+ const ast = parseSource(file.path, file.bytes);
56
+ return { measurements: [], findings: ast === undefined ? [] : scan(file.path, ast) };
57
+ },
58
+ }],
59
+ }),
60
+ }, { tool: 'js-security', category: 'security' }),
46
61
  claims: { extensions: jsTsExtensions },
47
- produces: [{ contract: findingResult.id, persistence: 'report' }],
48
- tools: { '@babel/parser': require('@babel/parser/package.json').version, ...babelTypes },
49
- rules: jsSecurityRules,
50
- operations: [{
51
- id: 'scan',
52
- role: 'inspection',
53
- inputs: { source: sourceFile },
54
- output: findingResult,
55
- execute(inputs) {
56
- const file = inputs.read('source', sourceFile);
57
- const ast = parseSource(file.path, file.bytes);
58
- return { measurements: [], findings: ast === undefined ? [] : scan(file.path, ast) };
59
- },
60
- }],
61
62
  };
62
63
  /** Parses like the babel-syntax provider; a file it rejects is that plugin's diagnostic, not a security finding. */
63
64
  function parseSource(path, bytes) {
@@ -218,7 +219,7 @@ function scan(path, ast) {
218
219
  }
219
220
  function report(rule, node, message) {
220
221
  const line = node.loc?.start.line ?? 1;
221
- findings.push({ tool: 'js-security', rule, category: 'security', level: catalog[rule].level, message, path,
222
+ findings.push({ check: rule, level: catalog[rule].level, message, path,
222
223
  line, endLine: Math.max(line, node.loc?.end.line ?? line) });
223
224
  }
224
225
  }
@@ -1,5 +1,6 @@
1
1
  import type { Node } from '@babel/types';
2
- import type { FunctionComplexity, StructuralObservation } from '@repometry/core/internal/model/code-structure.js';
2
+ import type { StructuralObservation } from '@repometry/core/internal/engine/author-contracts.js';
3
+ import type { FunctionComplexity } from '@repometry/core/internal/model/code-structure.js';
3
4
  import type { FunctionNaming } from './qualified-names.js';
4
5
  export declare function structuralObservations(ast: Node, names: ReadonlyMap<Node, FunctionNaming>): {
5
6
  observations: StructuralObservation[];
@@ -72,8 +72,8 @@ export function structuralObservations(ast, names) {
72
72
  visit(child, frame, depth + Number(block), node);
73
73
  }
74
74
  }
75
- function observe(rule, value, label, location, anchor) {
76
- observations.push({ rule, value, label, line: location?.loc?.start.line, endLine: location?.loc?.end.line,
75
+ function observe(check, value, label, location, anchor) {
76
+ observations.push({ check, value, label, line: location?.loc?.start.line, endLine: location?.loc?.end.line,
77
77
  ...(anchor === undefined ? {} : { anchor }) });
78
78
  }
79
79
  }
@@ -1,2 +1 @@
1
- import type { Plugin } from '@repometry/core/internal/engine/plugin.js';
2
- export declare const maintainability: Plugin;
1
+ export declare const maintainability: import("@repometry/core/internal/engine/plugin.js").Plugin;
@@ -1,38 +1,39 @@
1
- import { pluginApi } from '@repometry/core/internal/engine/plugin.js';
2
- import { codeStructure, structureCodeLines } from '@repometry/core/internal/model/code-structure.js';
3
- import { findingResult } from '@repometry/core/internal/model/finding.js';
1
+ import { codeStructure, findingResult } from '@repometry/core/internal/engine/author-contracts.js';
2
+ import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
3
+ import { structureCodeLines } from '@repometry/core/internal/model/code-structure.js';
4
4
  import { definitions } from '@repometry/core/internal/model/measurement.js';
5
5
  import { sourceFile } from '@repometry/core/internal/model/snapshot.js';
6
6
  import { structuralRules } from '@repometry/core/internal/profile/maintainability.js';
7
7
  import { structuralSmells } from './structural-smells.js';
8
- export const maintainability = {
9
- id: 'maintainability', version: '1.0.0', api: pluginApi,
10
- kinds: ['analysis'],
11
- produces: [{ contract: findingResult.id, persistence: 'report', metrics: [
12
- { id: definitions.cognitiveComplexity, label: 'Cognitive complexity', unit: 'count', scope: 'file', aggregate: 'sum',
13
- better: 'lower', group: 'Maintainability' },
14
- { id: definitions.classes, label: 'Classes', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Size' },
15
- { id: definitions.codeLines, label: 'Lines of code', short: 'Code lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none',
16
- group: 'Size' },
17
- { id: definitions.comments, label: 'Comment lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Size' },
18
- ] }],
19
- rules: Object.entries(structuralRules).map(([id, { limit, minutesPerExcess }]) => ({ id, category: 'structure', defaults: { limit, cost: minutesPerExcess } })),
20
- operations: [{
21
- id: 'file', role: 'inspection', inputs: { syntax: codeStructure, source: sourceFile }, output: findingResult,
22
- execute(inputs) {
23
- const facts = inputs.read('syntax', codeStructure);
24
- const { path, observations = [], cognitiveFunctions = [], cognitiveComplexity, classes, commentLines } = facts;
25
- const codeLines = structureCodeLines(facts);
26
- const counts = [[definitions.cognitiveComplexity, cognitiveComplexity], [definitions.classes, classes],
27
- [definitions.codeLines, codeLines?.length], [definitions.comments, commentLines]];
28
- return {
29
- findings: structuralSmells(path, observations),
30
- measurements: [
31
- ...cognitiveFunctions.map(({ line, column, name, value }) => ({ definition: definitions.cognitiveComplexity, target: 'function', path, line, column, name, value })),
32
- ...counts.flatMap(([definition, value]) => value === undefined ? [] : [{ definition, target: 'file', path, value }]),
33
- ],
34
- };
35
- },
36
- }],
37
- };
8
+ export const maintainability = bundledPlugin({
9
+ schema: pluginManifestSchema, id: 'maintainability', version: '1.0.0', category: 'maintainability',
10
+ checks: Object.entries(structuralRules).map(([id, { limit, minutesPerExcess }]) => ({ id, defaults: { limit, cost: minutesPerExcess } })),
11
+ create: () => ({
12
+ produces: [{ contract: findingResult.id, persistence: 'report', metrics: [
13
+ { id: definitions.cognitiveComplexity, label: 'Cognitive complexity', unit: 'count', scope: 'file', aggregate: 'sum',
14
+ better: 'lower', group: 'Maintainability' },
15
+ { id: definitions.classes, label: 'Classes', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Size' },
16
+ { id: definitions.codeLines, label: 'Lines of code', short: 'Code lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none',
17
+ group: 'Size' },
18
+ { id: definitions.comments, label: 'Comment lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Size' },
19
+ ] }],
20
+ operations: [{
21
+ id: 'file', role: 'inspection', inputs: { syntax: codeStructure, source: sourceFile }, output: findingResult,
22
+ execute(inputs) {
23
+ const facts = inputs.read('syntax', codeStructure);
24
+ const { path, observations = [], cognitiveFunctions = [], cognitiveComplexity, classes, commentLines } = facts;
25
+ const codeLines = structureCodeLines(facts);
26
+ const counts = [[definitions.cognitiveComplexity, cognitiveComplexity], [definitions.classes, classes],
27
+ [definitions.codeLines, codeLines?.length], [definitions.comments, commentLines]];
28
+ return {
29
+ findings: structuralSmells(path, observations),
30
+ measurements: [
31
+ ...cognitiveFunctions.map(({ line, column, name, value }) => ({ definition: definitions.cognitiveComplexity, target: 'function', path, line, column, name, value })),
32
+ ...counts.flatMap(([definition, value]) => value === undefined ? [] : [{ definition, target: 'file', path, value }]),
33
+ ],
34
+ };
35
+ },
36
+ }],
37
+ }),
38
+ }, { tool: 'repometry', category: 'structure' });
38
39
  //# sourceMappingURL=maintainability.js.map
@@ -1,3 +1,2 @@
1
- import type { StructuralObservation } from '@repometry/core/internal/model/code-structure.js';
2
- import type { Finding } from '@repometry/core/internal/model/finding.js';
1
+ import type { Finding, StructuralObservation } from '@repometry/core/internal/engine/author-contracts.js';
3
2
  export declare function structuralSmells(path: string, observations: readonly StructuralObservation[]): Finding[];
@@ -2,13 +2,13 @@ import { structuralRules } from '@repometry/core/internal/profile/maintainabilit
2
2
  export function structuralSmells(path, observations) {
3
3
  const findings = [];
4
4
  const functionLimit = structuralRules['function-complexity'].limit;
5
- const functionExcess = observations.reduce((total, { rule, value }) => total + (rule === 'function-complexity' ? Math.max(0, value - functionLimit) : 0), 0);
6
- for (const { rule, value, label, line, endLine, anchor } of observations) {
7
- const { limit, minutesPerExcess } = structuralRules[rule];
5
+ const functionExcess = observations.reduce((total, { check, value }) => total + (check === 'function-complexity' ? Math.max(0, value - functionLimit) : 0), 0);
6
+ for (const { check, value, label, line, endLine, anchor } of observations) {
7
+ const { limit, minutesPerExcess } = structuralRules[check];
8
8
  if (value <= limit)
9
9
  continue;
10
- const chargedExcess = rule === 'file-complexity' ? Math.max(0, value - limit - functionExcess) : value - limit;
11
- findings.push({ tool: 'repometry', rule, category: 'structure', level: 'medium', path,
10
+ const chargedExcess = check === 'file-complexity' ? Math.max(0, value - limit - functionExcess) : value - limit;
11
+ findings.push({ check, level: 'medium', path,
12
12
  message: `${label} ${value} (limit ${limit})`, line, endLine, effortMinutes: chargedExcess * minutesPerExcess,
13
13
  value, limit, anchor: anchor ?? '(file)' });
14
14
  }
@@ -1,2 +1,17 @@
1
- import type { Plugin } from '@repometry/core/internal/engine/plugin.js';
2
- export declare const actionsSecurity: Plugin;
1
+ export declare const actionsSecurity: {
2
+ id: string;
3
+ version: string;
4
+ api: string;
5
+ tools?: Readonly<Record<string, string>>;
6
+ operations: readonly import("@repometry/core").Operation[];
7
+ rules?: readonly import("@repometry/core/internal/engine/plugin.js").RuleDescriptor[];
8
+ config?: import("@repometry/core/internal/engine/plugin.js").PluginConfigSchema;
9
+ settings?: import("@repometry/core/internal/model/plugin-data.js").JsonValue;
10
+ kinds: readonly import("@repometry/core/internal/engine/plugin.js").PluginKind[];
11
+ providesLanguages?: readonly import("@repometry/core/internal/model/language.js").ProvidedLanguage[];
12
+ languageProvenanceRequiresSource?: true;
13
+ produces: readonly import("@repometry/core/internal/engine/plugin.js").ProductDeclaration[];
14
+ claims: {
15
+ globs: string[];
16
+ };
17
+ };
@@ -1,5 +1,5 @@
1
- import { pluginApi } from '@repometry/core/internal/engine/plugin.js';
2
- import { findingResult } from '@repometry/core/internal/model/finding.js';
1
+ import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
2
+ import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
3
3
  import { sourceFile } from '@repometry/core/internal/model/snapshot.js';
4
4
  const tool = 'actions-security';
5
5
  const ruleCatalog = {
@@ -20,19 +20,24 @@ const ruleCatalog = {
20
20
  'secrets-inherit': { level: 'low',
21
21
  description: 'A reusable workflow call passes every repository secret with secrets: inherit.' },
22
22
  };
23
+ const paths = ['.github/workflows/*.yml', '.github/workflows/*.yaml', 'action.yml', 'action.yaml'];
23
24
  export const actionsSecurity = {
24
- id: tool, version: '1.0.0', api: pluginApi,
25
- kinds: ['security'],
26
- claims: { globs: ['.github/workflows/*.yml', '.github/workflows/*.yaml', 'action.yml', 'action.yaml'] },
27
- produces: [{ contract: findingResult.id, persistence: 'report' }],
28
- rules: Object.entries(ruleCatalog).map(([id, { description }]) => ({ id, category: 'infrastructure', description })),
29
- operations: [{
30
- id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
31
- execute(inputs) {
32
- const { path, bytes } = inputs.read('source', sourceFile);
33
- return { measurements: [], findings: audit(path, new TextDecoder().decode(bytes)) };
34
- },
35
- }],
25
+ ...bundledPlugin({
26
+ schema: pluginManifestSchema, id: tool, version: '1.0.0', category: 'security',
27
+ include: paths,
28
+ checks: Object.entries(ruleCatalog).map(([id, { description }]) => ({ id, description })),
29
+ create: () => ({
30
+ produces: [{ contract: findingResult.id, persistence: 'report' }],
31
+ operations: [{
32
+ id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
33
+ execute(inputs) {
34
+ const { path, bytes } = inputs.read('source', sourceFile);
35
+ return { measurements: [], findings: audit(path, new TextDecoder().decode(bytes)) };
36
+ },
37
+ }],
38
+ }),
39
+ }, { tool: tool, category: 'infrastructure' }),
40
+ claims: { globs: paths },
36
41
  };
37
42
  function audit(path, text) {
38
43
  const root = new YamlReader(text).read();
@@ -41,7 +46,7 @@ function audit(path, text) {
41
46
  // Aliased nodes are visited once per alias; report each location once.
42
47
  const key = `${rule}\0${line}\0${message}`;
43
48
  if (!findings.has(key)) {
44
- findings.set(key, { tool, rule, category: 'infrastructure', level: ruleCatalog[rule].level, message, path, line });
49
+ findings.set(key, { check: rule, level: ruleCatalog[rule].level, message, path, line });
45
50
  }
46
51
  };
47
52
  const jobs = entryOf(root, 'jobs');
@@ -50,7 +55,7 @@ function audit(path, text) {
50
55
  else
51
56
  for (const step of itemsOf(valueOf(valueOf(root, 'runs'), 'steps')))
52
57
  auditStep(step, undefined, report);
53
- return [...findings.values()].sort((left, right) => left.line - right.line || (left.rule < right.rule ? -1 : left.rule > right.rule ? 1 : 0));
58
+ return [...findings.values()].sort((left, right) => left.line - right.line || (left.check < right.check ? -1 : left.check > right.check ? 1 : 0));
54
59
  }
55
60
  function auditWorkflow(root, jobs, report) {
56
61
  const events = triggers(valueOf(root, 'on'));
@@ -1,2 +1,17 @@
1
- import type { Plugin } from '@repometry/core/internal/engine/plugin.js';
2
- export declare const dockerfile: Plugin;
1
+ export declare const dockerfile: {
2
+ id: string;
3
+ version: string;
4
+ api: string;
5
+ tools?: Readonly<Record<string, string>>;
6
+ operations: readonly import("@repometry/core").Operation[];
7
+ rules?: readonly import("@repometry/core/internal/engine/plugin.js").RuleDescriptor[];
8
+ config?: import("@repometry/core/internal/engine/plugin.js").PluginConfigSchema;
9
+ settings?: import("@repometry/core/internal/model/plugin-data.js").JsonValue;
10
+ kinds: readonly import("@repometry/core/internal/engine/plugin.js").PluginKind[];
11
+ providesLanguages?: readonly import("@repometry/core/internal/model/language.js").ProvidedLanguage[];
12
+ languageProvenanceRequiresSource?: true;
13
+ produces: readonly import("@repometry/core/internal/engine/plugin.js").ProductDeclaration[];
14
+ claims: {
15
+ globs: string[];
16
+ };
17
+ };
@@ -1,5 +1,5 @@
1
- import { pluginApi } from '@repometry/core/internal/engine/plugin.js';
2
- import { findingResult } from '@repometry/core/internal/model/finding.js';
1
+ import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
2
+ import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
3
3
  import { sourceFile } from '@repometry/core/internal/model/snapshot.js';
4
4
  const rules = {
5
5
  'unpinned-base-image': { level: 'medium',
@@ -30,27 +30,32 @@ const secretName = /_(?:[A-Z0-9]*PASS(?:WORD|WD)S?|[A-Z0-9]*SECRETS?|[A-Z0-9]*TO
30
30
  const qualifiers = new Set(['DIR', 'ENABLED', 'ENDPOINT', 'EXPIRES', 'EXPIRY', 'FILE', 'FORMAT', 'HEADER', 'HOST', 'LEN', 'LENGTH',
31
31
  'LIFETIME', 'MODE', 'NAME', 'PATH', 'POLICY', 'PORT', 'REQUIRED', 'SIZE', 'TIMEOUT', 'TTL', 'TYPE', 'URI', 'URL', 'USER',
32
32
  'USERNAME', 'VERSION']);
33
+ const paths = ['**/Dockerfile', '**/Dockerfile.*', '**/*.dockerfile', '**/Containerfile'];
33
34
  export const dockerfile = {
34
- id: 'dockerfile', version: '1.0.0', api: pluginApi,
35
- kinds: ['security'],
36
- claims: { globs: ['**/Dockerfile', '**/Dockerfile.*', '**/*.dockerfile', '**/Containerfile'] },
37
- produces: [{ contract: findingResult.id, persistence: 'report' }],
38
- rules: Object.entries(rules).map(([id, { description }]) => ({ id, category: 'infrastructure', description })),
39
- operations: [{
40
- id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
41
- execute(inputs) {
42
- const { path, bytes } = inputs.read('source', sourceFile);
43
- if (bytes.includes(0))
44
- return { measurements: [], findings: [] };
45
- return { measurements: [], findings: scan(path, new TextDecoder().decode(bytes)) };
46
- },
47
- }],
35
+ ...bundledPlugin({
36
+ schema: pluginManifestSchema, id: 'dockerfile', version: '1.0.0', category: 'security',
37
+ include: paths,
38
+ checks: Object.entries(rules).map(([id, { description }]) => ({ id, description })),
39
+ create: () => ({
40
+ produces: [{ contract: findingResult.id, persistence: 'report' }],
41
+ operations: [{
42
+ id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
43
+ execute(inputs) {
44
+ const { path, bytes } = inputs.read('source', sourceFile);
45
+ if (bytes.includes(0))
46
+ return { measurements: [], findings: [] };
47
+ return { measurements: [], findings: scan(path, new TextDecoder().decode(bytes)) };
48
+ },
49
+ }],
50
+ }),
51
+ }, { tool: 'dockerfile', category: 'infrastructure', categoryBeforeRule: true }),
52
+ claims: { globs: paths },
48
53
  };
49
54
  function scan(path, text) {
50
55
  const { escape, instructions } = parseDockerfile(text);
51
56
  const findings = [];
52
57
  const report = (rule, at, message) => {
53
- findings.push({ tool: 'dockerfile', category: 'infrastructure', rule, level: rules[rule].level, message, path,
58
+ findings.push({ check: rule, level: rules[rule].level, message, path,
54
59
  line: at.line, endLine: at.endLine });
55
60
  };
56
61
  const globals = new Map();
@@ -86,7 +91,7 @@ function scan(path, text) {
86
91
  }
87
92
  checkFinalStage();
88
93
  return findings.sort((left, right) => left.line - right.line || left.endLine - right.endLine
89
- || left.rule.localeCompare(right.rule));
94
+ || left.check.localeCompare(right.check));
90
95
  function startStage(instruction) {
91
96
  const [reference = '', as, name] = words(instruction.args, escape).filter(item => !item.startsWith('--'));
92
97
  const image = expand(reference, globals);
@@ -1,4 +1,19 @@
1
- import type { Plugin } from '@repometry/core/internal/engine/plugin.js';
2
1
  /** Above this many hits of one rule in one file, the rest collapse into a single summary finding. */
3
2
  export declare const findingsPerRule = 20;
4
- export declare const npmSupplyChain: Plugin;
3
+ export declare const npmSupplyChain: {
4
+ id: string;
5
+ version: string;
6
+ api: string;
7
+ tools?: Readonly<Record<string, string>>;
8
+ operations: readonly import("@repometry/core/internal/engine/plugin.js").Operation[];
9
+ rules?: readonly import("@repometry/core/internal/engine/plugin.js").RuleDescriptor[];
10
+ config?: import("@repometry/core/internal/engine/plugin.js").PluginConfigSchema;
11
+ settings?: import("@repometry/core/internal/model/plugin-data.js").JsonValue;
12
+ kinds: readonly import("@repometry/core/internal/engine/plugin.js").PluginKind[];
13
+ providesLanguages?: readonly import("@repometry/core/internal/model/language.js").ProvidedLanguage[];
14
+ languageProvenanceRequiresSource?: true;
15
+ produces: readonly import("@repometry/core/internal/engine/plugin.js").ProductDeclaration[];
16
+ claims: {
17
+ globs: string[];
18
+ };
19
+ };
@@ -1,5 +1,6 @@
1
- import { isRecord, pluginApi } from '@repometry/core/internal/engine/plugin.js';
2
- import { findingResult } from '@repometry/core/internal/model/finding.js';
1
+ import { isRecord } from '@repometry/core/internal/engine/plugin.js';
2
+ import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
3
+ import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
3
4
  import { sourceFile } from '@repometry/core/internal/model/snapshot.js';
4
5
  const tool = 'npm-supply-chain';
5
6
  const ruleDescriptions = {
@@ -19,27 +20,32 @@ const installScripts = ['preinstall', 'install', 'postinstall'];
19
20
  const levelOrder = ['low', 'medium', 'high'];
20
21
  /** A repository page URL such as https://github.com/owner/repo, which npm clones with git. */
21
22
  const hostedRepository = /^https:\/\/(?:www\.)?(?:github\.com|gitlab\.com|bitbucket\.org)\/[^/?#]+\/[^/?#]+\/?(?:#.*)?$/i;
23
+ const paths = ['**/package.json', '**/package-lock.json', '**/npm-shrinkwrap.json', '**/yarn.lock', '**/pnpm-lock.yaml'];
22
24
  export const npmSupplyChain = {
23
- id: tool, version: '1.0.0', api: pluginApi,
24
- kinds: ['security'],
25
- claims: { globs: ['**/package.json', '**/package-lock.json', '**/npm-shrinkwrap.json', '**/yarn.lock', '**/pnpm-lock.yaml'] },
26
- produces: [{ contract: findingResult.id, persistence: 'report' }],
27
- rules: Object.entries(ruleDescriptions).map(([id, description]) => ({ id, category: 'dependency', description })),
28
- operations: [{
29
- id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
30
- execute(inputs) {
31
- const { path, bytes } = inputs.read('source', sourceFile);
32
- if (path.split('/').includes('node_modules'))
33
- return { measurements: [], findings: [] };
34
- const name = path.slice(path.lastIndexOf('/') + 1);
35
- const text = new TextDecoder().decode(bytes);
36
- const hits = name === 'package.json' ? jsonHits(name, text, manifestHits)
37
- : name === 'package-lock.json' || name === 'npm-shrinkwrap.json' ? jsonHits(name, text, packageLockHits)
38
- : name === 'yarn.lock' ? yarnLockHits(text)
39
- : name === 'pnpm-lock.yaml' ? pnpmLockHits(text) : [];
40
- return { measurements: [], findings: capped(path, name, hits) };
41
- },
42
- }],
25
+ ...bundledPlugin({
26
+ schema: pluginManifestSchema, id: tool, version: '1.0.0', category: 'security',
27
+ include: paths,
28
+ checks: Object.entries(ruleDescriptions).map(([id, description]) => ({ id, description })),
29
+ create: () => ({
30
+ produces: [{ contract: findingResult.id, persistence: 'report' }],
31
+ operations: [{
32
+ id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
33
+ execute(inputs) {
34
+ const { path, bytes } = inputs.read('source', sourceFile);
35
+ if (path.split('/').includes('node_modules'))
36
+ return { measurements: [], findings: [] };
37
+ const name = path.slice(path.lastIndexOf('/') + 1);
38
+ const text = new TextDecoder().decode(bytes);
39
+ const hits = name === 'package.json' ? jsonHits(name, text, manifestHits)
40
+ : name === 'package-lock.json' || name === 'npm-shrinkwrap.json' ? jsonHits(name, text, packageLockHits)
41
+ : name === 'yarn.lock' ? yarnLockHits(text)
42
+ : name === 'pnpm-lock.yaml' ? pnpmLockHits(text) : [];
43
+ return { measurements: [], findings: capped(path, name, hits) };
44
+ },
45
+ }],
46
+ }),
47
+ }, { tool: tool, category: 'dependency' }),
48
+ claims: { globs: paths },
43
49
  };
44
50
  function capped(path, name, hits) {
45
51
  const byLine = [...hits].sort((left, right) => (left.line ?? 0) - (right.line ?? 0));
@@ -52,11 +58,11 @@ function capped(path, name, hits) {
52
58
  if (rest.length === 0)
53
59
  continue;
54
60
  const level = rest.reduce((worst, hit) => levelOrder.indexOf(hit.level) > levelOrder.indexOf(worst) ? hit.level : worst, 'low');
55
- summaries.push({ tool, rule, category: 'dependency', level, path,
61
+ summaries.push({ check: rule, level, path,
56
62
  message: `${name} has ${matching.length} ${rule} findings; only the first ${findingsPerRule} are listed.` });
57
63
  }
58
64
  kept.sort((left, right) => (left.line ?? 0) - (right.line ?? 0));
59
- return [...kept.map(({ rule, level, message, line, endLine }) => ({ tool, rule, category: 'dependency', level, message, path,
65
+ return [...kept.map(({ rule, level, message, line, endLine }) => ({ check: rule, level, message, path,
60
66
  ...(line === undefined ? {} : { line, endLine: endLine ?? line }) })), ...summaries];
61
67
  }
62
68
  function jsonHits(name, text, analyse) {
@@ -1,12 +1,24 @@
1
- import type { Plugin, RuleDescriptor } from '@repometry/core/internal/engine/plugin.js';
2
- import type { Finding } from '@repometry/core/internal/model/finding.js';
3
1
  /** A line that contains this marker is never reported. */
4
2
  export declare const ignoreMarker = "repometry-ignore-secret";
5
3
  /** Files larger than this are not scanned. */
6
4
  export declare const maxScannedBytes: number;
7
5
  export declare function isPlaceholder(value: string): boolean;
8
6
  export declare function shannonEntropy(value: string): number;
9
- export declare const secretRules: readonly RuleDescriptor[];
10
- /** Scans one file. Secret values never reach a finding: messages name only the kind of secret. */
11
- export declare function scanSecrets(path: string, bytes: Uint8Array): Finding[];
12
- export declare const secrets: Plugin;
7
+ export declare const secrets: {
8
+ id: string;
9
+ version: string;
10
+ api: string;
11
+ tools?: Readonly<Record<string, string>>;
12
+ operations: readonly import("@repometry/core/internal/engine/plugin.js").Operation[];
13
+ rules?: readonly import("@repometry/core/internal/engine/plugin.js").RuleDescriptor[];
14
+ config?: import("@repometry/core/internal/engine/plugin.js").PluginConfigSchema;
15
+ settings?: import("@repometry/core/internal/model/plugin-data.js").JsonValue;
16
+ kinds: readonly import("@repometry/core/internal/engine/plugin.js").PluginKind[];
17
+ providesLanguages?: readonly import("@repometry/core/internal/model/language.js").ProvidedLanguage[];
18
+ languageProvenanceRequiresSource?: true;
19
+ produces: readonly import("@repometry/core/internal/engine/plugin.js").ProductDeclaration[];
20
+ claims: {
21
+ globs: string[];
22
+ scanOnly: boolean;
23
+ };
24
+ };
@@ -1,5 +1,6 @@
1
- import { isRecord, pluginApi } from '@repometry/core/internal/engine/plugin.js';
2
- import { findingResult } from '@repometry/core/internal/model/finding.js';
1
+ import { isRecord } from '@repometry/core/internal/engine/plugin.js';
2
+ import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
3
+ import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
3
4
  import { sourceFile } from '@repometry/core/internal/model/snapshot.js';
4
5
  /** A line that contains this marker is never reported. */
5
6
  export const ignoreMarker = 'repometry-ignore-secret';
@@ -143,16 +144,14 @@ function assignedSecret(line, claimed) {
143
144
  }
144
145
  return undefined;
145
146
  }
146
- const genericRule = { id: 'generic-secret-assignment', category: 'secret',
147
+ const genericRule = { id: 'generic-secret-assignment',
147
148
  description: 'Flags a quoted high-entropy literal of 16 or more characters assigned to a password, secret, token or API key name, '
148
149
  + `ignoring placeholders such as example, dummy, changeme, xxx, \${...} and process.env; ${skipped}.` };
149
- const sensitiveRule = { id: 'sensitive-file', category: 'secret',
150
+ const sensitiveRule = { id: 'sensitive-file',
150
151
  description: 'Flags files that usually hold credentials: .env and .env.* except .env.example, .env.sample and .env.template, '
151
152
  + '*.pem and *.key unless they hold only public certificates or keys, *.p12, *.pfx, id_rsa, id_dsa, id_ecdsa, id_ed25519, '
152
153
  + `.git-credentials, and .npmrc or .pypirc with a literal auth token; ${ignoreMarker} on the first line skips the file.` };
153
- export const secretRules = [
154
- ...lineRules.map(({ id, description }) => ({ id, category: 'secret', description })), genericRule, sensitiveRule,
155
- ];
154
+ const secretRules = [...lineRules.map(({ id, description }) => ({ id, description })), genericRule, sensitiveRule];
156
155
  const sshKeys = new Set(['id_rsa', 'id_dsa', 'id_ecdsa', 'id_ed25519']);
157
156
  const envTemplates = new Set(['example', 'sample', 'template']);
158
157
  const publicPem = /^(?:(?:TRUSTED |X509 )?CERTIFICATE|(?:NEW )?CERTIFICATE REQUEST|X509 CRL|(?:RSA |SSH2 )?PUBLIC KEY|PKCS7|CMS|(?:DH|EC) PARAMETERS)$/;
@@ -193,7 +192,7 @@ function sensitiveTextKind(name, lines) {
193
192
  return undefined;
194
193
  }
195
194
  function finding(rule, level, message, path, line) {
196
- return { tool: 'secrets', rule, category: 'secret', level, message, path, line, endLine: line };
195
+ return { check: rule, level, message, path, line, endLine: line };
197
196
  }
198
197
  function lineFindings(path, context) {
199
198
  const line = context.lines[context.index];
@@ -206,7 +205,7 @@ function lineFindings(path, context) {
206
205
  if (!rule.accept(match, context))
207
206
  continue;
208
207
  claimed.push([match.index ?? 0, (match.index ?? 0) + match[0].length]);
209
- if (!findings.some(item => item.rule === rule.id))
208
+ if (!findings.some(item => item.check === rule.id))
210
209
  findings.push(finding(rule.id, rule.level, rule.message, path, context.index + 1));
211
210
  }
212
211
  }
@@ -216,7 +215,7 @@ function lineFindings(path, context) {
216
215
  return findings;
217
216
  }
218
217
  /** Scans one file. Secret values never reach a finding: messages name only the kind of secret. */
219
- export function scanSecrets(path, bytes) {
218
+ function scanSecrets(path, bytes) {
220
219
  if (bytes.length > maxScannedBytes)
221
220
  return [];
222
221
  const name = path.slice(path.lastIndexOf('/') + 1);
@@ -236,19 +235,24 @@ export function scanSecrets(path, bytes) {
236
235
  }
237
236
  return findings;
238
237
  }
238
+ // The dotfile selector includes credentials stored in hidden files and directories.
239
+ const paths = ['**/*', '**/.*'];
239
240
  export const secrets = {
240
- id: 'secrets', version: '1.0.0', api: pluginApi,
241
- kinds: ['security'],
242
- // `**/*` skips dotfiles, so `**/.*` adds .env, .npmrc and files under dot directories.
243
- claims: { globs: ['**/*', '**/.*'], scanOnly: true },
244
- produces: [{ contract: findingResult.id, persistence: 'report' }],
245
- rules: secretRules,
246
- operations: [{
247
- id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
248
- execute(inputs) {
249
- const { path, bytes } = inputs.read('source', sourceFile);
250
- return { measurements: [], findings: scanSecrets(path, bytes) };
251
- },
252
- }],
241
+ ...bundledPlugin({
242
+ schema: pluginManifestSchema, id: 'secrets', version: '1.0.0', category: 'security',
243
+ include: paths,
244
+ checks: secretRules,
245
+ create: () => ({
246
+ produces: [{ contract: findingResult.id, persistence: 'report' }],
247
+ operations: [{
248
+ id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
249
+ execute(inputs) {
250
+ const { path, bytes } = inputs.read('source', sourceFile);
251
+ return { measurements: [], findings: scanSecrets(path, bytes) };
252
+ },
253
+ }],
254
+ }),
255
+ }, { tool: 'secrets', category: 'secret' }),
256
+ claims: { globs: paths, scanOnly: true },
253
257
  };
254
258
  //# sourceMappingURL=secrets.js.map
@@ -1,35 +1,28 @@
1
- import { pluginApi } from '@repometry/core/internal/engine/plugin.js';
2
- const manifest = {
3
- api: pluginApi, version: '1.0.0', kinds: ['source'],
4
- operations: [], produces: [{ contract: 'repometry.source-locator/v1', persistence: 'transient' }],
5
- };
6
- export const localSource = {
7
- ...manifest, id: 'local',
8
- locate: () => ({ provider: 'local', url: './sources/{revision}/{path}' }),
9
- };
10
- export const githubSource = {
11
- ...manifest, id: 'github',
12
- locate(context) {
13
- const project = forgeProject(context, 'github.com', context.env.GITHUB_REPOSITORY, context.env.GITHUB_SERVER_URL, 2);
14
- if (!project)
15
- return undefined;
16
- const { origin, path } = project;
17
- const url = origin === 'https://github.com' ? `https://raw.githubusercontent.com/${path}/{revision}/{path}`
18
- : `${origin}/${path}/raw/{revision}/{path}`;
19
- return { provider: 'github', url, web: `${origin}/${path}/blob/{revision}/{path}#L{line}` };
20
- },
21
- };
22
- export const gitlabSource = {
23
- ...manifest, id: 'gitlab',
24
- locate(context) {
25
- const project = forgeProject(context, 'gitlab.com', context.env.CI_PROJECT_PATH, context.env.CI_SERVER_URL);
26
- if (!project)
27
- return undefined;
28
- const { origin, path } = project;
29
- return { provider: 'gitlab', url: `${origin}/api/v4/projects/${encodeURIComponent(path)}/repository/files/{path:component}/raw?ref={revision}`,
30
- web: `${origin}/${path}/-/blob/{revision}/{path}#L{line}` };
31
- },
32
- };
1
+ import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
2
+ function sourcePlugin(id, locate) {
3
+ return { ...bundledPlugin({
4
+ schema: pluginManifestSchema, id, version: '1.0.0', category: 'source',
5
+ create: () => ({ operations: [], produces: [{ contract: 'repometry.source-locator/v1', persistence: 'transient' }] }),
6
+ }), locate };
7
+ }
8
+ export const localSource = sourcePlugin('local', () => ({ provider: 'local', url: './sources/{revision}/{path}' }));
9
+ export const githubSource = sourcePlugin('github', (context) => {
10
+ const project = forgeProject(context, 'github.com', context.env.GITHUB_REPOSITORY, context.env.GITHUB_SERVER_URL, 2);
11
+ if (!project)
12
+ return undefined;
13
+ const { origin, path } = project;
14
+ const url = origin === 'https://github.com' ? `https://raw.githubusercontent.com/${path}/{revision}/{path}`
15
+ : `${origin}/${path}/raw/{revision}/{path}`;
16
+ return { provider: 'github', url, web: `${origin}/${path}/blob/{revision}/{path}#L{line}` };
17
+ });
18
+ export const gitlabSource = sourcePlugin('gitlab', (context) => {
19
+ const project = forgeProject(context, 'gitlab.com', context.env.CI_PROJECT_PATH, context.env.CI_SERVER_URL);
20
+ if (!project)
21
+ return undefined;
22
+ const { origin, path } = project;
23
+ return { provider: 'gitlab', url: `${origin}/api/v4/projects/${encodeURIComponent(path)}/repository/files/{path:component}/raw?ref={revision}`,
24
+ web: `${origin}/${path}/-/blob/{revision}/{path}#L{line}` };
25
+ });
33
26
  function forgeProject(context, host, ciProject, ciServer, segments) {
34
27
  if (context.option !== undefined && context.option !== '') {
35
28
  const explicit = remoteProject(context.option) ?? projectAt('https://' + host, context.option);
@@ -225,7 +225,8 @@ function scanShellPart(cursor, wordStart) {
225
225
  }
226
226
  export function sourceTokenizer(path) {
227
227
  const syntax = syntaxOf(path);
228
- if (syntax === undefined && languageIdOf(path) === 'shell' && /\.(?:sh|bash)$/i.test(path)) {
228
+ const language = languageIdOf(path);
229
+ if (syntax === undefined && (language === 'shell' || language === 'bash') && /\.(?:sh|bash)$/i.test(path)) {
229
230
  return scanLines(shellGrammar, scanShellLine);
230
231
  }
231
232
  return tokenizer(syntax);