repometry 0.6.2 → 0.7.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 (91) hide show
  1. package/package.json +1 -1
  2. package/target/main/resources/config/process-plugins-v1.schema.json +75 -0
  3. package/target/main/resources/report/json/report-v2.schema.json +21 -1
  4. package/target/main/resources/report/json/repository-summary-v1.schema.json +9 -0
  5. package/target/main/resources/report/json/viewer-inspection-v1.schema.json +11 -3
  6. package/target/main/resources/viewer/files.css +6 -0
  7. package/target/main/resources/viewer/index.html +1 -1
  8. package/target/main/resources/viewer/styles.css +1 -0
  9. package/target/main/ts/cli/config.d.ts +1 -0
  10. package/target/main/ts/cli/config.js +3 -2
  11. package/target/main/ts/cli/main.js +37 -19
  12. package/target/main/ts/cli/reporting.js +3 -3
  13. package/target/main/ts/compose/analysis-files.d.ts +1 -0
  14. package/target/main/ts/compose/analysis-files.js +27 -7
  15. package/target/main/ts/compose/analysis-imports.js +2 -1
  16. package/target/main/ts/compose/analysis-report.js +7 -3
  17. package/target/main/ts/compose/analysis-results.d.ts +4 -1
  18. package/target/main/ts/compose/analysis-results.js +3 -0
  19. package/target/main/ts/compose/analysis-sources.js +2 -1
  20. package/target/main/ts/compose/languages.js +4 -1
  21. package/target/main/ts/compose/plugin-list.d.ts +11 -2
  22. package/target/main/ts/compose/plugin-list.js +4 -1
  23. package/target/main/ts/compose/process-plugins.d.ts +2 -0
  24. package/target/main/ts/compose/process-plugins.js +63 -0
  25. package/target/main/ts/compose/structure-measures.d.ts +5 -0
  26. package/target/main/ts/compose/structure-measures.js +57 -0
  27. package/target/main/ts/core/engine/manifest.js +5 -1
  28. package/target/main/ts/core/model/clone-source.js +0 -1
  29. package/target/main/ts/core/model/code-structure.d.ts +14 -9
  30. package/target/main/ts/core/model/code-structure.js +23 -10
  31. package/target/main/ts/core/model/language.d.ts +2 -0
  32. package/target/main/ts/core/model/plugin-data.d.ts +2 -0
  33. package/target/main/ts/core/model/quality-summary.d.ts +4 -0
  34. package/target/main/ts/core/model/quality-summary.js +53 -29
  35. package/target/main/ts/core/model/report.d.ts +6 -0
  36. package/target/main/ts/plugin.d.ts +1 -1
  37. package/target/main/ts/plugins/coverage/coverage.d.ts +2 -1
  38. package/target/main/ts/plugins/coverage/coverage.js +40 -30
  39. package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -1
  40. package/target/main/ts/plugins/language-js/function-facts.js +0 -1
  41. package/target/main/ts/plugins/language-js/js-security.js +25 -37
  42. package/target/main/ts/plugins/language-js/structural-observations.js +5 -4
  43. package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -1
  44. package/target/main/ts/plugins/maintainability/maintainability.js +9 -8
  45. package/target/main/ts/plugins/security/dockerfile.js +45 -37
  46. package/target/main/ts/plugins/structure/structure.js +2 -2
  47. package/target/main/ts/report/html/app/viewer-code-map.js +6 -5
  48. package/target/main/ts/report/html/app/viewer-columns.d.ts +2 -0
  49. package/target/main/ts/report/html/app/viewer-columns.js +9 -4
  50. package/target/main/ts/report/html/app/viewer-data.d.ts +2 -1
  51. package/target/main/ts/report/html/app/viewer-data.js +1 -1
  52. package/target/main/ts/report/html/app/viewer-file-aside.d.ts +5 -9
  53. package/target/main/ts/report/html/app/viewer-file-aside.js +18 -8
  54. package/target/main/ts/report/html/app/viewer-file-figures.d.ts +2 -0
  55. package/target/main/ts/report/html/app/viewer-file-figures.js +6 -1
  56. package/target/main/ts/report/html/app/viewer-hotspots.js +7 -5
  57. package/target/main/ts/report/html/app/viewer-inspection.js +1 -1
  58. package/target/main/ts/report/html/app/viewer-issue-group.js +2 -2
  59. package/target/main/ts/report/html/app/viewer-languages.d.ts +3 -2
  60. package/target/main/ts/report/html/app/viewer-languages.js +14 -7
  61. package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +4 -4
  62. package/target/main/ts/report/html/app/viewer-line-coverage.js +11 -24
  63. package/target/main/ts/report/html/app/viewer-map-scale.d.ts +1 -1
  64. package/target/main/ts/report/html/app/viewer-map-scale.js +1 -1
  65. package/target/main/ts/report/html/app/viewer-map-shape.d.ts +2 -2
  66. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -3
  67. package/target/main/ts/report/html/app/viewer-metric-registry.js +0 -9
  68. package/target/main/ts/report/html/app/viewer-metrics-view.js +1 -4
  69. package/target/main/ts/report/html/app/viewer-metrics.d.ts +2 -0
  70. package/target/main/ts/report/html/app/viewer-metrics.js +5 -0
  71. package/target/main/ts/report/html/app/viewer-overview-cards.js +4 -1
  72. package/target/main/ts/report/html/app/viewer-overview-hotspots.js +2 -2
  73. package/target/main/ts/report/html/app/viewer-profile.js +15 -1
  74. package/target/main/ts/report/html/app/viewer-source-view.js +7 -6
  75. package/target/main/ts/report/html/app/viewer-table-cells.js +8 -2
  76. package/target/main/ts/report/html/app/viewer-table-rows.d.ts +2 -0
  77. package/target/main/ts/report/html/app/viewer-table-rows.js +7 -5
  78. package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +2 -5
  79. package/target/main/ts/report/html/app/viewer-tokenizer.js +9 -12
  80. package/target/main/ts/report/html/app/viewer-totals.d.ts +6 -0
  81. package/target/main/ts/report/html/app/viewer-totals.js +11 -0
  82. package/target/main/ts/report/html/app/viewer-trend-data.d.ts +1 -1
  83. package/target/main/ts/report/html/app/viewer-trend-data.js +1 -1
  84. package/target/main/ts/report/html/app/viewer-trend-nav.js +3 -2
  85. package/target/main/ts/report/html/app/viewer.js +1 -7
  86. package/target/main/ts/report/json/projections/commit-summary.js +5 -0
  87. package/target/main/ts/report/json/projections/file-metrics.js +20 -4
  88. package/target/main/ts/report/json/projections/inspection-details.js +32 -14
  89. package/target/main/ts/report/json/projections/metric-values.d.ts +1 -0
  90. package/target/main/ts/report/json/projections/metric-values.js +36 -3
  91. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +8 -1
@@ -1,13 +1,20 @@
1
- /** The inspection's languages, which its files point to by index, and the colour of each by its name. */
1
+ /** The inspection's languages, which its files point to by index, the colour of each by its name, and each file's id. */
2
2
  let languages = [];
3
3
  let colors = new Map();
4
+ let ids = new Map();
4
5
  function nameOf(language) {
5
6
  return language.label ?? language.id;
6
7
  }
7
8
  /** Takes the languages of the inspection on screen: their names, and the colours the plugins and the catalog give them. */
8
- export function useLanguages(list) {
9
- languages = list ?? [];
9
+ export function useLanguages(metrics) {
10
+ languages = metrics.languages ?? [];
10
11
  colors = new Map(languages.flatMap(language => language.color ? [[nameOf(language), language.color]] : []));
12
+ ids = new Map(metrics.files.flatMap(file => file.language === undefined || !languages[file.language] ? []
13
+ : [[file.path, languages[file.language].id]]));
14
+ }
15
+ /** The id of a file's language, as the inspection gives it: what decides how its source is read. */
16
+ export function languageIdOf(path) {
17
+ return ids.get(path);
11
18
  }
12
19
  /**
13
20
  * Dependency lockfiles, by exact file name. They are generated, often the largest files in a repository, and no
@@ -36,17 +43,17 @@ export function sized(files) {
36
43
  const weights = {
37
44
  bytes: entry => entry.bytes,
38
45
  lines: entry => entry.lines,
39
- 'code-lines': entry => entry.quality?.codeLines ?? entry.lines,
46
+ 'code-lines': entry => entry.quality?.codeLines,
40
47
  };
41
48
  /**
42
49
  * Size in bytes when every file has it: one measure for code, lockfiles and ignored files alike, untouched by
43
- * formatting. Without sizes, physical lines where any file is only counted (the one line measure all files have),
44
- * otherwise code lines.
50
+ * formatting. Without sizes, code lines where every file was read and has them, otherwise physical lines, the one line
51
+ * measure all files have: one bar never adds the two.
45
52
  */
46
53
  function shareMeasure(files) {
47
54
  if (sized(files))
48
55
  return 'bytes';
49
- return files.some(entry => entry.analysed === false || isLockfile(entry.path)) ? 'lines' : 'code-lines';
56
+ return files.every(entry => entry.analysed !== false && entry.quality?.codeLines !== undefined) ? 'code-lines' : 'lines';
50
57
  }
51
58
  /** Where a file's weight goes on the bar: its language, or one of the two categories. */
52
59
  function shareOf(entry) {
@@ -40,8 +40,8 @@ export declare function callReading(calls: readonly number[]): LineReading;
40
40
  */
41
41
  export declare function lineReadings(coverage: FileLineCoverage): Map<number, LineReading>;
42
42
  /**
43
- * The tint a gap of blank and comment lines takes so the strip has no breaks: the state of the measured line above it,
44
- * which the gap closes, or for a gap at the file's start, of the line below. A gap beside a line that was not measured
45
- * takes its other neighbour, and one with no measured neighbour stays plain.
43
+ * The tint the lines without a coverage record take so the strip has no breaks. Coverage records only code, so such a
44
+ * line is a blank, a comment or a declaration no test can run: between two records it takes the state above, the block
45
+ * it closes; before the first record, the state below. After the last record the strip ends.
46
46
  */
47
- export declare function bridgeStates(states: ReadonlyMap<number, LineState>, codeless: readonly boolean[]): Map<number, LineState>;
47
+ export declare function bridgeStates(states: ReadonlyMap<number, LineState>): Map<number, LineState>;
@@ -90,32 +90,19 @@ export function lineReadings(coverage) {
90
90
  readings.set(line, callReading(counts));
91
91
  return readings;
92
92
  }
93
- /** The last line of the gap of codeless, unmeasured lines that starts at `line`. */
94
- function gapEnd(states, codeless, line) {
95
- let end = line;
96
- while (end < codeless.length && !states.has(end + 1) && codeless[end])
97
- end += 1;
98
- return end;
99
- }
100
93
  /**
101
- * The tint a gap of blank and comment lines takes so the strip has no breaks: the state of the measured line above it,
102
- * which the gap closes, or for a gap at the file's start, of the line below. A gap beside a line that was not measured
103
- * takes its other neighbour, and one with no measured neighbour stays plain.
94
+ * The tint the lines without a coverage record take so the strip has no breaks. Coverage records only code, so such a
95
+ * line is a blank, a comment or a declaration no test can run: between two records it takes the state above, the block
96
+ * it closes; before the first record, the state below. After the last record the strip ends.
104
97
  */
105
- export function bridgeStates(states, codeless) {
98
+ export function bridgeStates(states) {
99
+ const lines = [...states.keys()].sort((a, b) => a - b);
106
100
  const bridged = new Map();
107
- let line = 1;
108
- while (line <= codeless.length) {
109
- if (states.has(line) || !codeless[line - 1]) {
110
- line += 1;
111
- continue;
112
- }
113
- const end = gapEnd(states, codeless, line);
114
- const state = states.get(line - 1) ?? states.get(end + 1);
115
- if (state)
116
- for (let at = line; at <= end; at++)
117
- bridged.set(at, state);
118
- line = end + 1;
119
- }
101
+ const fill = (from, to, state) => { for (let at = from; at < to; at++)
102
+ bridged.set(at, state); };
103
+ if (lines.length)
104
+ fill(1, lines[0], states.get(lines[0]));
105
+ for (const [index, line] of lines.slice(0, -1).entries())
106
+ fill(line + 1, lines[index + 1], states.get(line));
120
107
  return bridged;
121
108
  }
@@ -18,7 +18,7 @@ export declare function spreadLevels(files: ReadonlyMap<string, number>): Map<st
18
18
  export declare function relativePeaks(entries: readonly {
19
19
  readonly path: string;
20
20
  readonly folder: boolean;
21
- readonly score: number;
21
+ readonly score: number | null;
22
22
  }[]): (path: string, folder: boolean) => number;
23
23
  export declare function levelLegend(): HTMLElement;
24
24
  export declare function sunburstLegend(metric: HotspotMetric, limits: readonly number[] | undefined): HTMLElement;
@@ -96,7 +96,7 @@ export function relativePeaks(entries) {
96
96
  const level = (path, folder) => folder ? `folder:${path.split('/').length}` : 'file';
97
97
  const peaks = new Map();
98
98
  for (const { path, folder, score } of entries)
99
- peaks.set(level(path, folder), Math.max(peaks.get(level(path, folder)) ?? 1, score));
99
+ peaks.set(level(path, folder), Math.max(peaks.get(level(path, folder)) ?? 1, score ?? 0));
100
100
  return (path, folder) => peaks.get(level(path, folder)) ?? 1;
101
101
  }
102
102
  function swatches() {
@@ -1,12 +1,12 @@
1
1
  import type { Metrics } from './viewer-inspection.js';
2
2
  /** Rings (a sunburst) or tiles (a treemap); the last choice is remembered for this viewer. */
3
3
  export type MapShape = 'rings' | 'tiles';
4
- /** A file or folder on the map: its area, and the score its colour is read from. */
4
+ /** A file or folder on the map: its area, and the score its colour is read from; null where it was not measured. */
5
5
  export interface Branch {
6
6
  readonly entry: Metrics;
7
7
  readonly folder: boolean;
8
8
  readonly area: number;
9
- readonly score: number;
9
+ readonly score: number | null;
10
10
  }
11
11
  /** What the ring and tile layouts draw with. */
12
12
  export interface MapDraw {
@@ -25,7 +25,6 @@ export interface Valued {
25
25
  readonly analysed?: boolean | undefined;
26
26
  }
27
27
  /** Curated groups first, in this order; groups named by plugins follow in catalog order. */
28
- export declare const curatedGroups: readonly ['Maintainability', 'Coverage', 'Security', 'Size'];
29
28
  /** The metrics the viewer draws from their typed fields; a Repometry metric it has no code for goes by its descriptor. */
30
29
  export declare function isBuiltin(descriptor: MetricDescriptor): boolean;
31
30
  /** One spec per descriptor, in catalog order; descriptors listed twice by id count once. */
@@ -34,8 +33,6 @@ export declare function metricSpecs(catalog: readonly MetricDescriptor[]): Metri
34
33
  export declare function catalogIndex(catalog: readonly MetricDescriptor[] | undefined): Map<string, number>;
35
34
  /** Specs by key, for the query field and the Trends views. Where versions share a key, the one the index holds wins. */
36
35
  export declare function byKey(specs: readonly MetricSpec[], index?: ReadonlyMap<string, number>): Map<string, MetricSpec>;
37
- /** The Trends groups: the curated ones in their order, then each plugin's, with the specs that have a trend. */
38
- export declare function trendGroups(specs: readonly MetricSpec[]): [string, MetricSpec[]][];
39
36
  /**
40
37
  * The repository's value at a commit. A commit lists every metric it measured, null where nothing rolls up; a metric
41
38
  * it does not list did not run, and has no value, so a chart breaks its line instead of dropping to zero.
@@ -27,7 +27,6 @@ const reserved = new Set(['lang', 'language', 'component', 'path', 'in', 'has',
27
27
  'coverable-lines', 'covered-lines', 'uncovered-lines', 'security-high', 'security-medium', 'security-low',
28
28
  ...Object.values(builtinKeys)]);
29
29
  /** Curated groups first, in this order; groups named by plugins follow in catalog order. */
30
- export const curatedGroups = ['Maintainability', 'Coverage', 'Security', 'Size'];
31
30
  /** The metrics the viewer draws from their typed fields; a Repometry metric it has no code for goes by its descriptor. */
32
31
  export function isBuiltin(descriptor) {
33
32
  return handDrawn.has(descriptor.id);
@@ -80,14 +79,6 @@ export function byKey(specs, index) {
80
79
  }
81
80
  return keys;
82
81
  }
83
- /** The Trends groups: the curated ones in their order, then each plugin's, with the specs that have a trend. */
84
- export function trendGroups(specs) {
85
- const groups = new Map(curatedGroups.map(group => [group, []]));
86
- for (const spec of specs)
87
- if (spec.trend)
88
- groups.set(spec.group, [...groups.get(spec.group) ?? [], spec]);
89
- return [...groups].filter(([, members]) => members.length > 0);
90
- }
91
82
  /** The id whose presence says a metric was measured: a ratio is measured where its denominator is. */
92
83
  function measuredId(spec) {
93
84
  return spec.descriptor.ratio?.over ?? spec.descriptor.id;
@@ -5,7 +5,6 @@ import { directorySummary, fileDetails } from './viewer-file-aside.js';
5
5
  import { formatQuery, matches, parseQuery } from './viewer-filter.js';
6
6
  import { pageSize } from './viewer-inspection.js';
7
7
  import { renderLanguages } from './viewer-language-bar.js';
8
- import { isLockfile } from './viewer-languages.js';
9
8
  import { breadcrumbs, splitter } from './viewer-layout.js';
10
9
  import { findingIndex } from './viewer-locations.js';
11
10
  import { labelOf } from './viewer-metrics.js';
@@ -124,9 +123,7 @@ export function metricsView(details, navigation, settings, directory, selectedFi
124
123
  function showAside(files, filtering) {
125
124
  const next = selectedFile
126
125
  ? fileDetails(details, selectedFile, { ...navigation, href: (target, options) => target === 'metrics' ? linkTo(options) : navigation.href(target, options) })
127
- : directorySummary(aggregate(directory, files), { analysed: files.filter(entry => entry.analysed !== false).length,
128
- lockfiles: files.filter(entry => isLockfile(entry.path)).length,
129
- selection: filtering ? `${count(files.length)} of ${count(scopeFiles.length)} files selected` : undefined });
126
+ : directorySummary(aggregate(directory, files), files, filtering ? `${count(files.length)} of ${count(scopeFiles.length)} files selected` : undefined);
130
127
  aside.replaceWith(next);
131
128
  aside = next;
132
129
  }
@@ -32,6 +32,8 @@ export declare function labelOf(metric: Metric): string;
32
32
  export declare function definitionOf(metric: Metric): string;
33
33
  /** Which way is better: the green and red of changes and the flags on a chart follow it. */
34
34
  export declare function betterOf(metric: Metric): 'lower' | 'higher' | 'none';
35
+ /** Where the maintainability grade covers only some files, as in a repository some plugins cannot measure, it says so. */
36
+ export declare function gradeScope(quality: QualitySummary | undefined): string | undefined;
35
37
  /** A metric's value at a commit; null where the commit has no such measurement. */
36
38
  export declare function metricValue(report: PublicHistoryEntry, metric: Metric, quality: QualitySummary | undefined, context?: InspectionContext): number | null;
37
39
  export declare function isPercent(metric: Metric): boolean;
@@ -120,6 +120,11 @@ const readers = {
120
120
  'security-medium': (_, __, context) => context?.security?.medium,
121
121
  'security-low': (_, __, context) => context?.security?.low,
122
122
  };
123
+ /** Where the maintainability grade covers only some files, as in a repository some plugins cannot measure, it says so. */
124
+ export function gradeScope(quality) {
125
+ const scope = quality?.maintainability?.gradeCoverage;
126
+ return scope && scope.measuredFiles < scope.totalFiles ? `Graded on ${count(scope.measuredFiles)} of ${count(scope.totalFiles)} files` : undefined;
127
+ }
123
128
  /** A metric's value at a commit; null where the commit has no such measurement. */
124
129
  export function metricValue(report, metric, quality, context) {
125
130
  const spec = pluginSpec(metric);
@@ -1,6 +1,6 @@
1
1
  import { byId, count, percent, quantity } from './viewer-dom.js';
2
2
  import { codeSmellCategories, securityCategories } from './viewer-files.js';
3
- import { coverageGrade, formatMetric, metricValue, pluginSpec, securityGrades, securityRisks } from './viewer-metrics.js';
3
+ import { coverageGrade, formatMetric, gradeScope, metricValue, pluginSpec, securityGrades, securityRisks } from './viewer-metrics.js';
4
4
  import { href } from './viewer-route.js';
5
5
  /** Coverage kinds beyond lines, by their registry keys, in the words the Overview card uses for them. */
6
6
  const coverageKinds = [['branch-coverage', 'Branches'], ['function-coverage', 'Functions']];
@@ -86,6 +86,9 @@ export function renderQuality(report, quality) {
86
86
  detailText('maintainability-detail', 'Not measured');
87
87
  else
88
88
  detailText('maintainability-detail', quantity(maintainability.smells, 'code smell'), maintainability.smells > 0 ? smellsLink(report.sha) : undefined);
89
+ const scope = byId('maintainability-scope');
90
+ scope.textContent = gradeScope(quality) ?? '';
91
+ scope.hidden = !scope.textContent;
89
92
  }
90
93
  /** The words of the five steps, as every grade has them: clear A, low B, medium C, high D, critical F. */
91
94
  const severities = ['clear', 'low', 'medium', 'high', 'critical'];
@@ -1,6 +1,6 @@
1
1
  import { renderSunburst } from './viewer-code-map.js';
2
2
  import { byId, count, notice, parentPath, quantity } from './viewer-dom.js';
3
- import { hotspotScore } from './viewer-file-figures.js';
3
+ import { hotspotScore, scorePeak } from './viewer-file-figures.js';
4
4
  import { securityCategories } from './viewer-files.js';
5
5
  import { band, bandLimits } from './viewer-map-scale.js';
6
6
  import { mapStub } from './viewer-map-shape.js';
@@ -88,7 +88,7 @@ export function renderOverviewHotspots(details, sha, area, scanned) {
88
88
  overviewMap(details, sha, { metric });
89
89
  allLink(href({ page: 'hotspots', sha }), true);
90
90
  const top = rankedFiles(details, metric);
91
- const peak = Math.max(1, ...top.map(item => item.value ?? 0));
91
+ const peak = scorePeak(top.map(item => item.value));
92
92
  const rows = top.map(({ path, value, entry }) => {
93
93
  const score = document.createElement('span');
94
94
  score.className = 'chip';
@@ -50,11 +50,25 @@ function identity(profile) {
50
50
  section.append(facts);
51
51
  return section;
52
52
  }
53
+ /** The languages the plugins claim, each with the patterns of the files it reads; an older inspection did not record them. */
54
+ function claims(languages) {
55
+ if (!languages)
56
+ return none('Not recorded for this inspection');
57
+ if (!languages.length)
58
+ return none('No language plugin');
59
+ const list = element('ul', 'profile-claims');
60
+ list.append(...languages.map(language => {
61
+ const item = element('li');
62
+ item.append(element('span', 'profile-claim', language.label), chips([...language.extensions.map(extension => `**/*${extension}`), ...language.globs]));
63
+ return item;
64
+ }));
65
+ return list;
66
+ }
53
67
  /** What the inspection reads and what it leaves out, as the patterns the profile states. */
54
68
  function files(profile) {
55
69
  const section = block('Files');
56
70
  const facts = element('dl', 'profile-facts');
57
- facts.append(row('Included', profile.extensions.length ? chips(profile.extensions.map(extension => `**/*${extension}`)) : none('Every file')));
71
+ facts.append(row('Included', claims(profile.languages)));
58
72
  facts.append(row('Excluded paths', profile.excludedPaths.length ? chips(profile.excludedPaths) : none()));
59
73
  facts.append(row('Excluded directories', profile.excludedDirectories.length
60
74
  ? chips(profile.excludedDirectories.map(directory => `**/${directory}/`)) : none()));
@@ -2,7 +2,8 @@
2
2
  // on the lines they describe, or the tests' coverage in the gutter; and the short excerpt a finding shows.
3
3
  import { element } from './viewer-dom.js';
4
4
  import { bridgeStates, hitLabel } from './viewer-line-coverage.js';
5
- import { codeless, highlighter, runNodes, tokenizer } from './viewer-tokenizer.js';
5
+ import { languageIdOf } from './viewer-languages.js';
6
+ import { highlighter, runNodes, tokenizer } from './viewer-tokenizer.js';
6
7
  function sourceLines(text) {
7
8
  return text.replace(/\r\n?/g, '\n').replace(/\n$/, '').split('\n');
8
9
  }
@@ -18,11 +19,11 @@ function complexityBadge(start) {
18
19
  * called; a miss's red says it. Nothing runs on a blank or comment line: where a tool counts one anyway, or it sits
19
20
  * inside a run of one state, it keeps the strip's tint and says nothing.
20
21
  */
21
- function coverageCell(own, bridged, runs) {
22
+ function coverageCell(own, bridged) {
22
23
  const state = own?.state ?? bridged;
23
24
  if (!state)
24
25
  return [];
25
- if (!own || codeless(runs)) {
26
+ if (!own) {
26
27
  const silent = element('span', `src-cov src-cov-mark-${state}`);
27
28
  silent.setAttribute('aria-hidden', 'true');
28
29
  return [silent];
@@ -42,10 +43,10 @@ function noteBox(note) {
42
43
  export function renderSource(container, text, options) {
43
44
  const lines = sourceLines(text);
44
45
  // Tokenized up front, in order, since a comment's state carries from line to line.
45
- const tokenize = tokenizer(options.path);
46
+ const tokenize = tokenizer(languageIdOf(options.path));
46
47
  const tokens = lines.map(line => tokenize(line));
47
48
  const states = new Map([...options.coverage ?? []].map(([line, reading]) => [line, reading.state]));
48
- const bridged = options.coverage ? bridgeStates(states, tokens.map(codeless)) : new Map();
49
+ const bridged = bridgeStates(states);
49
50
  const starts = new Map(options.functions.map(entry => [entry.line, entry]));
50
51
  const notes = new Map();
51
52
  for (const note of options.notes)
@@ -73,7 +74,7 @@ export function renderSource(container, text, options) {
73
74
  const start = starts.get(number);
74
75
  if (start)
75
76
  mark.append(complexityBadge(start));
76
- mark.append(...coverageCell(options.coverage?.get(number), bridged.get(number), runs));
77
+ mark.append(...coverageCell(options.coverage?.get(number), bridged.get(number)));
77
78
  const anchor = element('a', 'src-number', String(number));
78
79
  anchor.href = `#L${number}`;
79
80
  anchor.addEventListener('click', event => {
@@ -1,6 +1,7 @@
1
1
  import { basename, count, element, link, parentPath } from './viewer-dom.js';
2
2
  import { duplicationContext } from './viewer-file-figures.js';
3
3
  import { isLockfile, languageColor, languageOf } from './viewer-languages.js';
4
+ import { partialNote } from './viewer-totals.js';
4
5
  const icons = { file: 'fx-file-icon', folder: 'fx-folder-icon', component: 'fx-component-icon' };
5
6
  /** In the flat list the folder is context and the file name is the subject; a long folder wraps after a slash. */
6
7
  function flatLabel(path) {
@@ -38,12 +39,17 @@ function entryIcon(row) {
38
39
  icon.style.color = isLockfile(row.entry.path) ? 'var(--lockfile)' : languageColor(languageOf(row.entry));
39
40
  return icon;
40
41
  }
41
- function cell(entry, column) {
42
+ function cell(entry, column, files) {
42
43
  const result = element('td', 'numeric', column.display(entry));
43
44
  if (column.value(entry) === 0)
44
45
  result.classList.add('fx-zero');
45
46
  if (column.label === 'Duplication')
46
47
  result.title = duplicationContext(entry) ?? '';
48
+ const partial = files && column.present ? partialNote(files, column.present) : undefined;
49
+ if (partial) {
50
+ result.classList.add('fx-partial');
51
+ result.title = partial;
52
+ }
47
53
  return result;
48
54
  }
49
55
  /** One row of the Metrics table: its name, with what it is and how many files it holds, then its figures. */
@@ -65,7 +71,7 @@ export function metricsRow(row, context, open) {
65
71
  name.append(element('span', 'fx-entry-tag', 'Lockfile'));
66
72
  if (kind !== 'file' && 'files' in entry)
67
73
  name.append(element('span', 'fx-entry-count', count(entry.files)));
68
- result.append(name, ...context.columns.map(column => cell(entry, column)));
74
+ result.append(name, ...context.columns.map(column => cell(entry, column, row.files)));
69
75
  return result;
70
76
  }
71
77
  function counted(total, one, many) {
@@ -5,6 +5,8 @@ export type RowKind = 'folder' | 'file' | 'component';
5
5
  export interface Row {
6
6
  readonly entry: Metrics;
7
7
  readonly kind: RowKind;
8
+ /** The files a folder's or a component's total is made of. */
9
+ readonly files?: readonly Metrics[];
8
10
  }
9
11
  /** A row of the table, or the fold that stands for the ignored ones. */
10
12
  export type DisplayRow = Row | {
@@ -1,4 +1,4 @@
1
- import { count, parentPath } from './viewer-dom.js';
1
+ import { count, inside, parentPath } from './viewer-dom.js';
2
2
  import { compareEntries } from './viewer-file-figures.js';
3
3
  import { pageSize } from './viewer-inspection.js';
4
4
  import { aggregate } from './viewer-totals.js';
@@ -13,18 +13,20 @@ const fileRow = (entry) => ({ entry, kind: 'file' });
13
13
  export function componentRows(components, files, filtering) {
14
14
  const chosen = new Map(files.map(entry => [entry.path, entry]));
15
15
  const rows = components.map(({ component, paths }) => ({
16
- entry: aggregate(component.name, paths.flatMap(path => chosen.get(path) ?? [])), kind: 'component'
16
+ entry: aggregate(component.name, paths.flatMap(path => chosen.get(path) ?? [])), kind: 'component',
17
+ files: paths.flatMap(path => chosen.get(path) ?? [])
17
18
  }))
18
19
  .filter(row => !filtering || row.entry.files > 0);
19
20
  const assigned = new Set(components.flatMap(({ paths }) => paths));
20
21
  const rest = files.filter(entry => !assigned.has(entry.path));
21
22
  if (rest.length)
22
- rows.push({ entry: aggregate(notInComponent, rest), kind: 'component' });
23
+ rows.push({ entry: aggregate(notInComponent, rest), kind: 'component', files: rest });
23
24
  return rows;
24
25
  }
25
26
  /** A folder's own listing: the folders right under it with their recorded totals, then its files. */
26
27
  export function folderRows(directories, files, directory) {
27
- return [...directories.filter(entry => entry.path && parentPath(entry.path) === directory).map(folderRow),
28
+ const under = (entry) => ({ ...folderRow(entry), files: files.filter(file => inside(file.path, entry.path)) });
29
+ return [...directories.filter(entry => entry.path && parentPath(entry.path) === directory).map(under),
28
30
  ...files.filter(entry => parentPath(entry.path) === directory).map(fileRow)];
29
31
  }
30
32
  /** Filtered folders hold only what passes the query, and their totals count only that. */
@@ -42,7 +44,7 @@ export function filteredFolderRows(files, directory) {
42
44
  below.set(folder, [...below.get(folder) ?? [], entry]);
43
45
  }
44
46
  }
45
- return [...[...below].map(([path, entries]) => folderRow(aggregate(path, entries))), ...here.map(fileRow)];
47
+ return [...[...below].map(([path, entries]) => ({ ...folderRow(aggregate(path, entries)), files: entries })), ...here.map(fileRow)];
46
48
  }
47
49
  /** Sorts in place by a column; sorted by path, folders come before files. */
48
50
  export function sortRows(rows, byPath, value, ascending) {
@@ -6,11 +6,8 @@ export type Run = [TokenKind, string];
6
6
  * before the slash. State carries across lines, so a block comment or a template literal stays coloured to its end.
7
7
  * Other languages come back as plain text.
8
8
  */
9
- export declare function tokenizer(path: string): (line: string) => Run[];
10
- /** A line with no code: blank, or nothing but comment. */
11
- export declare function codeless(lineRuns: readonly (readonly [TokenKind, string])[]): boolean;
9
+ export declare function tokenizer(language: string | undefined): (line: string) => Run[];
12
10
  /** A line's runs as nodes: coloured spans and plain text. */
13
11
  export declare function runNodes(lineRuns: readonly Run[]): Node[];
12
+ /** Highlights a file's lines, or a snippet of them, by the file's language. */
14
13
  export declare function highlighter(path: string): (line: string) => Node[];
15
- /** A single line of code, coloured as the source view colours it; for a snippet that stands on its own. */
16
- export declare function highlightCode(path: string, line: string): Node[];
@@ -1,9 +1,13 @@
1
1
  // Light highlighting for JavaScript and TypeScript: a scanner, not a parser, that colours comments, strings, regular
2
- // expressions, numbers and keywords. Other languages come back as plain text.
2
+ // expressions, numbers and keywords. A file is read by its language as the inspection names it; any other language comes
3
+ // back as plain text, never in another language's colours.
3
4
  import { element } from './viewer-dom.js';
5
+ import { languageIdOf } from './viewer-languages.js';
4
6
  const keywords = new Set(('abstract as async await break case catch class const continue debugger declare default delete do else enum export '
5
7
  + 'extends false finally for from function get if implements import in instanceof interface let new null of package private protected '
6
8
  + 'public readonly return satisfies set static super switch this throw true try type typeof undefined var void while with yield').split(' '));
9
+ /** The languages this scanner was written for. */
10
+ const scanned = new Set(['javascript', 'typescript']);
7
11
  /** Words after which a slash opens a regular expression rather than divides. */
8
12
  const beforeRegex = new Set('return typeof instanceof in of new delete void throw case do else yield await'.split(' '));
9
13
  /** Past an escape: the index after the closing quote, or the line's end when it stays open. */
@@ -156,8 +160,8 @@ function runs() {
156
160
  * before the slash. State carries across lines, so a block comment or a template literal stays coloured to its end.
157
161
  * Other languages come back as plain text.
158
162
  */
159
- export function tokenizer(path) {
160
- if (!/\.(m|c)?[jt]sx?$/.test(path))
163
+ export function tokenizer(language) {
164
+ if (!scanned.has(language))
161
165
  return line => [['', line]];
162
166
  const state = { open: '', regexAllowed: true };
163
167
  return line => {
@@ -174,19 +178,12 @@ export function tokenizer(path) {
174
178
  return collected.done();
175
179
  };
176
180
  }
177
- /** A line with no code: blank, or nothing but comment. */
178
- export function codeless(lineRuns) {
179
- return lineRuns.every(([kind, value]) => kind === 'c' || !value.trim());
180
- }
181
181
  /** A line's runs as nodes: coloured spans and plain text. */
182
182
  export function runNodes(lineRuns) {
183
183
  return lineRuns.map(([kind, value]) => kind ? element('span', `tok-${kind}`, value) : document.createTextNode(value));
184
184
  }
185
+ /** Highlights a file's lines, or a snippet of them, by the file's language. */
185
186
  export function highlighter(path) {
186
- const tokenize = tokenizer(path);
187
+ const tokenize = tokenizer(languageIdOf(path));
187
188
  return line => runNodes(tokenize(line));
188
189
  }
189
- /** A single line of code, coloured as the source view colours it; for a snippet that stands on its own. */
190
- export function highlightCode(path, line) {
191
- return highlighter(path)(line);
192
- }
@@ -5,6 +5,12 @@ type Read = (entry: Metrics) => number | null | undefined;
5
5
  export declare function sum(files: readonly Metrics[], read: Read): number | null;
6
6
  /** Totals for any set of files, measured the way folder totals are: sums, the peak, and ratios of sums. */
7
7
  export declare function aggregate(path: string, files: readonly Metrics[]): Directory;
8
+ /**
9
+ * Where only some of the files whose code was measured carry a measure, their total is partial and says so; a total
10
+ * that all of them carry, or none, says nothing more. A file only a scanner read (a workflow, a manifest) has no code
11
+ * measures and is not expected to carry one.
12
+ */
13
+ export declare function partialNote(files: readonly Metrics[], present: (entry: Metrics) => boolean): string | undefined;
8
14
  /** The folders all of whose files are only counted, found in one pass over the files. */
9
15
  export declare function unreadFolders(files: readonly Pick<Metrics, 'path' | 'analysed'>[]): Set<string>;
10
16
  /** The folders above a path, nearest first. */
@@ -1,3 +1,4 @@
1
+ import { count } from './viewer-dom.js';
1
2
  import { sized } from './viewer-languages.js';
2
3
  import { localCatalog } from './viewer-inspection.js';
3
4
  import { rollUp } from './viewer-metric-registry.js';
@@ -62,6 +63,16 @@ export function aggregate(path, files) {
62
63
  ...(sized(files) ? { bytes: zeroSum(files, entry => entry.bytes) } : {}),
63
64
  };
64
65
  }
66
+ /**
67
+ * Where only some of the files whose code was measured carry a measure, their total is partial and says so; a total
68
+ * that all of them carry, or none, says nothing more. A file only a scanner read (a workflow, a manifest) has no code
69
+ * measures and is not expected to carry one.
70
+ */
71
+ export function partialNote(files, present) {
72
+ const read = files.filter(entry => entry.quality !== undefined);
73
+ const measured = read.filter(present).length;
74
+ return measured > 0 && measured < read.length ? `Measured in ${count(measured)} of ${count(read.length)} files` : undefined;
75
+ }
65
76
  /** The folders all of whose files are only counted, found in one pass over the files. */
66
77
  export function unreadFolders(files) {
67
78
  const read = new Map();
@@ -10,7 +10,7 @@ export interface TrendData {
10
10
  readonly context: Record<string, InspectionContext> | null;
11
11
  readonly compact: boolean;
12
12
  /** How many pull request reviews are saved: changed-line coverage is a series only where there are some. */
13
- readonly reviews?: number | undefined;
13
+ readonly reviews: number;
14
14
  /** Link to the Trends page for a commit, keeping or replacing the view and period. */
15
15
  readonly link: (sha: string, view?: TrendView, period?: Period) => string;
16
16
  }
@@ -54,7 +54,7 @@ export function trendValue(data, report, metric) {
54
54
  */
55
55
  export function availableViews(data) {
56
56
  const has = (metric) => data.reports.some(report => trendValue(data, report, metric) !== null);
57
- const shown = (view) => view === 'diff-coverage' ? (data.reviews ?? 0) > 0 : has(view === 'debt-changes' ? 'effort' : view);
57
+ const shown = (view) => view === 'diff-coverage' ? data.reviews > 0 : has(view === 'debt-changes' ? 'effort' : view);
58
58
  return groups().flatMap(([, views]) => views).filter(shown);
59
59
  }
60
60
  /** The whole curve by default; only a very long history opens on its last hundred inspections. */
@@ -1,5 +1,5 @@
1
1
  import { element } from './viewer-dom.js';
2
- import { coverageGrade, formatMetric } from './viewer-metrics.js';
2
+ import { coverageGrade, formatMetric, gradeScope } from './viewer-metrics.js';
3
3
  import { groups, trendValue, viewLabel, viewMetric } from './viewer-trend-data.js';
4
4
  function gradeLabel(text, grade) {
5
5
  const label = element('span', 'trend-reading trend-reading-grade', text);
@@ -43,7 +43,8 @@ function groupBlock({ data, selected, current, period }, group, present) {
43
43
  title.append(reading);
44
44
  const list = element('ul');
45
45
  list.append(...present.map(view => seriesLink(data, selected, view, view === current, period)));
46
- block.append(title, list);
46
+ const scope = group === 'Maintainability' ? gradeScope(data.quality[selected.sha]) : undefined;
47
+ block.append(title, ...scope ? [element('p', 'trend-group-note', scope)] : [], list);
47
48
  return block;
48
49
  }
49
50
  /** The series list, and a select with the same series for a narrow screen. */
@@ -102,13 +102,7 @@ function start(data) {
102
102
  updateTabs(page, row.findingCount, row.diagnosticCount);
103
103
  else if (cachedDetail)
104
104
  updateDetailsTabs(page, cachedDetail);
105
- if (pullReviewCount !== undefined)
106
- showTab('pulls', pullReviewCount > 0 || page === 'pulls');
107
- else
108
- void loadPulls().then(records => {
109
- if (version === revision)
110
- showTab('pulls', Boolean(records?.length) || page === 'pulls');
111
- });
105
+ showTab('pulls', pullReviewCount > 0 || page === 'pulls');
112
106
  void detail?.then(asset => {
113
107
  if (!asset || version !== revision)
114
108
  return;
@@ -106,6 +106,11 @@ export function historyEntry(report) {
106
106
  lineCoverage = { covered: item.covered, total: item.total };
107
107
  }
108
108
  }
109
+ const unmeasured = new Set(report.pluginData?.inventory?.flatMap(file => file.unmeasured ?? []));
110
+ if (unmeasured.has('functions'))
111
+ functions = null;
112
+ if (unmeasured.has('cyclomaticComplexity'))
113
+ maxComplexity = null;
109
114
  const window = report.appliedConfig.churnWindow;
110
115
  const endingAt = isRecord(window) && typeof window.endingAt === 'string' ? window.endingAt : '';
111
116
  const committedAt = Date.parse(report.committedAt ?? endingAt);