repometry 0.4.1 → 0.5.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 (190) hide show
  1. package/README.md +4 -0
  2. package/package.json +1 -1
  3. package/target/main/resources/report/json/report-v2.schema.json +13 -1
  4. package/target/main/resources/viewer/files.css +7 -3
  5. package/target/main/resources/viewer/styles.css +2 -2
  6. package/target/main/ts/api/git/git.d.ts +1 -0
  7. package/target/main/ts/api/git/git.js +12 -0
  8. package/target/main/ts/api/git/inspection-source.js +2 -8
  9. package/target/main/ts/api/git/local.d.ts +1 -1
  10. package/target/main/ts/api/git/local.js +39 -5
  11. package/target/main/ts/api/process/docker-tool-runner.d.ts +13 -0
  12. package/target/main/ts/api/process/docker-tool-runner.js +108 -0
  13. package/target/main/ts/api/process/failure.d.ts +1 -0
  14. package/target/main/ts/api/process/failure.js +12 -0
  15. package/target/main/ts/api/process/plugin.d.ts +10 -0
  16. package/target/main/ts/api/process/plugin.js +96 -0
  17. package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
  18. package/target/main/ts/compose/analyze-snapshot.js +82 -29
  19. package/target/main/ts/compose/inspect.d.ts +5 -0
  20. package/target/main/ts/compose/inspect.js +10 -6
  21. package/target/main/ts/core/engine/execute.d.ts +3 -1
  22. package/target/main/ts/core/engine/execute.js +14 -2
  23. package/target/main/ts/core/engine/operation-cache.d.ts +14 -0
  24. package/target/main/ts/core/engine/operation-cache.js +66 -0
  25. package/target/main/ts/core/engine/plan.d.ts +1 -0
  26. package/target/main/ts/core/engine/plan.js +22 -3
  27. package/target/main/ts/core/engine/plugin.d.ts +8 -1
  28. package/target/main/ts/core/engine/plugin.js +1 -3
  29. package/target/main/ts/core/engine/report-products.js +2 -13
  30. package/target/main/ts/core/model/clone-source.js +1 -1
  31. package/target/main/ts/core/model/code-structure.d.ts +3 -0
  32. package/target/main/ts/core/model/code-structure.js +4 -1
  33. package/target/main/ts/core/model/finding-ignore.js +1 -1
  34. package/target/main/ts/core/model/finding.js +1 -1
  35. package/target/main/ts/core/model/line-coverage.d.ts +5 -1
  36. package/target/main/ts/core/model/line-coverage.js +14 -11
  37. package/target/main/ts/core/model/measurement.js +1 -1
  38. package/target/main/ts/core/model/plugin-data.d.ts +2 -0
  39. package/target/main/ts/core/model/plugin-data.js +15 -1
  40. package/target/main/ts/core/model/quality-summary.js +1 -1
  41. package/target/main/ts/core/model/scanner-import.js +1 -1
  42. package/target/main/ts/core/model/snapshot.d.ts +1 -0
  43. package/target/main/ts/core/model/snapshot.js +5 -1
  44. package/target/main/ts/core/model/source.d.ts +3 -0
  45. package/target/main/ts/core/model/source.js +15 -0
  46. package/target/main/ts/core/ports/tool-runner.d.ts +18 -0
  47. package/target/main/ts/core/ports/tool-runner.js +2 -0
  48. package/target/main/ts/plugin.d.ts +7 -1
  49. package/target/main/ts/plugin.js +3 -1
  50. package/target/main/ts/plugins/coverage/coverage.d.ts +5 -2
  51. package/target/main/ts/plugins/coverage/coverage.js +35 -10
  52. package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -0
  53. package/target/main/ts/plugins/language-js/function-facts.js +30 -4
  54. package/target/main/ts/report/html/app/viewer-chart-bars.d.ts +11 -0
  55. package/target/main/ts/report/html/app/viewer-chart-bars.js +54 -0
  56. package/target/main/ts/report/html/app/viewer-chart-label.d.ts +15 -0
  57. package/target/main/ts/report/html/app/viewer-chart-label.js +43 -0
  58. package/target/main/ts/report/html/app/viewer-chart-line.d.ts +24 -0
  59. package/target/main/ts/report/html/app/viewer-chart-line.js +89 -0
  60. package/target/main/ts/report/html/app/viewer-chart-points.d.ts +49 -0
  61. package/target/main/ts/report/html/app/viewer-chart-points.js +74 -0
  62. package/target/main/ts/report/html/app/viewer-chart-scale.d.ts +21 -0
  63. package/target/main/ts/report/html/app/viewer-chart-scale.js +93 -0
  64. package/target/main/ts/report/html/app/viewer-chart-svg.d.ts +28 -0
  65. package/target/main/ts/report/html/app/viewer-chart-svg.js +41 -0
  66. package/target/main/ts/report/html/app/viewer-chart-time.d.ts +26 -0
  67. package/target/main/ts/report/html/app/viewer-chart-time.js +150 -0
  68. package/target/main/ts/report/html/app/viewer-chart-tip.d.ts +4 -0
  69. package/target/main/ts/report/html/app/viewer-chart-tip.js +210 -0
  70. package/target/main/ts/report/html/app/viewer-chart-x.d.ts +12 -0
  71. package/target/main/ts/report/html/app/viewer-chart-x.js +50 -0
  72. package/target/main/ts/report/html/app/viewer-chart.d.ts +4 -98
  73. package/target/main/ts/report/html/app/viewer-chart.js +16 -677
  74. package/target/main/ts/report/html/app/viewer-code-map.d.ts +27 -0
  75. package/target/main/ts/report/html/app/viewer-code-map.js +175 -0
  76. package/target/main/ts/report/html/app/viewer-columns.d.ts +38 -0
  77. package/target/main/ts/report/html/app/viewer-columns.js +92 -0
  78. package/target/main/ts/report/html/app/viewer-commit-picker.d.ts +12 -0
  79. package/target/main/ts/report/html/app/viewer-commit-picker.js +229 -0
  80. package/target/main/ts/report/html/app/viewer-commits.d.ts +5 -9
  81. package/target/main/ts/report/html/app/viewer-commits.js +17 -216
  82. package/target/main/ts/report/html/app/viewer-controls.d.ts +43 -0
  83. package/target/main/ts/report/html/app/viewer-controls.js +141 -0
  84. package/target/main/ts/report/html/app/viewer-copy.d.ts +17 -0
  85. package/target/main/ts/report/html/app/viewer-copy.js +64 -0
  86. package/target/main/ts/report/html/app/viewer-diagnostics.d.ts +4 -0
  87. package/target/main/ts/report/html/app/viewer-diagnostics.js +60 -0
  88. package/target/main/ts/report/html/app/viewer-dom.d.ts +27 -0
  89. package/target/main/ts/report/html/app/viewer-dom.js +99 -0
  90. package/target/main/ts/report/html/app/viewer-file-aside.d.ts +19 -0
  91. package/target/main/ts/report/html/app/viewer-file-aside.js +124 -0
  92. package/target/main/ts/report/html/app/viewer-file-figures.d.ts +15 -0
  93. package/target/main/ts/report/html/app/viewer-file-figures.js +60 -0
  94. package/target/main/ts/report/html/app/viewer-file-source.d.ts +7 -0
  95. package/target/main/ts/report/html/app/viewer-file-source.js +119 -0
  96. package/target/main/ts/report/html/app/viewer-files.d.ts +2 -118
  97. package/target/main/ts/report/html/app/viewer-files.js +24 -2184
  98. package/target/main/ts/report/html/app/viewer-filter.d.ts +3 -51
  99. package/target/main/ts/report/html/app/viewer-filter.js +111 -450
  100. package/target/main/ts/report/html/app/viewer-hotspots.d.ts +4 -0
  101. package/target/main/ts/report/html/app/viewer-hotspots.js +131 -0
  102. package/target/main/ts/report/html/app/viewer-inspection.d.ts +69 -0
  103. package/target/main/ts/report/html/app/viewer-inspection.js +36 -0
  104. package/target/main/ts/report/html/app/viewer-issue-group.d.ts +27 -0
  105. package/target/main/ts/report/html/app/viewer-issue-group.js +174 -0
  106. package/target/main/ts/report/html/app/viewer-issues.d.ts +4 -0
  107. package/target/main/ts/report/html/app/viewer-issues.js +173 -0
  108. package/target/main/ts/report/html/app/viewer-language-bar.d.ts +9 -0
  109. package/target/main/ts/report/html/app/viewer-language-bar.js +72 -0
  110. package/target/main/ts/report/html/app/viewer-languages.d.ts +27 -0
  111. package/target/main/ts/report/html/app/viewer-languages.js +93 -0
  112. package/target/main/ts/report/html/app/viewer-layout.d.ts +14 -0
  113. package/target/main/ts/report/html/app/viewer-layout.js +134 -0
  114. package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +47 -0
  115. package/target/main/ts/report/html/app/viewer-line-coverage.js +121 -0
  116. package/target/main/ts/report/html/app/viewer-locations.d.ts +16 -0
  117. package/target/main/ts/report/html/app/viewer-locations.js +31 -0
  118. package/target/main/ts/report/html/app/viewer-map-scale.d.ts +26 -0
  119. package/target/main/ts/report/html/app/viewer-map-scale.js +147 -0
  120. package/target/main/ts/report/html/app/viewer-map-shape.d.ts +42 -0
  121. package/target/main/ts/report/html/app/viewer-map-shape.js +102 -0
  122. package/target/main/ts/report/html/app/viewer-metric-format.d.ts +23 -0
  123. package/target/main/ts/report/html/app/viewer-metric-format.js +93 -0
  124. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -20
  125. package/target/main/ts/report/html/app/viewer-metric-registry.js +0 -77
  126. package/target/main/ts/report/html/app/viewer-metrics-view.d.ts +4 -0
  127. package/target/main/ts/report/html/app/viewer-metrics-view.js +162 -0
  128. package/target/main/ts/report/html/app/viewer-metrics.d.ts +6 -1
  129. package/target/main/ts/report/html/app/viewer-metrics.js +53 -35
  130. package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +12 -0
  131. package/target/main/ts/report/html/app/viewer-overview-cards.js +112 -0
  132. package/target/main/ts/report/html/app/viewer-overview-hotspots.d.ts +9 -0
  133. package/target/main/ts/report/html/app/viewer-overview-hotspots.js +173 -0
  134. package/target/main/ts/report/html/app/viewer-overview-lead.d.ts +12 -0
  135. package/target/main/ts/report/html/app/viewer-overview-lead.js +116 -0
  136. package/target/main/ts/report/html/app/viewer-profile-badges.d.ts +11 -0
  137. package/target/main/ts/report/html/app/viewer-profile-badges.js +119 -0
  138. package/target/main/ts/report/html/app/viewer-profile-table.d.ts +29 -0
  139. package/target/main/ts/report/html/app/viewer-profile-table.js +124 -0
  140. package/target/main/ts/report/html/app/viewer-profile.d.ts +2 -6
  141. package/target/main/ts/report/html/app/viewer-profile.js +6 -248
  142. package/target/main/ts/report/html/app/viewer-pull-sections.d.ts +4 -0
  143. package/target/main/ts/report/html/app/viewer-pull-sections.js +118 -0
  144. package/target/main/ts/report/html/app/viewer-pull-trend.d.ts +5 -0
  145. package/target/main/ts/report/html/app/viewer-pull-trend.js +63 -0
  146. package/target/main/ts/report/html/app/viewer-pulls.d.ts +0 -1
  147. package/target/main/ts/report/html/app/viewer-pulls.js +28 -178
  148. package/target/main/ts/report/html/app/viewer-query-field.d.ts +19 -0
  149. package/target/main/ts/report/html/app/viewer-query-field.js +203 -0
  150. package/target/main/ts/report/html/app/viewer-route.d.ts +34 -0
  151. package/target/main/ts/report/html/app/viewer-route.js +55 -0
  152. package/target/main/ts/report/html/app/viewer-shell.d.ts +20 -0
  153. package/target/main/ts/report/html/app/viewer-shell.js +116 -0
  154. package/target/main/ts/report/html/app/viewer-source-view.d.ts +49 -0
  155. package/target/main/ts/report/html/app/viewer-source-view.js +150 -0
  156. package/target/main/ts/report/html/app/viewer-source.d.ts +0 -84
  157. package/target/main/ts/report/html/app/viewer-source.js +7 -363
  158. package/target/main/ts/report/html/app/viewer-suggest.d.ts +13 -0
  159. package/target/main/ts/report/html/app/viewer-suggest.js +91 -0
  160. package/target/main/ts/report/html/app/viewer-sunburst.d.ts +5 -0
  161. package/target/main/ts/report/html/app/viewer-sunburst.js +40 -0
  162. package/target/main/ts/report/html/app/viewer-table-cells.d.ts +25 -0
  163. package/target/main/ts/report/html/app/viewer-table-cells.js +129 -0
  164. package/target/main/ts/report/html/app/viewer-table-rows.d.ts +54 -0
  165. package/target/main/ts/report/html/app/viewer-table-rows.js +95 -0
  166. package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +16 -0
  167. package/target/main/ts/report/html/app/viewer-tokenizer.js +192 -0
  168. package/target/main/ts/report/html/app/viewer-totals.d.ts +14 -0
  169. package/target/main/ts/report/html/app/viewer-totals.js +89 -0
  170. package/target/main/ts/report/html/app/viewer-treemap.d.ts +24 -0
  171. package/target/main/ts/report/html/app/viewer-treemap.js +112 -0
  172. package/target/main/ts/report/html/app/viewer-trend-data.d.ts +49 -0
  173. package/target/main/ts/report/html/app/viewer-trend-data.js +105 -0
  174. package/target/main/ts/report/html/app/viewer-trend-nav.d.ts +5 -0
  175. package/target/main/ts/report/html/app/viewer-trend-nav.js +85 -0
  176. package/target/main/ts/report/html/app/viewer-trend-points.d.ts +30 -0
  177. package/target/main/ts/report/html/app/viewer-trend-points.js +128 -0
  178. package/target/main/ts/report/html/app/viewer-trend-series.d.ts +26 -0
  179. package/target/main/ts/report/html/app/viewer-trend-series.js +98 -0
  180. package/target/main/ts/report/html/app/viewer-trends.d.ts +2 -70
  181. package/target/main/ts/report/html/app/viewer-trends.js +41 -392
  182. package/target/main/ts/report/html/app/viewer.js +152 -663
  183. package/target/main/ts/report/html/site/badges.js +41 -18
  184. package/target/main/ts/report/json/store/local-store.js +2 -12
  185. package/target/main/ts/report/json/store/operation-cache.d.ts +8 -0
  186. package/target/main/ts/report/json/store/operation-cache.js +32 -0
  187. package/target/main/ts/report/json/store/replace-file.d.ts +1 -0
  188. package/target/main/ts/report/json/store/replace-file.js +14 -0
  189. package/target/main/ts/report.d.ts +1 -0
  190. package/target/main/ts/report.js +1 -0
@@ -1,15 +1,19 @@
1
+ import { isIgnored, isLockfile, languageOf } from './viewer-languages.js';
1
2
  import { labelOf } from './viewer-metrics.js';
3
+ function byKind(table, clause) {
4
+ return table[clause.kind](clause);
5
+ }
6
+ function ratio(part, whole) {
7
+ return part !== undefined && whole !== undefined && whole > 0 ? part / whole : null;
8
+ }
2
9
  const measures = {
3
10
  complexity: { label: labelOf('complexity'), read: entry => entry.complexity?.maximum ?? null },
4
11
  cognitive: { label: labelOf('cognitive'), read: entry => entry.quality?.cognitiveComplexity ?? null },
5
12
  lines: { label: labelOf('code-lines'), read: entry => entry.quality?.codeLines ?? entry.lines },
6
13
  functions: { label: 'Functions', read: entry => entry.functions },
7
- coverage: { label: labelOf('coverage'), percent: true,
8
- read: entry => entry.lineCoverage && entry.lineCoverage.total > 0 ? entry.lineCoverage.covered / entry.lineCoverage.total : null },
9
- duplication: { label: 'Duplication', percent: true, read: entry => {
10
- const duplication = entry.quality?.duplication;
11
- return duplication && duplication.codeLines > 0 ? duplication.duplicatedLines / duplication.codeLines : null;
12
- } },
14
+ coverage: { label: labelOf('coverage'), percent: true, read: entry => ratio(entry.lineCoverage?.covered, entry.lineCoverage?.total) },
15
+ duplication: { label: 'Duplication', percent: true,
16
+ read: entry => ratio(entry.quality?.duplication?.duplicatedLines, entry.quality?.duplication?.codeLines) },
13
17
  remediation: { label: labelOf('effort'), minutes: true, read: entry => entry.quality?.maintainability?.effortMinutes ?? null },
14
18
  changes: { label: 'Git changes', read: entry => entry.quality?.churn ?? null },
15
19
  };
@@ -18,102 +22,12 @@ let pluginMeasures = new Map();
18
22
  export function usePluginMeasures(entries) {
19
23
  pluginMeasures = new Map(entries);
20
24
  }
21
- function measureOf(name) {
22
- return name in measures ? measures[name] : pluginMeasures.get(name);
23
- }
24
- /**
25
- * Dependency lockfiles, by exact file name. They are generated, often the largest files in a repository, and no
26
- * plugin reads them: the language bar and the Metrics list give them a category of their own beside the ignored files.
27
- */
28
- export const lockfileNames = new Set([
29
- 'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lock', 'bun.lockb', 'deno.lock',
30
- 'Cargo.lock', 'Gemfile.lock', 'composer.lock', 'poetry.lock', 'Pipfile.lock', 'uv.lock', 'go.sum', 'flake.lock',
31
- 'mix.lock', 'pubspec.lock', 'packages.lock.json', 'gradle.lockfile',
32
- ]);
33
- /** Whether a path names a lockfile: its file name, at any depth, exactly as the tools write it. */
34
- export function isLockfile(path) {
35
- return lockfileNames.has(path.slice(path.lastIndexOf('/') + 1));
36
- }
37
- /** Whether no plugin read a file and it is not a lockfile: what the interface calls ignored. */
38
- export function isIgnored(entry) {
39
- return entry.analysed === false && !isLockfile(entry.path);
40
- }
41
- /** The language bar's names for the two categories that are not languages. */
42
- export const lockfilesLabel = 'Lockfiles';
43
- export const ignoredLabel = 'Ignored';
44
- /** Whether every file carries its size: inspections made before sizes were recorded carry none. */
45
- export function sized(files) {
46
- return files.length > 0 && files.every(entry => entry.bytes !== undefined);
47
- }
48
- /**
49
- * What the language bar weighs, largest language first, then lockfiles, then the ignored files. Size in bytes when
50
- * every file has it: one measure for code, lockfiles and ignored files alike, untouched by formatting. Without sizes,
51
- * physical lines where any file is only counted (the one line measure all files have), otherwise code lines.
52
- */
53
- export function languageShares(files) {
54
- const measure = sized(files) ? 'bytes'
55
- : files.some(entry => entry.analysed === false || isLockfile(entry.path)) ? 'lines' : 'code-lines';
56
- const weightOf = (entry) => (measure === 'bytes' ? entry.bytes
57
- : measure === 'lines' ? entry.lines : entry.quality?.codeLines ?? entry.lines) ?? 0;
58
- const weights = new Map();
59
- let lockfiles = 0;
60
- let ignored = 0;
61
- for (const entry of files) {
62
- if (isLockfile(entry.path))
63
- lockfiles += weightOf(entry);
64
- else if (entry.analysed === false)
65
- ignored += weightOf(entry);
66
- else {
67
- const language = languageOf(entry.path);
68
- weights.set(language, (weights.get(language) ?? 0) + weightOf(entry));
69
- }
70
- }
71
- const shares = [...weights].filter(([, weight]) => weight > 0).sort((a, b) => b[1] - a[1]);
72
- if (lockfiles > 0)
73
- shares.push([lockfilesLabel, lockfiles]);
74
- if (ignored > 0)
75
- shares.push([ignoredLabel, ignored]);
76
- return { measure, shares };
77
- }
78
- /** Ready-made conditions offered before anything is typed: the questions people ask of a codebase most. */
79
- const presets = [
80
- { text: 'complexity>10', label: 'Complex functions' },
81
- { text: 'coverage<80%', label: 'Under 80% covered' },
82
- { text: 'duplication>0', label: 'Has duplication' },
83
- { text: 'remediation>0', label: 'Has technical debt' },
84
- { text: 'changes>0', label: 'Changed recently' },
85
- { text: 'has:findings', label: 'Has findings' },
86
- ];
87
- const languages = {
88
- ts: 'TypeScript', tsx: 'TypeScript', mts: 'TypeScript', cts: 'TypeScript',
89
- js: 'JavaScript', jsx: 'JavaScript', mjs: 'JavaScript', cjs: 'JavaScript',
90
- py: 'Python', go: 'Go', rs: 'Rust', java: 'Java', kt: 'Kotlin', kts: 'Kotlin', rb: 'Ruby', php: 'PHP', cs: 'C#',
91
- c: 'C', h: 'C', cc: 'C++', cpp: 'C++', cxx: 'C++', hpp: 'C++', hh: 'C++', swift: 'Swift', scala: 'Scala',
92
- vue: 'Vue', svelte: 'Svelte', sh: 'Shell', bash: 'Shell', css: 'CSS', scss: 'SCSS', less: 'Less', html: 'HTML',
93
- yaml: 'YAML', yml: 'YAML', json: 'JSON', dockerfile: 'Dockerfile',
94
- };
95
- /** Files a name alone types: Dockerfile and Containerfile, with or without a suffix such as Dockerfile.dev. */
96
- const namedLanguages = [[/^(?:dockerfile|containerfile)(?:\..+)?$/i, 'Dockerfile']];
97
- /** Language colours follow the conventions people already know from code hosts. */
98
- const languageColors = {
99
- TypeScript: '#3178c6', JavaScript: '#f1e05a', Python: '#3572a5', Go: '#00add8', Rust: '#dea584', Java: '#b07219',
100
- Kotlin: '#a97bff', Ruby: '#701516', PHP: '#4f5d95', 'C#': '#178600', C: '#555555', 'C++': '#f34b7d', Swift: '#f05138',
101
- Scala: '#c22d40', Vue: '#41b883', Svelte: '#ff3e00', Shell: '#89e051', CSS: '#663399', SCSS: '#c6538c', Less: '#1d365d',
102
- HTML: '#e34c26',
103
- // Configuration reads beside the code, so it takes quieter tones than the code hosts give it.
104
- YAML: '#c47d84', JSON: '#9b86b5', Dockerfile: '#4f9a94',
105
- };
106
- export function languageOf(path) {
107
- const name = path.slice(path.lastIndexOf('/') + 1);
108
- const named = namedLanguages.find(([pattern]) => pattern.test(name));
109
- if (named)
110
- return named[1];
111
- const dot = name.lastIndexOf('.');
112
- const extension = dot > 0 ? name.slice(dot + 1).toLowerCase() : '';
113
- return languages[extension] ?? (extension ? extension.toUpperCase() : 'Other');
25
+ /** Other plugins' metrics the query can name, by key. */
26
+ export function pluginMeasureList() {
27
+ return [...pluginMeasures];
114
28
  }
115
- export function languageColor(language) {
116
- return languageColors[language] ?? 'var(--neutral-2)';
29
+ export function measureOf(name) {
30
+ return name in measures ? measures[name] : pluginMeasures.get(name);
117
31
  }
118
32
  /** Splits the query into clauses; a word that names nothing known becomes a path fragment. */
119
33
  export function parseQuery(text) {
@@ -125,376 +39,123 @@ export function parseQuery(text) {
125
39
  }
126
40
  return clauses;
127
41
  }
42
+ /** A condition's number in the measure's own unit: a ratio for percentages (80 and 80% alike), minutes for hours. */
43
+ function conditionValue(spec, number, unit) {
44
+ if (spec.percent)
45
+ return unit === '%' || number > 1 ? number / 100 : number;
46
+ return unit === 'h' ? number * 60 : number;
47
+ }
128
48
  export function parseWord(word) {
129
49
  const keyedWord = /^(\w+):(.+)$/.exec(word);
130
50
  if (keyedWord)
131
51
  return keyed(keyedWord[1], keyedWord[2]);
132
52
  const condition = /^([\w.-]+)(>=|<=|>|<|=)(\d+(?:\.\d+)?)(%|h|min)?$/i.exec(word);
133
- if (condition) {
134
- const measure = condition[1].toLowerCase();
135
- const spec = measureOf(measure);
136
- if (!spec)
137
- return null;
138
- const number = Number(condition[3]);
139
- const unit = condition[4]?.toLowerCase();
140
- const value = spec.percent ? (unit === '%' || number > 1 ? number / 100 : number) : unit === 'h' ? number * 60 : number;
141
- return { kind: 'measure', measure, operator: condition[2], value };
142
- }
143
- return word ? { kind: 'path', value: word } : null;
144
- }
53
+ if (!condition)
54
+ return word ? { kind: 'path', value: word } : null;
55
+ const measure = condition[1].toLowerCase();
56
+ const spec = measureOf(measure);
57
+ if (!spec)
58
+ return null;
59
+ return { kind: 'measure', measure, operator: condition[2], value: conditionValue(spec, Number(condition[3]), condition[4]?.toLowerCase()) };
60
+ }
61
+ const yesNo = (value) => value === 'yes' || value === 'no';
62
+ const flag = (kind, read = value => value) => (value) => yesNo(value) ? { kind, value: read(value) } : null;
63
+ const named = (kind) => (value) => ({ kind, value });
64
+ /** The keys a clause is written with. The interface calls the files no plugin read "ignored"; `analysed:` stays a silent alias. */
65
+ const keys = new Map([
66
+ ['lang', named('lang')], ['language', named('lang')],
67
+ ['component', named('component')],
68
+ ['path', named('path')], ['in', named('path')],
69
+ ['has', (value) => value === 'findings' || value === 'diagnostics' ? { kind: 'has', value } : null],
70
+ ['analysed', flag('analysed')], ['analyzed', flag('analysed')],
71
+ ['ignored', flag('analysed', value => value === 'yes' ? 'no' : 'yes')],
72
+ ['lockfile', flag('lockfile')], ['lockfiles', flag('lockfile')],
73
+ ]);
145
74
  function keyed(key, value) {
146
- switch (key.toLowerCase()) {
147
- case 'lang':
148
- case 'language': return { kind: 'lang', value };
149
- case 'component': return { kind: 'component', value };
150
- case 'path':
151
- case 'in': return { kind: 'path', value };
152
- case 'has': return value === 'findings' || value === 'diagnostics' ? { kind: 'has', value } : null;
153
- // The interface and the query call the files no plugin read "ignored"; `analysed:` stays as a silent alias.
154
- case 'analysed':
155
- case 'analyzed': return value === 'yes' || value === 'no' ? { kind: 'analysed', value } : null;
156
- case 'ignored': return value === 'yes' || value === 'no' ? { kind: 'analysed', value: value === 'yes' ? 'no' : 'yes' } : null;
157
- case 'lockfile':
158
- case 'lockfiles': return value === 'yes' || value === 'no' ? { kind: 'lockfile', value } : null;
159
- default: return null;
160
- }
75
+ return keys.get(key.toLowerCase())?.(value) ?? null;
161
76
  }
162
77
  export function formatQuery(clauses) {
163
78
  return clauses.map(clauseText).join(' ');
164
79
  }
80
+ const quoted = (value) => /\s|"/.test(value) ? `"${value.replaceAll('"', '')}"` : value;
81
+ /** A measure's bound as written: percentages as percentages, everything else as the number. */
82
+ function boundText(clause) {
83
+ return measureOf(clause.measure)?.percent ? `${Math.round(clause.value * 1000) / 10}%` : String(clause.value);
84
+ }
85
+ /** A path that reads as anything else is written out as one. */
86
+ function pathText(value) {
87
+ return /^\w+:|[<>=]/.test(value) || /\s/.test(value) ? `path:${quoted(value)}` : value;
88
+ }
89
+ const clauseTexts = {
90
+ lang: clause => `lang:${quoted(clause.value)}`,
91
+ component: clause => `component:${quoted(clause.value)}`,
92
+ path: clause => pathText(clause.value),
93
+ has: clause => `has:${clause.value}`,
94
+ analysed: clause => `ignored:${clause.value === 'no' ? 'yes' : 'no'}`,
95
+ lockfile: clause => `lockfile:${clause.value}`,
96
+ measure: clause => `${clause.measure}${clause.operator}${boundText(clause)}`,
97
+ };
165
98
  export function clauseText(clause) {
166
- const quoted = (value) => /\s|"/.test(value) ? `"${value.replaceAll('"', '')}"` : value;
167
- switch (clause.kind) {
168
- case 'lang': return `lang:${quoted(clause.value)}`;
169
- case 'component': return `component:${quoted(clause.value)}`;
170
- case 'path': return /^\w+:|[<>=]/.test(clause.value) || /\s/.test(clause.value) ? `path:${quoted(clause.value)}` : clause.value;
171
- case 'has': return `has:${clause.value}`;
172
- case 'analysed': return `ignored:${clause.value === 'no' ? 'yes' : 'no'}`;
173
- case 'lockfile': return `lockfile:${clause.value}`;
174
- case 'measure': {
175
- const percent = measureOf(clause.measure)?.percent;
176
- const value = percent ? `${Math.round(clause.value * 1000) / 10}%` : String(clause.value);
177
- return `${clause.measure}${clause.operator}${value}`;
178
- }
179
- }
180
- }
99
+ return byKind(clauseTexts, clause);
100
+ }
101
+ const operatorSigns = { '>': '>', '>=': '≥', '<': '<', '<=': '≤', '=': '=' };
102
+ const yesNoWords = { yes: 'Yes', no: 'No' };
103
+ function measureLabel(clause) {
104
+ const { label, percent, minutes } = measureOf(clause.measure) ?? { label: clause.measure };
105
+ const bound = percent ? `${Math.round(clause.value * 1000) / 10}%` : minutes ? `${clause.value} min` : String(clause.value);
106
+ return { key: label, value: `${operatorSigns[clause.operator]} ${bound}` };
107
+ }
108
+ const clauseLabels = {
109
+ lang: clause => ({ key: 'Language', value: clause.value }),
110
+ component: clause => ({ key: 'Component', value: clause.value }),
111
+ path: clause => ({ key: 'Path', value: clause.value }),
112
+ has: clause => ({ key: 'Has', value: clause.value }),
113
+ analysed: clause => ({ key: 'Ignored', value: clause.value === 'no' ? 'Yes' : 'No' }),
114
+ lockfile: clause => ({ key: 'Lockfile', value: yesNoWords[clause.value] }),
115
+ measure: measureLabel,
116
+ };
181
117
  /** The chip's words: what it selects, in the interface's language rather than the query's. */
182
118
  export function clauseLabel(clause) {
183
- switch (clause.kind) {
184
- case 'lang': return { key: 'Language', value: clause.value };
185
- case 'component': return { key: 'Component', value: clause.value };
186
- case 'path': return { key: 'Path', value: clause.value };
187
- case 'has': return { key: 'Has', value: clause.value };
188
- case 'analysed': return { key: 'Ignored', value: clause.value === 'no' ? 'Yes' : 'No' };
189
- case 'lockfile': return { key: 'Lockfile', value: clause.value === 'yes' ? 'Yes' : 'No' };
190
- case 'measure': {
191
- const { label, percent, minutes } = measureOf(clause.measure) ?? { label: clause.measure };
192
- const value = percent ? `${Math.round(clause.value * 1000) / 10}%` : minutes ? `${clause.value} min` : String(clause.value);
193
- return { key: label, value: `${clause.operator === '>=' ? '≥' : clause.operator === '<=' ? '≤' : clause.operator} ${value}` };
194
- }
195
- }
119
+ return byKind(clauseLabels, clause);
196
120
  }
197
121
  export function sameClause(a, b) {
198
122
  return clauseText(a) === clauseText(b);
199
123
  }
124
+ const comparisons = {
125
+ '>': (value, bound) => value > bound,
126
+ '>=': (value, bound) => value >= bound,
127
+ '<': (value, bound) => value < bound,
128
+ '<=': (value, bound) => value <= bound,
129
+ '=': (value, bound) => value === bound,
130
+ };
131
+ const conditions = {
132
+ has: (clause, entry, facts) => clause.value === 'findings' ? (facts.findings.get(entry.path) ?? 0) > 0 : entry.diagnosticCount > 0,
133
+ analysed: (clause, entry) => isIgnored(entry) === (clause.value === 'no'),
134
+ lockfile: (clause, entry) => isLockfile(entry.path) === (clause.value === 'yes'),
135
+ measure: (clause, entry) => {
136
+ const { measure, operator, value: bound } = clause;
137
+ const value = measureOf(measure)?.read(entry) ?? null;
138
+ return value !== null && comparisons[operator](value, bound);
139
+ },
140
+ };
141
+ /** Whether the file passes the chips of one kind: any of them, or no chip of that kind at all. */
142
+ function anyOf(clauses, kind, test) {
143
+ const values = clauses.flatMap(clause => clause.kind === kind ? [clause.value.toLowerCase()] : []);
144
+ return values.length === 0 || values.some(test);
145
+ }
200
146
  /**
201
147
  * Whether a file passes the query. Chips of one kind widen the selection (TypeScript or JavaScript), chips of
202
148
  * different kinds narrow it (TypeScript in the core component), and every condition must hold.
203
149
  */
204
150
  export function matches(entry, clauses, facts, text = '') {
205
- const any = (kind, test) => {
206
- const values = clauses.flatMap(clause => clause.kind === kind ? [clause.value] : []);
207
- return values.length === 0 || values.some(test);
208
- };
209
151
  const path = entry.path.toLowerCase();
210
- if (text && !path.includes(text.toLowerCase()))
211
- return false;
212
- if (!any('lang', value => languageOf(entry.path).toLowerCase() === value.toLowerCase()))
213
- return false;
214
- if (!any('component', value => (facts.components.get(entry.path) ?? []).some(name => name.toLowerCase() === value.toLowerCase())))
215
- return false;
216
- if (!any('path', value => path.includes(value.toLowerCase())))
217
- return false;
218
- return clauses.every(clause => {
219
- if (clause.kind === 'has')
220
- return clause.value === 'findings' ? (facts.findings.get(entry.path) ?? 0) > 0 : entry.diagnosticCount > 0;
221
- if (clause.kind === 'analysed')
222
- return isIgnored(entry) === (clause.value === 'no');
223
- if (clause.kind === 'lockfile')
224
- return isLockfile(entry.path) === (clause.value === 'yes');
225
- if (clause.kind !== 'measure')
226
- return true;
227
- const value = measureOf(clause.measure)?.read(entry) ?? null;
228
- if (value === null)
229
- return false;
230
- switch (clause.operator) {
231
- case '>': return value > clause.value;
232
- case '>=': return value >= clause.value;
233
- case '<': return value < clause.value;
234
- case '<=': return value <= clause.value;
235
- case '=': return value === clause.value;
236
- }
237
- });
238
- }
239
- /** What the field offers for the typed text: the facets of this codebase first, then conditions, then the path. */
240
- export function suggest(text, files, facts, chosen) {
241
- const query = text.trim().toLowerCase();
242
- const taken = (clause) => chosen.some(other => sameClause(other, clause));
243
- const result = [];
244
- const counts = new Map();
245
- for (const file of files)
246
- counts.set(languageOf(file.path), (counts.get(languageOf(file.path)) ?? 0) + 1);
247
- for (const [language, total] of [...counts].sort((a, b) => b[1] - a[1])) {
248
- const clause = { kind: 'lang', value: language };
249
- if (!taken(clause) && (!query || language.toLowerCase().includes(query) || 'lang'.startsWith(query))) {
250
- result.push({ group: 'Languages', label: language, detail: quantity(total), clause, color: languageColor(language) });
251
- }
252
- }
253
- const members = new Map();
254
- for (const names of facts.components.values())
255
- for (const name of names)
256
- members.set(name, (members.get(name) ?? 0) + 1);
257
- for (const [name, total] of members) {
258
- const clause = { kind: 'component', value: name };
259
- if (!taken(clause) && (!query || name.toLowerCase().includes(query) || 'component'.startsWith(query))) {
260
- result.push({ group: 'Components', label: name, detail: quantity(total), clause });
261
- }
262
- }
263
- // Files only counted, never read by a plugin, are one condition away once the text names them.
264
- const named = (words) => query.length >= 3
265
- && words.some(phrase => phrase.startsWith(query) || (phrase.includes(' ') && phrase.includes(query)));
266
- const unread = files.filter(isIgnored).length;
267
- const notAnalysed = { kind: 'analysed', value: 'no' };
268
- if (unread && !taken(notAnalysed) && named(['ignored files', 'ignored:yes', 'not analysed', 'analysed:no'])) {
269
- result.push({ group: 'Conditions', label: 'Ignored files', detail: quantity(unread), clause: notAnalysed });
270
- }
271
- const lockfiles = files.filter(file => isLockfile(file.path)).length;
272
- const lockfile = { kind: 'lockfile', value: 'yes' };
273
- if (lockfiles && !taken(lockfile) && named(['lockfiles', 'lockfile:yes'])) {
274
- result.push({ group: 'Conditions', label: lockfilesLabel, detail: quantity(lockfiles), clause: lockfile });
275
- }
276
- const typed = query ? parseWord(text.trim()) : null;
277
- if (typed && (typed.kind === 'measure' || typed.kind === 'has' || typed.kind === 'analysed' || typed.kind === 'lockfile') && !taken(typed)) {
278
- const { key, value } = clauseLabel(typed);
279
- result.push({ group: 'Conditions', label: `${key} ${value}`, clause: typed });
280
- }
281
- else {
282
- // Other plugins' metrics are offered once the typed text names them; the presets stay Repometry's own.
283
- if (query)
284
- for (const [key, { label }] of pluginMeasures) {
285
- const clause = { kind: 'measure', measure: key, operator: '>', value: 0 };
286
- if (!taken(clause) && (key.startsWith(query) || label.toLowerCase().includes(query))) {
287
- result.push({ group: 'Conditions', label: `${label} above zero`, detail: `${label} > 0`, clause });
288
- }
289
- }
290
- for (const preset of presets) {
291
- const clause = parseWord(preset.text);
292
- const { key, value } = clauseLabel(clause);
293
- if (!taken(clause) && (!query || preset.label.toLowerCase().includes(query) || preset.text.startsWith(query) || key.toLowerCase().includes(query))) {
294
- result.push({ group: 'Conditions', label: preset.label, detail: `${key} ${value}`, clause });
295
- }
296
- }
297
- }
298
- if (query && !(typed && typed.kind !== 'path')) {
299
- result.push({ group: 'Path', label: `Path contains “${text.trim()}”`, clause: { kind: 'path', value: text.trim() } });
300
- }
301
- return result;
302
- }
303
- function quantity(total) {
304
- return `${total.toLocaleString()} ${total === 1 ? 'file' : 'files'}`;
305
- }
306
- /**
307
- * The field: chips for the chosen clauses, then a text input; the list of suggestions hangs from it in one frame.
308
- * Backspace in an empty input takes the last chip back into text, so a chip can be edited, not just removed.
309
- */
310
- export function queryField(clauses, options) {
311
- let chosen = [...clauses];
312
- let active = 0;
313
- let shown = [];
314
- const root = element('div', 'qf');
315
- const box = element('div', 'qf-box');
316
- const chips = element('span', 'qf-chips');
317
- const input = element('input', 'qf-input');
318
- input.type = 'text';
319
- input.autocomplete = 'off';
320
- input.spellcheck = false;
321
- input.setAttribute('role', 'combobox');
322
- input.setAttribute('aria-label', 'Filter files');
323
- input.setAttribute('aria-autocomplete', 'list');
324
- input.setAttribute('aria-expanded', 'false');
325
- const list = element('ul', 'qf-options');
326
- list.id = `qf-options-${Math.random().toString(36).slice(2, 8)}`;
327
- list.setAttribute('role', 'listbox');
328
- input.setAttribute('aria-controls', list.id);
329
- const popover = element('div', 'qf-popover');
330
- popover.hidden = true;
331
- const help = element('p', 'qf-help', 'Combine chips: same kind widens, different kinds narrow. Type complexity>10 or coverage<80% for a condition.');
332
- popover.append(list, help);
333
- box.append(chips, input);
334
- root.append(box, popover);
335
- function placeholder() {
336
- input.placeholder = chosen.length ? 'Add a filter' : 'Filter by language, component, condition or path';
337
- }
338
- function renderChips() {
339
- chips.replaceChildren(...chosen.map((clause, index) => {
340
- const chip = element('span', `qf-chip qf-chip-${clause.kind}`);
341
- const { key, value } = clauseLabel(clause);
342
- if (clause.kind === 'lang') {
343
- const dot = element('span', 'qf-dot');
344
- dot.style.background = languageColor(clause.value);
345
- chip.append(dot);
346
- }
347
- chip.append(element('span', 'qf-chip-key', key), element('span', 'qf-chip-value', value));
348
- const remove = element('button', 'qf-remove');
349
- remove.type = 'button';
350
- remove.setAttribute('aria-label', `Remove ${key} ${value}`);
351
- remove.addEventListener('click', () => {
352
- chosen.splice(index, 1);
353
- commit();
354
- input.focus();
355
- });
356
- chip.append(remove);
357
- return chip;
358
- }));
359
- placeholder();
360
- }
361
- function commit() {
362
- renderChips();
363
- options.change(chosen, input.value.trim());
364
- if (!popover.hidden)
365
- update();
366
- }
367
- function update() {
368
- shown = options.suggestions(input.value);
369
- active = Math.min(active, Math.max(0, shown.length - 1));
370
- let group = '';
371
- list.replaceChildren(...shown.flatMap((suggestion, index) => {
372
- const items = [];
373
- if (suggestion.group !== group) {
374
- group = suggestion.group;
375
- const heading = element('li', 'qf-group', group);
376
- heading.setAttribute('role', 'presentation');
377
- items.push(heading);
378
- }
379
- const item = element('li', 'qf-option');
380
- item.id = `${list.id}-${index}`;
381
- item.setAttribute('role', 'option');
382
- if (suggestion.color) {
383
- const dot = element('span', 'qf-dot');
384
- dot.style.background = suggestion.color;
385
- item.append(dot);
386
- }
387
- item.append(element('span', 'qf-option-label', suggestion.label));
388
- if (suggestion.detail)
389
- item.append(element('span', 'qf-option-detail', suggestion.detail));
390
- item.addEventListener('mousedown', event => event.preventDefault());
391
- item.addEventListener('click', () => choose(suggestion));
392
- item.addEventListener('mousemove', () => { if (active !== index) {
393
- active = index;
394
- highlight();
395
- } });
396
- items.push(item);
397
- return items;
398
- }));
399
- highlight();
400
- }
401
- function highlight() {
402
- for (const item of list.querySelectorAll('.qf-option'))
403
- item.classList.toggle('active', item.id === `${list.id}-${active}`);
404
- const current = list.querySelector(`#${list.id}-${active}`);
405
- if (current) {
406
- input.setAttribute('aria-activedescendant', current.id);
407
- current.scrollIntoView({ block: 'nearest' });
408
- }
409
- else
410
- input.removeAttribute('aria-activedescendant');
411
- }
412
- function open() {
413
- if (!popover.hidden)
414
- return;
415
- popover.hidden = false;
416
- root.classList.add('open');
417
- input.setAttribute('aria-expanded', 'true');
418
- active = 0;
419
- update();
420
- document.addEventListener('pointerdown', outside, true);
421
- }
422
- function close() {
423
- if (popover.hidden)
424
- return;
425
- popover.hidden = true;
426
- root.classList.remove('open');
427
- input.setAttribute('aria-expanded', 'false');
428
- document.removeEventListener('pointerdown', outside, true);
429
- }
430
- function outside(event) {
431
- if (!root.contains(event.target))
432
- close();
433
- }
434
- function choose(suggestion) {
435
- if (!chosen.some(clause => sameClause(clause, suggestion.clause)))
436
- chosen.push(suggestion.clause);
437
- input.value = '';
438
- active = 0;
439
- commit();
440
- }
441
- box.addEventListener('pointerdown', event => {
442
- if (event.target === box || event.target === chips) {
443
- event.preventDefault();
444
- input.focus();
445
- }
446
- });
447
- input.addEventListener('focus', open);
448
- input.addEventListener('input', () => {
449
- open();
450
- active = 0;
451
- update();
452
- options.change(chosen, input.value.trim());
453
- });
454
- input.addEventListener('keydown', event => {
455
- if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
456
- event.preventDefault();
457
- open();
458
- if (shown.length)
459
- active = (active + (event.key === 'ArrowDown' ? 1 : -1) + shown.length) % shown.length;
460
- highlight();
461
- }
462
- else if (event.key === 'Enter') {
463
- event.preventDefault();
464
- const typed = input.value.trim();
465
- const suggestion = shown[active];
466
- if (suggestion && !popover.hidden)
467
- choose(suggestion);
468
- else if (typed)
469
- choose({ group: '', label: typed, clause: parseWord(typed) ?? { kind: 'path', value: typed } });
470
- }
471
- else if (event.key === 'Escape') {
472
- if (!popover.hidden) {
473
- event.preventDefault();
474
- close();
475
- }
476
- }
477
- else if (event.key === 'Backspace' && input.value === '' && chosen.length) {
478
- event.preventDefault();
479
- input.value = clauseText(chosen.pop());
480
- commit();
481
- }
482
- });
483
- renderChips();
484
- return {
485
- element: root,
486
- text: () => input.value.trim(),
487
- set(next) {
488
- chosen = [...next];
489
- commit();
490
- },
491
- };
492
- }
493
- function element(tag, className, text) {
494
- const node = document.createElement(tag);
495
- if (className)
496
- node.className = className;
497
- if (text !== undefined)
498
- node.textContent = text;
499
- return node;
152
+ const language = languageOf(entry.path).toLowerCase();
153
+ const components = (facts.components.get(entry.path) ?? []).map(name => name.toLowerCase());
154
+ const widened = [
155
+ path.includes(text.toLowerCase()),
156
+ anyOf(clauses, 'lang', value => language === value),
157
+ anyOf(clauses, 'component', value => components.includes(value)),
158
+ anyOf(clauses, 'path', value => path.includes(value)),
159
+ ];
160
+ return widened.every(Boolean) && clauses.every(clause => conditions[clause.kind]?.(clause, entry, facts) ?? true);
500
161
  }
@@ -0,0 +1,4 @@
1
+ import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
2
+ import type { Navigation, Preferences } from './viewer-inspection.js';
3
+ /** The Hotspots page: the folder's code map coloured by a metric, and its files ranked by it beside. */
4
+ export declare function hotspotView(details: InspectionDetails, navigation: Navigation, settings: Preferences, directory: string): HTMLElement;