repometry 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repometry",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Track repository metrics without SaaS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -428,6 +428,9 @@
428
428
  .fx-source { min-width: 0; padding: 0; overflow: hidden; }
429
429
  .fx-source-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .25rem 1rem; padding: .625rem 1rem; background: var(--band); border-bottom: 1px solid var(--rule); }
430
430
  .fx-source-path { min-width: 0; font-size: .8125rem; color: var(--ink); overflow-wrap: anywhere; }
431
+ .fx-source-name { display: inline-flex; align-items: center; gap: .125rem; min-width: 0; }
432
+ .fx-source-name .fx-copy-inline { position: static; flex: none; width: 1.5rem; height: 1.5rem; }
433
+ .fx-source-name .fx-copy-inline svg { width: .8125rem; height: .8125rem; }
431
434
  .fx-source-meta { display: inline-flex; align-items: center; gap: .375rem; font-size: .75rem; color: var(--secondary); }
432
435
  /* The switch between findings and coverage leads the head's right side; a narrow head wraps it under the name whole. */
433
436
  .fx-source-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .375rem .875rem; min-width: 0; }
@@ -446,18 +449,19 @@
446
449
  .src-number:hover { color: var(--ink); }
447
450
  .src-code { padding-right: 1.5rem; font: inherit; white-space: pre; color: var(--ink); }
448
451
  .src-flagged { background: var(--warn-bg); }
449
- /* Coverage replaces the findings on the lines: covered green, partly covered amber, missed red, unmeasured plain. The
450
- gutter says the same by shape, a full, half or empty dot, for readers who do not tell the tints apart. */
452
+ /* Coverage replaces the findings in the gutter and leaves the code plain: each measured line's cell is tinted, quiet
453
+ green where tests ran, coral where they missed, amber where they missed branches, and says how often it ran where
454
+ the report counts it; a miss needs no number. Blank and comment lines keep the strip's tint without a count; unmeasured lines
455
+ stay plain, and runs of lines join into one strip. */
451
456
  .src-cov { display: none; }
452
457
  .src[data-layer="coverage"] .src-complexity, .src[data-layer="coverage"] .src-note { display: none; }
453
458
  .src[data-layer="coverage"] .src-flagged { background: none; }
454
- .src[data-layer="coverage"] .src-cov-covered { background: var(--good-bg); }
455
- .src[data-layer="coverage"] .src-cov-partial { background: var(--warn-bg); }
456
- .src[data-layer="coverage"] .src-cov-uncovered { background: var(--bad-bg); }
457
- .src[data-layer="coverage"] .src-cov { display: block; width: .5rem; height: .5rem; border: 1.5px solid currentColor; border-radius: 50%; }
458
- .src-cov-mark-covered { color: var(--good); background: currentColor; }
459
- .src-cov-mark-partial { color: var(--grade-c); background: linear-gradient(90deg, currentColor 50%, transparent 50%); }
460
- .src-cov-mark-uncovered { color: var(--bad); }
459
+ .src[data-layer="coverage"] .src-line { grid-template-columns: 3.25rem 3rem max-content; }
460
+ .src[data-layer="coverage"] .src-cov { display: flex; flex: 1; align-self: stretch; align-items: center; justify-content: flex-end;
461
+ padding-right: .5rem; font-family: var(--sans); font-size: .6875rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
462
+ .src-cov-mark-covered { color: var(--cov-hit-ink); background: var(--cov-hit-bg); }
463
+ .src-cov-mark-partial { color: var(--cov-part-ink); background: var(--cov-part-bg); }
464
+ .src-cov-mark-uncovered { color: var(--cov-miss-ink); background: var(--cov-miss-bg); }
461
465
  .src-target, .src-target:hover { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
462
466
  .src-complexity { min-width: 1.375rem; padding: 0 .25rem; font-family: var(--sans); font-size: .6875rem; font-weight: 650; line-height: 1.125rem; text-align: center; border-radius: 4px; color: var(--secondary); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--rule); }
463
467
  .src-band-1 { color: var(--heat-ink); background: var(--heat-1); box-shadow: none; }
@@ -22,7 +22,13 @@
22
22
  --flag-good: #2f9445;
23
23
  --flag-bad: #c63d36;
24
24
  --bad-bg: #fdecea;
25
- --good-bg: #eff8f2;
25
+ /* Line coverage cells in the source gutter: a quiet green, coral for what tests missed, amber for missed branches. */
26
+ --cov-hit-bg: #e2f2e8;
27
+ --cov-hit-ink: #2f6e49;
28
+ --cov-miss-bg: #fbe2df;
29
+ --cov-miss-ink: #a8382e;
30
+ --cov-part-bg: #fbedcd;
31
+ --cov-part-ink: #7d5a10;
26
32
  --bad-ink: #9f2a21;
27
33
  --warn-bg: #fdf3dc;
28
34
  --warn-ink: #81580a;
@@ -87,7 +93,12 @@
87
93
  --flag-good: #5fd06a;
88
94
  --flag-bad: #f0736b;
89
95
  --bad-bg: #3a1c1a;
90
- --good-bg: #11231a;
96
+ --cov-hit-bg: #15301f;
97
+ --cov-hit-ink: #8fd0a9;
98
+ --cov-miss-bg: #3b1d1a;
99
+ --cov-miss-ink: #f0958c;
100
+ --cov-part-bg: #372a10;
101
+ --cov-part-ink: #e6c272;
91
102
  --bad-ink: #ffb1a8;
92
103
  --warn-bg: #352812;
93
104
  --warn-ink: #f2cd7f;
@@ -1,7 +1,7 @@
1
1
  import { formatQuery, ignoredLabel, isLockfile, languageColor, languageOf, languageShares, lockfilesLabel, matches, parseQuery, queryField, sameClause, sized, suggest, usePluginMeasures } from './viewer-filter.js';
2
2
  import { bandLabels as pluginBandLabels, bandOf, bandScale, catalogIndex, compareValues, entryValue, firstSortAscending, format, rollUp } from './viewer-metric-registry.js';
3
3
  import { extendCatalog, labelOf, pluginMetrics, pluginSpec, securityRisks, size } from './viewer-metrics.js';
4
- import { highlightCode, isSourceLayer, lineSnippet, lineStates, renderExcerpt, renderSource, setSourceLayer } from './viewer-source.js';
4
+ import { highlightCode, isSourceLayer, lineHits, lineSnippet, lineStates, renderExcerpt, renderSource, setSourceLayer } from './viewer-source.js';
5
5
  /**
6
6
  * The finding categories Repometry counts as code smells, mirroring core's quality summary (structure and
7
7
  * duplication), so the Overview's smell count links to exactly the findings it counts.
@@ -544,10 +544,9 @@ function directorySummary(entry, analysed, lockfiles, selection) {
544
544
  panel.setAttribute('aria-label', selection ? 'Selection totals' : 'Folder totals');
545
545
  const heading = element('div', 'fx-aside-heading');
546
546
  heading.append(element('h2', '', selection ? 'Selection' : entry.path ? basename(entry.path) : 'All files'));
547
+ // The breadcrumbs above name the folder; only a selection needs its words here.
547
548
  if (selection)
548
549
  heading.append(element('p', 'fx-aside-path fx-aside-selection', selection));
549
- else if (entry.path.includes('/'))
550
- heading.append(element('p', 'fx-aside-path', parentPath(entry.path) + '/'));
551
550
  const facts = element('dl', 'fx-kv');
552
551
  // A measurement the inspection did not take leaves no row behind.
553
552
  const quality = entry.quality;
@@ -578,13 +577,12 @@ function fileDetails(details, entry, navigation, hooks = {}) {
578
577
  const panel = element('aside', 'fx-aside fx-file');
579
578
  panel.setAttribute('aria-label', 'File details');
580
579
  const heading = element('div', 'fx-aside-heading');
580
+ // The breadcrumbs above name the folder, so the title is the file alone.
581
581
  const title = element('h2', '', basename(entry.path));
582
582
  const close = link(navigation.href('metrics', { directory: parentPath(entry.path) }), '', 'fx-close');
583
583
  close.setAttribute('aria-label', 'Close file details');
584
584
  close.title = 'Close file details';
585
585
  heading.append(title, close);
586
- if (entry.path.includes('/'))
587
- heading.append(element('p', 'fx-aside-path', parentPath(entry.path) + '/'));
588
586
  const facts = element('dl', 'fx-kv');
589
587
  const quality = entry.quality;
590
588
  if (quality?.codeLines !== undefined)
@@ -683,6 +681,12 @@ function fileView(details, navigation, file, load) {
683
681
  // The folder is in the breadcrumbs right above; the head names the file alone, with its full path on hover.
684
682
  const name = element('code', 'fx-source-path', basename(file.path));
685
683
  name.title = file.path;
684
+ // The whole path from the repository root is a click away; a refused clipboard shows it in the name's place, selected.
685
+ const named = element('span', 'fx-source-name');
686
+ named.append(name, copyPathButton(file.path, () => {
687
+ name.textContent = file.path;
688
+ return name;
689
+ }));
686
690
  const meta = element('span', 'fx-source-meta');
687
691
  meta.append(dot, `${language} · ${count(file.lines)} lines`);
688
692
  // Lines show the findings, or the tests' coverage where the file has it; without coverage the head stays as it was.
@@ -700,7 +704,7 @@ function fileView(details, navigation, file, load) {
700
704
  toggle?.classList.add('fx-source-layer');
701
705
  const tools = element('div', 'fx-source-tools');
702
706
  tools.append(...toggle ? [toggle] : [], meta);
703
- head.append(name, tools);
707
+ head.append(named, tools);
704
708
  // The forge's page for the file, at the chosen line, whether or not the text opens here.
705
709
  const page = navigation.sourcePage?.(file.path, navigation.line);
706
710
  const forge = page ? link(page.href, `View on ${page.provider}`, 'fx-source-forge') : null;
@@ -739,7 +743,7 @@ function fileView(details, navigation, file, load) {
739
743
  path: file.path,
740
744
  functions: functions.flatMap(record => record.line === null ? [] : [{ line: record.line, complexity: record.complexity, name: record.name }]),
741
745
  notes, line: navigation.line, choose,
742
- coverage: coverage ? lineStates(coverage) : undefined, layer,
746
+ coverage: coverage ? lineStates(coverage) : undefined, hits: coverage ? lineHits(coverage) : undefined, layer,
743
747
  });
744
748
  const next = fileDetails(details, file, nav, { text, reveal: line => { reveal(line); choose(line); } });
745
749
  aside.replaceWith(next);
@@ -1793,6 +1797,38 @@ function ignoreSnippet(finding) {
1793
1797
  details.append(title, hint, code, feedback);
1794
1798
  return details;
1795
1799
  }
1800
+ /**
1801
+ * Copies a file's path from the repository root. Where the browser refuses the clipboard, `show` puts the path on the
1802
+ * page and it is selected, for the reader's own copy shortcut.
1803
+ */
1804
+ function copyPathButton(path, show) {
1805
+ const label = 'Copy path';
1806
+ const copy = element('button', 'fx-copy fx-copy-inline');
1807
+ copy.type = 'button';
1808
+ copy.title = `${label}: ${path}`;
1809
+ copy.setAttribute('aria-label', label);
1810
+ copy.append(copyIcon());
1811
+ const status = element('span', 'visually-hidden');
1812
+ status.setAttribute('role', 'status');
1813
+ copy.append(status);
1814
+ let reset;
1815
+ copy.addEventListener('click', async () => {
1816
+ clearTimeout(reset);
1817
+ try {
1818
+ if (!navigator.clipboard)
1819
+ throw new Error('Clipboard unavailable');
1820
+ await navigator.clipboard.writeText(path);
1821
+ copy.classList.add('fx-copied');
1822
+ status.textContent = 'Path copied';
1823
+ reset = setTimeout(() => { copy.classList.remove('fx-copied'); status.textContent = ''; }, 1500);
1824
+ }
1825
+ catch {
1826
+ window.getSelection()?.selectAllChildren(show());
1827
+ status.textContent = 'Path selected. Press your copy shortcut.';
1828
+ }
1829
+ });
1830
+ return copy;
1831
+ }
1796
1832
  /** The common copy glyph, two offset sheets, with the check it turns into once copied. */
1797
1833
  export function copyIcon() {
1798
1834
  const svg = svgElement('svg');
@@ -48,12 +48,22 @@ export declare function isSourceLayer(value: string | null | undefined): value i
48
48
  * state wins: a line a test missed is never shown as covered.
49
49
  */
50
50
  export declare function lineStates(coverage: FileLineCoverage): Map<number, LineState>;
51
+ /** Runs of equal hit counts: first and last line, 1-based and inclusive, and how often tests ran them; 0 is a miss. */
52
+ export type HitRun = readonly [first: number, last: number, count: number];
53
+ /** How often tests ran each line, where the report carries the counts; an older report has none. */
54
+ export declare function lineHits(coverage: FileLineCoverage): Map<number, number>;
55
+ /** A count short enough for the gutter: 3×, 980×, 1.2K×, 45K×, 270K×, 3.4M×. */
56
+ export declare function hitLabel(count: number): string;
57
+ /** What a measured line says to a pointer and a screen reader: its state, and how often it ran where that is known. */
58
+ export declare function lineCoverageText(state: LineState, count?: number): string;
51
59
  export interface SourceOptions {
52
60
  readonly path: string;
53
61
  readonly functions: readonly SourceFunction[];
54
62
  readonly notes: readonly SourceNote[];
55
63
  /** Each line's coverage, where the file has a coverage report. */
56
64
  readonly coverage?: ReadonlyMap<number, LineState> | undefined;
65
+ /** How often tests ran each line, where the report counts it. */
66
+ readonly hits?: ReadonlyMap<number, number> | undefined;
57
67
  /** What the lines show first; the view switches it with setSourceLayer. */
58
68
  readonly layer?: SourceLayer | undefined;
59
69
  /** The line to bring into view and mark, from the URL. */
@@ -91,3 +101,5 @@ export type TokenKind = '' | 'c' | 's' | 'n' | 'k';
91
101
  * template literal stays coloured to its end. Other languages come back as plain text.
92
102
  */
93
103
  export declare function tokenizer(path: string): (line: string) => [TokenKind, string][];
104
+ /** A line with no code: blank, or nothing but comment. */
105
+ export declare function codeless(runs: readonly (readonly [TokenKind, string])[]): boolean;
@@ -75,6 +75,29 @@ export function lineStates(coverage) {
75
75
  lay(coverage.uncovered, 'uncovered');
76
76
  return states;
77
77
  }
78
+ /** How often tests ran each line, where the report carries the counts; an older report has none. */
79
+ export function lineHits(coverage) {
80
+ // The wire is getting `hits`; until it lands the field is read off the record as the agreed shape.
81
+ const runs = coverage.hits;
82
+ const hits = new Map();
83
+ for (const [from, to, count] of runs ?? [])
84
+ for (let line = Math.max(1, from); line <= to; line++)
85
+ hits.set(line, count);
86
+ return hits;
87
+ }
88
+ // Two figures are enough for a glance; the tooltip has the whole count.
89
+ const compactCount = new Intl.NumberFormat('en', { notation: 'compact', maximumSignificantDigits: 2 });
90
+ const fullCount = new Intl.NumberFormat();
91
+ /** A count short enough for the gutter: 3×, 980×, 1.2K×, 45K×, 270K×, 3.4M×. */
92
+ export function hitLabel(count) {
93
+ return `${count < 1000 ? count : compactCount.format(count)}×`;
94
+ }
95
+ /** What a measured line says to a pointer and a screen reader: its state, and how often it ran where that is known. */
96
+ export function lineCoverageText(state, count) {
97
+ if (count === undefined || state === 'uncovered')
98
+ return lineStateNames[state];
99
+ return `${lineStateNames[state]}. Ran ${fullCount.format(count)} ${count === 1 ? 'time' : 'times'}`;
100
+ }
78
101
  const lineStateNames = {
79
102
  covered: 'Covered', partial: 'Partly covered: some branches missed', uncovered: 'Not covered',
80
103
  };
@@ -87,7 +110,7 @@ export function setSourceLayer(container, layer) {
87
110
  /** The source as numbered lines; returns a function that brings a line into view and marks it. */
88
111
  export function renderSource(container, text, options) {
89
112
  const lines = text.replace(/\r\n?/g, '\n').replace(/\n$/, '').split('\n');
90
- const highlight = highlighter(options.path);
113
+ const tokenize = tokenizer(options.path);
91
114
  const starts = new Map(options.functions.map(entry => [entry.line, entry]));
92
115
  const notes = new Map();
93
116
  for (const note of options.notes)
@@ -109,15 +132,22 @@ export function renderSource(container, text, options) {
109
132
  badge.title = `Cyclomatic complexity ${start.complexity}`;
110
133
  mark.append(badge);
111
134
  }
112
- // The coverage layer marks each measured line in the gutter by shape, full, half or empty, as well as by its tint.
135
+ // The coverage layer tints each measured line's gutter cell and writes in it how often the line ran; a miss's red says it.
136
+ // Some tools count blank and comment lines as run; nothing runs there, so they keep the strip's tint and say nothing.
137
+ const runs = tokenize(line);
113
138
  const state = options.coverage?.get(number);
114
- if (state) {
115
- row.classList.add(`src-cov-${state}`);
116
- const glyph = element('span', `src-cov src-cov-mark-${state}`);
117
- glyph.setAttribute('role', 'img');
118
- glyph.setAttribute('aria-label', lineStateNames[state]);
119
- glyph.title = lineStateNames[state];
120
- mark.append(glyph);
139
+ if (state && codeless(runs)) {
140
+ const cell = element('span', `src-cov src-cov-mark-${state}`);
141
+ cell.setAttribute('aria-hidden', 'true');
142
+ mark.append(cell);
143
+ }
144
+ else if (state) {
145
+ const count = options.hits?.get(number);
146
+ const cell = element('span', `src-cov src-cov-mark-${state}`, count === undefined || state === 'uncovered' ? '' : hitLabel(count));
147
+ cell.setAttribute('role', 'img');
148
+ cell.setAttribute('aria-label', lineCoverageText(state, count));
149
+ cell.title = lineCoverageText(state, count);
150
+ mark.append(cell);
121
151
  }
122
152
  const anchor = element('a', 'src-number', String(number));
123
153
  anchor.href = `#L${number}`;
@@ -127,7 +157,7 @@ export function renderSource(container, text, options) {
127
157
  options.choose(number);
128
158
  });
129
159
  const content = element('code', 'src-code');
130
- content.append(...highlight(line));
160
+ content.append(...runs.map(([kind, value]) => kind ? element('span', `tok-${kind}`, value) : document.createTextNode(value)));
131
161
  if (notes.has(number))
132
162
  row.classList.add('src-flagged');
133
163
  row.append(mark, anchor, content);
@@ -338,6 +368,10 @@ export function tokenizer(path) {
338
368
  return runs;
339
369
  };
340
370
  }
371
+ /** A line with no code: blank, or nothing but comment. */
372
+ export function codeless(runs) {
373
+ return runs.every(([kind, value]) => kind === 'c' || !value.trim());
374
+ }
341
375
  function highlighter(path) {
342
376
  const tokenize = tokenizer(path);
343
377
  return line => tokenize(line).map(([kind, value]) => kind ? element('span', `tok-${kind}`, value) : document.createTextNode(value));