@skeudo/core 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/code/analyze.d.ts +87 -0
- package/dist/code/analyze.js +135 -0
- package/dist/code/fold.d.ts +39 -0
- package/dist/code/fold.js +48 -0
- package/dist/code/parse.d.ts +36 -0
- package/dist/code/parse.js +597 -0
- package/dist/code/types.d.ts +173 -0
- package/dist/code/types.js +1 -0
- package/dist/data/parse.d.ts +10 -0
- package/dist/data/parse.js +266 -0
- package/dist/data/replay.d.ts +16 -0
- package/dist/data/replay.js +142 -0
- package/dist/data/types.d.ts +125 -0
- package/dist/data/types.js +2 -0
- package/dist/diagnostic.d.ts +7 -0
- package/dist/diagnostic.js +1 -0
- package/dist/header.d.ts +15 -0
- package/dist/header.js +22 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +11 -0
- package/dist/views.d.ts +27 -0
- package/dist/views.js +50 -0
- package/package.json +39 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The Skeudo authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @skeudo/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Alpha.** The format and this API will change in ways that break existing sketches and code. Until 1.0, breaking changes come in minor versions (0.1 to 0.2), never in patches, and the [release notes](https://github.com/wlezzar/skeudo/releases) list each one.
|
|
4
|
+
|
|
5
|
+
The parser for [Skeudo](https://github.com/wlezzar/skeudo), small text formats for explaining code to a reader. A sketch is pseudocode for code review where every outside effect is tagged, or a data model drawn as tables and a story of how their rows change, and its first line says which: `view: code` or `view: data`. The format is defined in [spec/spec.md](https://github.com/wlezzar/skeudo/blob/main/spec/spec.md).
|
|
6
|
+
|
|
7
|
+
Most people want a renderer instead: [`@skeudo/html`](https://www.npmjs.com/package/@skeudo/html), [`markdown-it-skeudo`](https://www.npmjs.com/package/markdown-it-skeudo), [`remark-skeudo`](https://www.npmjs.com/package/remark-skeudo) or the [`skeudo`](https://www.npmjs.com/package/skeudo) CLI. Use this package to read sketches in your own tools.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @skeudo/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { parse } from '@skeudo/core';
|
|
17
|
+
|
|
18
|
+
const sketch = parse(`view: code
|
|
19
|
+
get_user(id):
|
|
20
|
+
row = find(id) ::read:postgres.users
|
|
21
|
+
return row
|
|
22
|
+
`);
|
|
23
|
+
|
|
24
|
+
sketch.view; // 'code', or 'data' for a sketch whose first line is `view: data`
|
|
25
|
+
sketch.diagnostics; // [{ line, severity, message }], the warnings listed in the spec
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`parse` never throws. A problem becomes a warning on its line, and line numbers count from the sketch's first line. The result is a `Sketch`, a union told apart by `view`:
|
|
29
|
+
|
|
30
|
+
- A `CodeSketch` has its `lines`, each with its code segments and tags, the `variables` it defines and uses, its `signature`, and the repository it names with `::repo`. `analyze(sketch)` lists what a reviewer looks at: the effects, the systems each one touches, failures and the flows of labeled values. `rollup(sketch, line)` sums up a block for its header, as a folded header shows it.
|
|
31
|
+
- A `DataSketch` has its `tables` (and folders), `groups` and story `steps`. `replayData(sketch)` plays the story and returns the rows at each frame, and the rows each read finds.
|
|
32
|
+
|
|
33
|
+
The exported TypeScript types describe every field.
|
|
34
|
+
|
|
35
|
+
## Options
|
|
36
|
+
|
|
37
|
+
| Option | Default | |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| `labelKinds` | `['untrusted', 'secret']` | Tag kinds whose value labels a variable, as `::untrusted:body` labels `body`. Every later use of a labeled variable is marked. |
|
|
40
|
+
|
|
41
|
+
## Other exports
|
|
42
|
+
|
|
43
|
+
- `FENCE_LANGS`: the Markdown fence languages that hold a sketch, `skeudo` and `sketch`.
|
|
44
|
+
- `parseTagsOnly(text)`: the tags in a string made only of tags, such as `::read:postgres.users`, or undefined. The Markdown plugins use it for inline code.
|
|
45
|
+
- `parseRepo(url)` and `repoId(repo)`: the `::repo` forms.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
MIT
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Diagnostic } from '../diagnostic.ts';
|
|
2
|
+
import type { ChangeKind, CodeSketch, Note, SketchLine, Tag, Variable } from './types.ts';
|
|
3
|
+
export interface Effect {
|
|
4
|
+
line: number;
|
|
5
|
+
direction: 'read' | 'write';
|
|
6
|
+
/** Full system value, such as `postgres.orders` or `*`. */
|
|
7
|
+
system: string;
|
|
8
|
+
/** System without its part: `postgres`. */
|
|
9
|
+
root: string;
|
|
10
|
+
/** Part after the first dot: `orders`. */
|
|
11
|
+
part?: string;
|
|
12
|
+
conditional: boolean;
|
|
13
|
+
unverified: boolean;
|
|
14
|
+
/** The system is `*`: decided at runtime. */
|
|
15
|
+
runtime: boolean;
|
|
16
|
+
note?: Note;
|
|
17
|
+
tag: Tag;
|
|
18
|
+
/** The line's text with its tags removed. */
|
|
19
|
+
context: string;
|
|
20
|
+
/** What the change being sketched did to the effect's line. A removed effect is one the code no longer has. */
|
|
21
|
+
change?: ChangeKind;
|
|
22
|
+
}
|
|
23
|
+
/** A change tag, with the effects on the lines it covers. */
|
|
24
|
+
export interface Change {
|
|
25
|
+
line: number;
|
|
26
|
+
kind: ChangeKind;
|
|
27
|
+
note?: string;
|
|
28
|
+
tag: Tag;
|
|
29
|
+
context: string;
|
|
30
|
+
/** True when the tag is `::new` or `::removed` on a block header, so it covers the whole block. */
|
|
31
|
+
block: boolean;
|
|
32
|
+
/** Effects on the lines the change covers, in order. */
|
|
33
|
+
effects: Effect[];
|
|
34
|
+
}
|
|
35
|
+
/** Systems, counted from the effects the code has: removed effects are left out. */
|
|
36
|
+
export interface SystemUse {
|
|
37
|
+
name: string;
|
|
38
|
+
reads: number;
|
|
39
|
+
writes: number;
|
|
40
|
+
parts: string[];
|
|
41
|
+
runtime: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface Failure {
|
|
44
|
+
line: number;
|
|
45
|
+
name: string;
|
|
46
|
+
/** Prose on the line, or the enclosing block header when the line has none. */
|
|
47
|
+
condition: string;
|
|
48
|
+
tag: Tag;
|
|
49
|
+
}
|
|
50
|
+
export interface Flag {
|
|
51
|
+
line: number;
|
|
52
|
+
kind: 'danger' | 'unsure' | 'unverified' | 'runtime';
|
|
53
|
+
text: string;
|
|
54
|
+
tag: Tag;
|
|
55
|
+
}
|
|
56
|
+
/** A labeled variable used on a line that has an effect. Removed effects are left out. */
|
|
57
|
+
export interface Flow {
|
|
58
|
+
line: number;
|
|
59
|
+
variable: string;
|
|
60
|
+
labels: string[];
|
|
61
|
+
effect: Effect;
|
|
62
|
+
}
|
|
63
|
+
export interface Review {
|
|
64
|
+
effects: Effect[];
|
|
65
|
+
systems: SystemUse[];
|
|
66
|
+
failures: Failure[];
|
|
67
|
+
flags: Flag[];
|
|
68
|
+
flows: Flow[];
|
|
69
|
+
/** Change tags in a sketch of a commit or pull request, in line order. */
|
|
70
|
+
changes: Change[];
|
|
71
|
+
labeled: Variable[];
|
|
72
|
+
/** Tags of kinds the spec doesn't define, such as `::todo` or `::lock`. */
|
|
73
|
+
others: {
|
|
74
|
+
line: number;
|
|
75
|
+
tag: Tag;
|
|
76
|
+
context: string;
|
|
77
|
+
}[];
|
|
78
|
+
diagnostics: Diagnostic[];
|
|
79
|
+
}
|
|
80
|
+
/** The line's text without its tags. */
|
|
81
|
+
export declare function lineContext(line: SketchLine): string;
|
|
82
|
+
/**
|
|
83
|
+
* The tracked variables a line uses, in order: every use but a definition, and the variable a call chain
|
|
84
|
+
* starts with. Labeled data reaches an effect when the line with the effect uses the labeled variable.
|
|
85
|
+
*/
|
|
86
|
+
export declare function usedVariables(line: SketchLine): string[];
|
|
87
|
+
export declare function analyze(sketch: CodeSketch): Review;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { CHANGE_KINDS } from './parse.js';
|
|
2
|
+
const KNOWN = new Set(['read', 'write', 'fail', 'src', 'repo', 'doc', 'fold', 'danger', 'unsure', 'untrusted', 'secret', ...CHANGE_KINDS]);
|
|
3
|
+
/** The line's text without its tags. */
|
|
4
|
+
export function lineContext(line) {
|
|
5
|
+
let text = line.text;
|
|
6
|
+
for (const t of [...line.tags].reverse())
|
|
7
|
+
text = text.slice(0, t.start) + text.slice(t.end);
|
|
8
|
+
return text.replace(/\s+/g, ' ').trim();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The tracked variables a line uses, in order: every use but a definition, and the variable a call chain
|
|
12
|
+
* starts with. Labeled data reaches an effect when the line with the effect uses the labeled variable.
|
|
13
|
+
*/
|
|
14
|
+
export function usedVariables(line) {
|
|
15
|
+
const used = new Set();
|
|
16
|
+
for (const seg of line.segments) {
|
|
17
|
+
if (seg.type === 'var' && !seg.definition)
|
|
18
|
+
used.add(seg.name);
|
|
19
|
+
if (seg.type === 'call' && seg.head)
|
|
20
|
+
used.add(seg.head);
|
|
21
|
+
}
|
|
22
|
+
return [...used];
|
|
23
|
+
}
|
|
24
|
+
export function analyze(sketch) {
|
|
25
|
+
const byNumber = new Map(sketch.lines.map((l) => [l.number, l]));
|
|
26
|
+
const effects = [];
|
|
27
|
+
const failures = [];
|
|
28
|
+
const flags = [];
|
|
29
|
+
const flows = [];
|
|
30
|
+
const others = [];
|
|
31
|
+
const systems = new Map();
|
|
32
|
+
const changes = [];
|
|
33
|
+
const changeAt = new Map();
|
|
34
|
+
for (const line of sketch.lines) {
|
|
35
|
+
if (line.blank)
|
|
36
|
+
continue;
|
|
37
|
+
const context = lineContext(line);
|
|
38
|
+
const lineEffects = [];
|
|
39
|
+
const own = line.change && line.change.from === undefined ? line.tags.find((t) => CHANGE_KINDS.has(t.kind)) : undefined;
|
|
40
|
+
if (own && line.change) {
|
|
41
|
+
const change = {
|
|
42
|
+
line: line.number,
|
|
43
|
+
kind: line.change.kind,
|
|
44
|
+
note: line.change.note,
|
|
45
|
+
tag: own,
|
|
46
|
+
context,
|
|
47
|
+
block: line.header && line.change.kind !== 'changed',
|
|
48
|
+
effects: [],
|
|
49
|
+
};
|
|
50
|
+
changes.push(change);
|
|
51
|
+
changeAt.set(line.number, change);
|
|
52
|
+
}
|
|
53
|
+
const coveringChange = line.change && changeAt.get(line.change.from ?? line.number);
|
|
54
|
+
for (const tag of line.tags) {
|
|
55
|
+
if (tag.note?.danger)
|
|
56
|
+
flags.push({ line: line.number, kind: 'danger', text: tag.note.text, tag });
|
|
57
|
+
if ((tag.kind === 'read' || tag.kind === 'write') && tag.value) {
|
|
58
|
+
const system = tag.value;
|
|
59
|
+
const dot = system.indexOf('.');
|
|
60
|
+
const root = dot === -1 ? system : system.slice(0, dot);
|
|
61
|
+
const effect = {
|
|
62
|
+
line: line.number,
|
|
63
|
+
direction: tag.kind,
|
|
64
|
+
system,
|
|
65
|
+
root,
|
|
66
|
+
part: dot === -1 ? undefined : system.slice(dot + 1),
|
|
67
|
+
conditional: tag.conditional,
|
|
68
|
+
unverified: tag.unverified,
|
|
69
|
+
runtime: system === '*',
|
|
70
|
+
note: tag.note,
|
|
71
|
+
tag,
|
|
72
|
+
context,
|
|
73
|
+
change: line.change?.kind,
|
|
74
|
+
};
|
|
75
|
+
effects.push(effect);
|
|
76
|
+
coveringChange?.effects.push(effect);
|
|
77
|
+
// A removed effect is one the code no longer has: it isn't counted or followed.
|
|
78
|
+
if (effect.change !== 'removed') {
|
|
79
|
+
lineEffects.push(effect);
|
|
80
|
+
const use = systems.get(root) ?? { name: root, reads: 0, writes: 0, parts: [], runtime: effect.runtime };
|
|
81
|
+
if (tag.kind === 'read')
|
|
82
|
+
use.reads++;
|
|
83
|
+
else
|
|
84
|
+
use.writes++;
|
|
85
|
+
if (effect.part && !use.parts.includes(effect.part))
|
|
86
|
+
use.parts.push(effect.part);
|
|
87
|
+
systems.set(root, use);
|
|
88
|
+
}
|
|
89
|
+
if (effect.unverified)
|
|
90
|
+
flags.push({ line: line.number, kind: 'unverified', text: `${tag.kind}:${system} is unverified`, tag });
|
|
91
|
+
if (effect.runtime)
|
|
92
|
+
flags.push({ line: line.number, kind: 'runtime', text: `${tag.kind} target is decided at runtime`, tag });
|
|
93
|
+
}
|
|
94
|
+
else if (tag.kind === 'fail' && tag.value) {
|
|
95
|
+
let condition = context;
|
|
96
|
+
if (!condition && line.parent !== undefined) {
|
|
97
|
+
const parent = byNumber.get(line.parent);
|
|
98
|
+
if (parent)
|
|
99
|
+
condition = lineContext(parent).replace(/:$/, '');
|
|
100
|
+
}
|
|
101
|
+
failures.push({ line: line.number, name: tag.value, condition, tag });
|
|
102
|
+
}
|
|
103
|
+
else if (tag.kind === 'danger') {
|
|
104
|
+
if (!tag.note?.danger)
|
|
105
|
+
flags.push({ line: line.number, kind: 'danger', text: tag.note?.text || context, tag });
|
|
106
|
+
}
|
|
107
|
+
else if (tag.kind === 'unsure') {
|
|
108
|
+
flags.push({ line: line.number, kind: 'unsure', text: tag.note?.text || context, tag });
|
|
109
|
+
}
|
|
110
|
+
else if (!KNOWN.has(tag.kind)) {
|
|
111
|
+
others.push({ line: line.number, tag, context });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (lineEffects.length) {
|
|
115
|
+
for (const name of usedVariables(line)) {
|
|
116
|
+
const v = sketch.variables[name];
|
|
117
|
+
if (!v?.labels.length)
|
|
118
|
+
continue;
|
|
119
|
+
for (const effect of lineEffects)
|
|
120
|
+
flows.push({ line: line.number, variable: name, labels: v.labels, effect });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
effects,
|
|
126
|
+
systems: [...systems.values()],
|
|
127
|
+
failures,
|
|
128
|
+
flags,
|
|
129
|
+
flows,
|
|
130
|
+
changes,
|
|
131
|
+
labeled: Object.values(sketch.variables).filter((v) => v.labels.length),
|
|
132
|
+
others,
|
|
133
|
+
diagnostics: sketch.diagnostics,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Diagnostic } from '../diagnostic.ts';
|
|
2
|
+
import type { ChangeKind, CodeSketch, SketchLine, Tag } from './types.ts';
|
|
3
|
+
/** Tags of one kind, modifiers and value from the lines of a block, shown as one pill on its folded header. */
|
|
4
|
+
export interface RolledTag {
|
|
5
|
+
/** The first of these tags, in line order. */
|
|
6
|
+
tag: Tag;
|
|
7
|
+
/** The line of each of these tags, in order, so a line with two of them is listed twice. */
|
|
8
|
+
lines: number[];
|
|
9
|
+
/** The danger notes of these tags, in order: their `[!…]` notes, or the notes of `::danger` tags. */
|
|
10
|
+
dangers: string[];
|
|
11
|
+
/** True when they are all on removed lines, so they are effects the code no longer has. */
|
|
12
|
+
removed: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The labeled variables that reach these effects, in order: those used on a line that carries one. Only
|
|
15
|
+
* reads and writes have them, and not removed ones, as in analyze().
|
|
16
|
+
*/
|
|
17
|
+
flows: string[];
|
|
18
|
+
}
|
|
19
|
+
/** What a folded block header shows of the lines under it. */
|
|
20
|
+
export interface Rollup {
|
|
21
|
+
/** Line number of the header. */
|
|
22
|
+
header: number;
|
|
23
|
+
/** How many lines fold under the header, leaving out blank lines and lines renderers drop. */
|
|
24
|
+
lines: number;
|
|
25
|
+
/** The tags of the block's lines, in order of first appearance. */
|
|
26
|
+
tags: RolledTag[];
|
|
27
|
+
/** The changes on the block's lines, in order of first appearance. */
|
|
28
|
+
changes: ChangeKind[];
|
|
29
|
+
/** Warnings on the block's lines. */
|
|
30
|
+
diagnostics: Diagnostic[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sums up a block for its header, for when the block is folded. Every tag a reviewer must see rolls up:
|
|
34
|
+
* effects, failures, dangers, doubts, change tags and kinds the spec doesn't define. Labels stay on their
|
|
35
|
+
* variables, but the labeled variables that reach an effect are named on its pill, since the line that
|
|
36
|
+
* shows it is folded away. The tags renderers hide stay hidden. Tags of the same kind, modifiers and value
|
|
37
|
+
* share a pill. Their notes are dropped, except dangers, since a note says how and the pill only says what.
|
|
38
|
+
*/
|
|
39
|
+
export declare function rollup(sketch: CodeSketch, header: SketchLine): Rollup;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { usedVariables } from './analyze.js';
|
|
2
|
+
import { blockLines, CHANGE_KINDS, HIDDEN_KINDS } from './parse.js';
|
|
3
|
+
/**
|
|
4
|
+
* Sums up a block for its header, for when the block is folded. Every tag a reviewer must see rolls up:
|
|
5
|
+
* effects, failures, dangers, doubts, change tags and kinds the spec doesn't define. Labels stay on their
|
|
6
|
+
* variables, but the labeled variables that reach an effect are named on its pill, since the line that
|
|
7
|
+
* shows it is folded away. The tags renderers hide stay hidden. Tags of the same kind, modifiers and value
|
|
8
|
+
* share a pill. Their notes are dropped, except dangers, since a note says how and the pill only says what.
|
|
9
|
+
*/
|
|
10
|
+
export function rollup(sketch, header) {
|
|
11
|
+
const inside = blockLines(sketch.lines, header).filter((l) => !l.blank);
|
|
12
|
+
const numbers = new Set(inside.map((l) => l.number));
|
|
13
|
+
const tags = new Map();
|
|
14
|
+
const changes = [];
|
|
15
|
+
for (const line of inside) {
|
|
16
|
+
if (line.change && !changes.includes(line.change.kind))
|
|
17
|
+
changes.push(line.change.kind);
|
|
18
|
+
const labeled = usedVariables(line).filter((name) => sketch.variables[name]?.labels.length);
|
|
19
|
+
for (const tag of line.tags) {
|
|
20
|
+
if (HIDDEN_KINDS.has(tag.kind))
|
|
21
|
+
continue;
|
|
22
|
+
if (tag.value && sketch.variables[tag.value]?.labels.includes(tag.kind))
|
|
23
|
+
continue;
|
|
24
|
+
// A removed line's effects are ones the code no longer has, so they don't share a pill with current ones.
|
|
25
|
+
const removed = line.change?.kind === 'removed' && !CHANGE_KINDS.has(tag.kind);
|
|
26
|
+
const key = [tag.kind, tag.conditional, tag.unverified, tag.value ?? '', removed].join('\u0000');
|
|
27
|
+
let rolled = tags.get(key);
|
|
28
|
+
if (!rolled)
|
|
29
|
+
tags.set(key, (rolled = { tag, lines: [], dangers: [], removed, flows: [] }));
|
|
30
|
+
rolled.lines.push(line.number);
|
|
31
|
+
if ((tag.kind === 'read' || tag.kind === 'write') && tag.value && !removed) {
|
|
32
|
+
for (const name of labeled)
|
|
33
|
+
if (!rolled.flows.includes(name))
|
|
34
|
+
rolled.flows.push(name);
|
|
35
|
+
}
|
|
36
|
+
const danger = tag.note && (tag.note.danger || tag.kind === 'danger') ? tag.note.text : undefined;
|
|
37
|
+
if (danger && !rolled.dangers.includes(danger))
|
|
38
|
+
rolled.dangers.push(danger);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
header: header.number,
|
|
43
|
+
lines: inside.filter((l) => !l.hidden).length,
|
|
44
|
+
tags: [...tags.values()],
|
|
45
|
+
changes,
|
|
46
|
+
diagnostics: sketch.diagnostics.filter((d) => numbers.has(d.line)),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CodeSketch, ParseOptions, Repo, SketchLine, SrcLocation, Tag } from './types.ts';
|
|
2
|
+
/** Tag kinds that mark what a commit or pull request did to a line. */
|
|
3
|
+
export declare const CHANGE_KINDS: ReadonlySet<string>;
|
|
4
|
+
/**
|
|
5
|
+
* Tag kinds that renderers hide: `::src` and `::repo` become links, `::doc` shows on hover, and `::fold`
|
|
6
|
+
* folds its block.
|
|
7
|
+
*/
|
|
8
|
+
export declare const HIDDEN_KINDS: ReadonlySet<string>;
|
|
9
|
+
/**
|
|
10
|
+
* The lines of a header's block, in order: every line after it until a line that is no deeper, with the
|
|
11
|
+
* blank lines between them but not the blank lines after the block's last line.
|
|
12
|
+
*/
|
|
13
|
+
export declare function blockLines(lines: SketchLine[], header: SketchLine): SketchLine[];
|
|
14
|
+
/**
|
|
15
|
+
* Finds every tag in a line. A tag starts at the beginning of the text or after whitespace,
|
|
16
|
+
* so code such as `std::io` or `Vec::new()` stays plain text.
|
|
17
|
+
*/
|
|
18
|
+
export declare function scanTags(text: string, onWarning?: (message: string) => void): Tag[];
|
|
19
|
+
/** Parses text made only of tags, such as inline code `::read?:sys`. Returns undefined otherwise. */
|
|
20
|
+
export declare function parseTagsOnly(text: string): Tag[] | undefined;
|
|
21
|
+
/** Parses a `::src` note: `path:start-end`, `path:line`, `path`, or a bare line or range. */
|
|
22
|
+
export declare function parseLocation(text: string): SrcLocation | undefined;
|
|
23
|
+
export declare function formatLocation(loc: SrcLocation): string;
|
|
24
|
+
/**
|
|
25
|
+
* Parses the URL in a `::repo` note: `git+<remote>@<revision>`, `git+file://<path>@<revision>`, or any
|
|
26
|
+
* other URL, used as a base. Returns undefined when the note isn't a URL.
|
|
27
|
+
*/
|
|
28
|
+
export declare function parseRepo(text: string): Repo | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Names a repository by its host and path, as in `github.com/org/shop`, from a remote URL or the
|
|
31
|
+
* `git@host:path` form `git remote` prints. Two remotes with the same name are the same repository.
|
|
32
|
+
* Returns undefined for a local path or `file://` URL.
|
|
33
|
+
*/
|
|
34
|
+
export declare function repoId(remote: string): string | undefined;
|
|
35
|
+
/** Parses a block of the code view. */
|
|
36
|
+
export declare function parseCode(source: string, options?: ParseOptions): CodeSketch;
|