@driftsys/markspec 0.12.0 → 0.13.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/esm/ast/build.d.ts.map +1 -1
- package/esm/ast/build.js +19 -5
- package/esm/ast/equivalence.js +14 -2
- package/esm/ast/nodes.d.ts +15 -3
- package/esm/ast/nodes.d.ts.map +1 -1
- package/esm/compiler/inverses.d.ts.map +1 -1
- package/esm/compiler/inverses.js +18 -3
- package/esm/compiler/mod.d.ts +34 -1
- package/esm/compiler/mod.d.ts.map +1 -1
- package/esm/compiler/mod.js +112 -48
- package/esm/compiler/schema.d.ts +3 -2
- package/esm/compiler/schema.d.ts.map +1 -1
- package/esm/compiler/schema.js +6 -3
- package/esm/config/markspec.d.ts +2 -2
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +47 -5
- package/esm/criteria/scenarios.d.ts +55 -0
- package/esm/criteria/scenarios.d.ts.map +1 -0
- package/esm/criteria/scenarios.js +133 -0
- package/esm/discovery/mod.d.ts +20 -1
- package/esm/discovery/mod.d.ts.map +1 -1
- package/esm/discovery/mod.js +105 -17
- package/esm/discovery/projects.d.ts +6 -4
- package/esm/discovery/projects.d.ts.map +1 -1
- package/esm/discovery/projects.js +27 -17
- package/esm/formatter/entry_body.d.ts +13 -12
- package/esm/formatter/entry_body.d.ts.map +1 -1
- package/esm/formatter/entry_body.js +25 -17
- package/esm/formatter/feature_file.d.ts +40 -0
- package/esm/formatter/feature_file.d.ts.map +1 -0
- package/esm/formatter/feature_file.js +88 -0
- package/esm/formatter/md_equiv.d.ts +6 -5
- package/esm/formatter/md_equiv.d.ts.map +1 -1
- package/esm/formatter/md_equiv.js +6 -5
- package/esm/formatter/mod.d.ts +25 -3
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +267 -27
- package/esm/formatter/tab_markers.d.ts +15 -0
- package/esm/formatter/tab_markers.d.ts.map +1 -0
- package/esm/formatter/tab_markers.js +133 -0
- package/esm/gates/mod.d.ts +2 -2
- package/esm/gates/mod.d.ts.map +1 -1
- package/esm/gates/mod.js +18 -3
- package/esm/gherkin/load.d.ts +35 -0
- package/esm/gherkin/load.d.ts.map +1 -0
- package/esm/gherkin/load.js +39 -0
- package/esm/gherkin/parse.d.ts +11 -0
- package/esm/gherkin/parse.d.ts.map +1 -0
- package/esm/gherkin/parse.js +311 -0
- package/esm/gherkin/position.d.ts +23 -0
- package/esm/gherkin/position.d.ts.map +1 -0
- package/esm/gherkin/position.js +21 -0
- package/esm/gherkin/procedure.d.ts +76 -0
- package/esm/gherkin/procedure.d.ts.map +1 -0
- package/esm/gherkin/procedure.js +164 -0
- package/esm/gherkin/project.d.ts +35 -0
- package/esm/gherkin/project.d.ts.map +1 -0
- package/esm/gherkin/project.js +64 -0
- package/esm/gherkin/role.d.ts +23 -0
- package/esm/gherkin/role.d.ts.map +1 -0
- package/esm/gherkin/role.js +28 -0
- package/esm/gherkin/types.d.ts +118 -0
- package/esm/gherkin/types.d.ts.map +1 -0
- package/esm/gherkin/types.js +12 -0
- package/esm/lock/acquire_compile.d.ts +12 -4
- package/esm/lock/acquire_compile.d.ts.map +1 -1
- package/esm/lock/acquire_compile.js +15 -5
- package/esm/lock/canonical_edges.d.ts +6 -2
- package/esm/lock/canonical_edges.d.ts.map +1 -1
- package/esm/lock/canonical_edges.js +10 -3
- package/esm/lock/model.d.ts +5 -0
- package/esm/lock/model.d.ts.map +1 -1
- package/esm/lock/parser.d.ts.map +1 -1
- package/esm/lock/parser.js +2 -0
- package/esm/lock/resolve.d.ts +6 -2
- package/esm/lock/resolve.d.ts.map +1 -1
- package/esm/lock/resolve.js +36 -4
- package/esm/lock/serializer.d.ts.map +1 -1
- package/esm/lock/serializer.js +7 -1
- package/esm/lock/upstream_deps.js +1 -1
- package/esm/mod.d.ts +24 -6
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +19 -5
- package/esm/model/mod.d.ts +43 -2
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +1 -1
- package/esm/model/relations.d.ts +9 -0
- package/esm/model/relations.d.ts.map +1 -1
- package/esm/model/relations.js +16 -1
- package/esm/parser/attributes.d.ts +82 -3
- package/esm/parser/attributes.d.ts.map +1 -1
- package/esm/parser/attributes.js +199 -32
- package/esm/parser/body_tokens.d.ts +1 -1
- package/esm/parser/body_tokens.d.ts.map +1 -1
- package/esm/parser/body_tokens.js +49 -35
- package/esm/parser/feature_file.d.ts +116 -0
- package/esm/parser/feature_file.d.ts.map +1 -0
- package/esm/parser/feature_file.js +540 -0
- package/esm/parser/markdown.d.ts +7 -0
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +129 -40
- package/esm/parser/mod.d.ts +18 -0
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +51 -0
- package/esm/parser/translate.d.ts.map +1 -1
- package/esm/parser/translate.js +5 -0
- package/esm/refs/mod.d.ts +8 -3
- package/esm/refs/mod.d.ts.map +1 -1
- package/esm/refs/mod.js +20 -7
- package/esm/refs/split.d.ts +58 -0
- package/esm/refs/split.d.ts.map +1 -0
- package/esm/refs/split.js +137 -0
- package/esm/reporter/mod.d.ts +7 -0
- package/esm/reporter/mod.d.ts.map +1 -1
- package/esm/reporter/mod.js +113 -3
- package/esm/sync/mapping.d.ts +4 -3
- package/esm/sync/mapping.d.ts.map +1 -1
- package/esm/sync/mapping.js +52 -9
- package/esm/util/display_id.d.ts +20 -0
- package/esm/util/display_id.d.ts.map +1 -0
- package/esm/util/display_id.js +19 -0
- package/esm/validator/attributes.d.ts.map +1 -1
- package/esm/validator/attributes.js +4 -1
- package/esm/validator/block_role.d.ts +40 -0
- package/esm/validator/block_role.d.ts.map +1 -0
- package/esm/validator/block_role.js +109 -0
- package/esm/validator/feature_ac.d.ts.map +1 -1
- package/esm/validator/feature_ac.js +6 -1
- package/esm/validator/feature_parse.d.ts +35 -0
- package/esm/validator/feature_parse.d.ts.map +1 -0
- package/esm/validator/feature_parse.js +69 -0
- package/esm/validator/locators.d.ts +36 -0
- package/esm/validator/locators.d.ts.map +1 -0
- package/esm/validator/locators.js +184 -0
- package/esm/validator/mod.d.ts +10 -1
- package/esm/validator/mod.d.ts.map +1 -1
- package/esm/validator/mod.js +38 -14
- package/esm/validator/normalize.d.ts.map +1 -1
- package/esm/validator/normalize.js +8 -3
- package/esm/validator/per_type_attrs.d.ts +3 -3
- package/esm/validator/per_type_attrs.js +3 -3
- package/esm/validator/pipeline.d.ts +10 -16
- package/esm/validator/pipeline.d.ts.map +1 -1
- package/esm/validator/pipeline.js +37 -16
- package/esm/validator/procedure.d.ts +22 -0
- package/esm/validator/procedure.d.ts.map +1 -0
- package/esm/validator/procedure.js +58 -0
- package/esm/validator/trace_types.d.ts.map +1 -1
- package/esm/validator/trace_types.js +4 -3
- package/esm/validator/traceability.d.ts.map +1 -1
- package/esm/validator/traceability.js +4 -1
- package/esm/validator/type_resolution.d.ts +5 -3
- package/esm/validator/type_resolution.d.ts.map +1 -1
- package/esm/validator/type_resolution.js +14 -2
- package/esm/validator/types.d.ts +11 -0
- package/esm/validator/types.d.ts.map +1 -1
- package/esm/validator/types.js +26 -4
- package/esm/validator/uxil_family.d.ts +1 -1
- package/package.json +3 -1
- package/script/ast/build.d.ts.map +1 -1
- package/script/ast/build.js +19 -5
- package/script/ast/equivalence.js +14 -2
- package/script/ast/nodes.d.ts +15 -3
- package/script/ast/nodes.d.ts.map +1 -1
- package/script/compiler/inverses.d.ts.map +1 -1
- package/script/compiler/inverses.js +18 -3
- package/script/compiler/mod.d.ts +34 -1
- package/script/compiler/mod.d.ts.map +1 -1
- package/script/compiler/mod.js +110 -46
- package/script/compiler/schema.d.ts +3 -2
- package/script/compiler/schema.d.ts.map +1 -1
- package/script/compiler/schema.js +6 -3
- package/script/config/markspec.d.ts +2 -2
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +47 -5
- package/script/criteria/scenarios.d.ts +55 -0
- package/script/criteria/scenarios.d.ts.map +1 -0
- package/script/criteria/scenarios.js +139 -0
- package/script/discovery/mod.d.ts +20 -1
- package/script/discovery/mod.d.ts.map +1 -1
- package/script/discovery/mod.js +106 -17
- package/script/discovery/projects.d.ts +6 -4
- package/script/discovery/projects.d.ts.map +1 -1
- package/script/discovery/projects.js +27 -17
- package/script/formatter/entry_body.d.ts +13 -12
- package/script/formatter/entry_body.d.ts.map +1 -1
- package/script/formatter/entry_body.js +25 -17
- package/script/formatter/feature_file.d.ts +40 -0
- package/script/formatter/feature_file.d.ts.map +1 -0
- package/script/formatter/feature_file.js +92 -0
- package/script/formatter/md_equiv.d.ts +6 -5
- package/script/formatter/md_equiv.d.ts.map +1 -1
- package/script/formatter/md_equiv.js +6 -5
- package/script/formatter/mod.d.ts +25 -3
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +266 -26
- package/script/formatter/tab_markers.d.ts +15 -0
- package/script/formatter/tab_markers.d.ts.map +1 -0
- package/script/formatter/tab_markers.js +141 -0
- package/script/gates/mod.d.ts +2 -2
- package/script/gates/mod.d.ts.map +1 -1
- package/script/gates/mod.js +18 -3
- package/script/gherkin/load.d.ts +35 -0
- package/script/gherkin/load.d.ts.map +1 -0
- package/script/gherkin/load.js +76 -0
- package/script/gherkin/parse.d.ts +11 -0
- package/script/gherkin/parse.d.ts.map +1 -0
- package/script/gherkin/parse.js +314 -0
- package/script/gherkin/position.d.ts +23 -0
- package/script/gherkin/position.d.ts.map +1 -0
- package/script/gherkin/position.js +24 -0
- package/script/gherkin/procedure.d.ts +76 -0
- package/script/gherkin/procedure.d.ts.map +1 -0
- package/script/gherkin/procedure.js +169 -0
- package/script/gherkin/project.d.ts +35 -0
- package/script/gherkin/project.d.ts.map +1 -0
- package/script/gherkin/project.js +67 -0
- package/script/gherkin/role.d.ts +23 -0
- package/script/gherkin/role.d.ts.map +1 -0
- package/script/gherkin/role.js +31 -0
- package/script/gherkin/types.d.ts +118 -0
- package/script/gherkin/types.d.ts.map +1 -0
- package/script/gherkin/types.js +13 -0
- package/script/lock/acquire_compile.d.ts +12 -4
- package/script/lock/acquire_compile.d.ts.map +1 -1
- package/script/lock/acquire_compile.js +15 -5
- package/script/lock/canonical_edges.d.ts +6 -2
- package/script/lock/canonical_edges.d.ts.map +1 -1
- package/script/lock/canonical_edges.js +10 -3
- package/script/lock/model.d.ts +5 -0
- package/script/lock/model.d.ts.map +1 -1
- package/script/lock/parser.d.ts.map +1 -1
- package/script/lock/parser.js +2 -0
- package/script/lock/resolve.d.ts +6 -2
- package/script/lock/resolve.d.ts.map +1 -1
- package/script/lock/resolve.js +36 -4
- package/script/lock/serializer.d.ts.map +1 -1
- package/script/lock/serializer.js +7 -1
- package/script/lock/upstream_deps.js +1 -1
- package/script/mod.d.ts +24 -6
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +48 -6
- package/script/model/mod.d.ts +43 -2
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +2 -1
- package/script/model/relations.d.ts +9 -0
- package/script/model/relations.d.ts.map +1 -1
- package/script/model/relations.js +17 -1
- package/script/parser/attributes.d.ts +82 -3
- package/script/parser/attributes.d.ts.map +1 -1
- package/script/parser/attributes.js +205 -33
- package/script/parser/body_tokens.d.ts +1 -1
- package/script/parser/body_tokens.d.ts.map +1 -1
- package/script/parser/body_tokens.js +49 -35
- package/script/parser/feature_file.d.ts +116 -0
- package/script/parser/feature_file.d.ts.map +1 -0
- package/script/parser/feature_file.js +548 -0
- package/script/parser/markdown.d.ts +7 -0
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +128 -39
- package/script/parser/mod.d.ts +18 -0
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +52 -1
- package/script/parser/translate.d.ts.map +1 -1
- package/script/parser/translate.js +5 -0
- package/script/refs/mod.d.ts +8 -3
- package/script/refs/mod.d.ts.map +1 -1
- package/script/refs/mod.js +20 -7
- package/script/refs/split.d.ts +58 -0
- package/script/refs/split.d.ts.map +1 -0
- package/script/refs/split.js +145 -0
- package/script/reporter/mod.d.ts +7 -0
- package/script/reporter/mod.d.ts.map +1 -1
- package/script/reporter/mod.js +113 -3
- package/script/sync/mapping.d.ts +4 -3
- package/script/sync/mapping.d.ts.map +1 -1
- package/script/sync/mapping.js +52 -9
- package/script/util/display_id.d.ts +20 -0
- package/script/util/display_id.d.ts.map +1 -0
- package/script/util/display_id.js +22 -0
- package/script/validator/attributes.d.ts.map +1 -1
- package/script/validator/attributes.js +4 -1
- package/script/validator/block_role.d.ts +40 -0
- package/script/validator/block_role.d.ts.map +1 -0
- package/script/validator/block_role.js +112 -0
- package/script/validator/feature_ac.d.ts.map +1 -1
- package/script/validator/feature_ac.js +6 -1
- package/script/validator/feature_parse.d.ts +35 -0
- package/script/validator/feature_parse.d.ts.map +1 -0
- package/script/validator/feature_parse.js +73 -0
- package/script/validator/locators.d.ts +36 -0
- package/script/validator/locators.d.ts.map +1 -0
- package/script/validator/locators.js +188 -0
- package/script/validator/mod.d.ts +10 -1
- package/script/validator/mod.d.ts.map +1 -1
- package/script/validator/mod.js +38 -14
- package/script/validator/normalize.d.ts.map +1 -1
- package/script/validator/normalize.js +8 -3
- package/script/validator/per_type_attrs.d.ts +3 -3
- package/script/validator/per_type_attrs.js +3 -3
- package/script/validator/pipeline.d.ts +10 -16
- package/script/validator/pipeline.d.ts.map +1 -1
- package/script/validator/pipeline.js +36 -16
- package/script/validator/procedure.d.ts +22 -0
- package/script/validator/procedure.d.ts.map +1 -0
- package/script/validator/procedure.js +61 -0
- package/script/validator/trace_types.d.ts.map +1 -1
- package/script/validator/trace_types.js +4 -3
- package/script/validator/traceability.d.ts.map +1 -1
- package/script/validator/traceability.js +4 -1
- package/script/validator/type_resolution.d.ts +5 -3
- package/script/validator/type_resolution.d.ts.map +1 -1
- package/script/validator/type_resolution.js +14 -2
- package/script/validator/types.d.ts +11 -0
- package/script/validator/types.d.ts.map +1 -1
- package/script/validator/types.js +27 -4
- package/script/validator/uxil_family.d.ts +1 -1
|
@@ -81,17 +81,21 @@ function bodySpan(lines, entry) {
|
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* 0-based content column of the list item whose marker starts at `marker`
|
|
84
|
-
* on `line`: the marker column, plus 1 for the bullet, plus the
|
|
85
|
-
* after it.
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* start with a bullet and a space at `marker`, the marker column plus 2 is
|
|
90
|
-
* used as a fallback.
|
|
84
|
+
* on `line`: the marker column, plus 1 for the bullet, plus the whitespace
|
|
85
|
+
* after it. Tabs advance to the next four-column CommonMark tab stop.
|
|
86
|
+
* So `- [ID]` gives 2, `- [ID]` gives 4, and `-\t[ID]` gives 4 at
|
|
87
|
+
* column zero. Ordered lists never hold entries. When there is no bullet
|
|
88
|
+
* followed by whitespace at `marker`, use the marker column plus 2.
|
|
91
89
|
*/
|
|
92
90
|
export function contentColumn(line, marker) {
|
|
93
|
-
const m = /^[-*+]( +)/.exec(line.slice(marker));
|
|
94
|
-
|
|
91
|
+
const m = /^[-*+]([ \t]+)/.exec(line.slice(marker));
|
|
92
|
+
if (!m)
|
|
93
|
+
return marker + 2;
|
|
94
|
+
let column = marker + 1;
|
|
95
|
+
for (const character of m[1]) {
|
|
96
|
+
column += character === "\t" ? 4 - column % 4 : 1;
|
|
97
|
+
}
|
|
98
|
+
return column;
|
|
95
99
|
}
|
|
96
100
|
/** Dedented span lines, trailing whitespace removed. */
|
|
97
101
|
function spanText(lines, span) {
|
|
@@ -167,11 +171,14 @@ function dedent(line, indent) {
|
|
|
167
171
|
* before or after the edit. So the edit is refused when an `MSL-P020`,
|
|
168
172
|
* `MSL-P021` or `MSL-P022` names the entry (the message starts with
|
|
169
173
|
* `<displayId>:`). This is broader than that case: `MSL-P020` also fires
|
|
170
|
-
* when a body
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
174
|
+
* when a body `Id:` or trace-relation line has other content after it,
|
|
175
|
+
* when an `Id:` run sits directly under prose (warning), and when a
|
|
176
|
+
* trailing trace-relation line is body prose (warning), so such an entry
|
|
177
|
+
* is refused too. An entry whose trailer-looking lines the parser reads as
|
|
178
|
+
* body without a diagnostic (for example `Note:` lines, or `Status:`
|
|
179
|
+
* directly under prose) is edited as the parser sees it: those lines are
|
|
180
|
+
* body. A final paragraph of only core keys after a blank line, such as a
|
|
181
|
+
* lone `Rationale:` line, is the trailer, not body.
|
|
175
182
|
*/
|
|
176
183
|
export async function replaceEntryBody(text, file, displayId, body) {
|
|
177
184
|
const before = await locate(text, file, displayId);
|
|
@@ -268,9 +275,10 @@ function sameEntries(before, after, target, targetAfter) {
|
|
|
268
275
|
* blank line between them, raises no diagnostic; the parser keeps it as
|
|
269
276
|
* body text and adds no entry, so the edit is accepted.
|
|
270
277
|
*
|
|
271
|
-
* Known limit: the
|
|
272
|
-
*
|
|
273
|
-
*
|
|
278
|
+
* Known limit: the body scan raises at most one MSL-P020 per entry (the
|
|
279
|
+
* under-prose warning can add a second one), so when the target body
|
|
280
|
+
* already has a trailer-like line, a proposal that adds more such lines
|
|
281
|
+
* raises no new MSL-P020 and is accepted. The lines stay
|
|
274
282
|
* body text; no trailer or entry changes.
|
|
275
283
|
*/
|
|
276
284
|
function addsParseDiagnostic(before, after) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/formatter/feature_file
|
|
3
|
+
*
|
|
4
|
+
* Write-back for `.feature` files (epic #915, Case B). The only change
|
|
5
|
+
* `fmt` makes is to insert a missing `# Id: <ULID>` line into the header
|
|
6
|
+
* comment of a headed entry. Gherkin text, other comments and line endings
|
|
7
|
+
* stay as they are. The Markdown entry formatter and the ADR-029 prose pass
|
|
8
|
+
* never run on `.feature` text.
|
|
9
|
+
*/
|
|
10
|
+
import type { Entry } from "../model/mod.js";
|
|
11
|
+
/** Result of {@linkcode formatFeatureFile}. */
|
|
12
|
+
export interface FeatureFormatResult {
|
|
13
|
+
readonly output: string;
|
|
14
|
+
readonly changed: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Insert a missing `# Id: <ULID>` line into the header of each entry of a
|
|
18
|
+
* `.feature` file.
|
|
19
|
+
*
|
|
20
|
+
* The line goes before the first trailer line, with that line's comment
|
|
21
|
+
* prefix, so it matches the header's indentation and trailer spacing. A
|
|
22
|
+
* header without a trailer gets a `#` line (unless its last line is already
|
|
23
|
+
* an empty comment) and then the Id line, at the end of the header. An entry
|
|
24
|
+
* that has an Id, and every other part of the file, is left unchanged.
|
|
25
|
+
*
|
|
26
|
+
* @param text - The file text (LF or CRLF).
|
|
27
|
+
* @param entries - The entries parsed from `text`.
|
|
28
|
+
* @param generateUlid - ULID generator.
|
|
29
|
+
*/
|
|
30
|
+
export declare function formatFeatureFile(text: string, entries: readonly Entry[], generateUlid?: () => string): FeatureFormatResult;
|
|
31
|
+
/**
|
|
32
|
+
* Parse a `.feature` file and stamp the missing Ids of its entries. A file
|
|
33
|
+
* that does not parse has no entries, so it comes back unchanged.
|
|
34
|
+
*
|
|
35
|
+
* @param text - The file text.
|
|
36
|
+
* @param file - File path, used for parsing and diagnostics.
|
|
37
|
+
* @param generateUlid - ULID generator.
|
|
38
|
+
*/
|
|
39
|
+
export declare function formatFeatureText(text: string, file: string, generateUlid?: () => string): Promise<FeatureFormatResult>;
|
|
40
|
+
//# sourceMappingURL=feature_file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature_file.d.ts","sourceRoot":"","sources":["../../src/formatter/feature_file.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAY7C,+CAA+C;AAC/C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAOD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,YAAY,GAAE,MAAM,MAAoB,GACvC,mBAAmB,CA0CrB;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,YAAY,GAAE,MAAM,MAAoB,GACvC,OAAO,CAAC,mBAAmB,CAAC,CAG9B"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/formatter/feature_file
|
|
3
|
+
*
|
|
4
|
+
* Write-back for `.feature` files (epic #915, Case B). The only change
|
|
5
|
+
* `fmt` makes is to insert a missing `# Id: <ULID>` line into the header
|
|
6
|
+
* comment of a headed entry. Gherkin text, other comments and line endings
|
|
7
|
+
* stay as they are. The Markdown entry formatter and the ADR-029 prose pass
|
|
8
|
+
* never run on `.feature` text.
|
|
9
|
+
*/
|
|
10
|
+
import { ulid as defaultUlid } from "@std/ulid";
|
|
11
|
+
import { parseFile } from "../parser/mod.js";
|
|
12
|
+
import { featureHeaderRunEnd } from "../parser/feature_file.js";
|
|
13
|
+
import { applyLineEnding, detectLineEnding, normalizeLineEndings, } from "../util/line_endings.js";
|
|
14
|
+
/** Leading whitespace, `#`, and the spaces after it. */
|
|
15
|
+
const COMMENT_PREFIX_RE = /^(\s*#[ \t]*)/;
|
|
16
|
+
/** `true` when `line` is a comment line. */
|
|
17
|
+
function isComment(line) {
|
|
18
|
+
return line !== undefined && line.trimStart().startsWith("#");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Insert a missing `# Id: <ULID>` line into the header of each entry of a
|
|
22
|
+
* `.feature` file.
|
|
23
|
+
*
|
|
24
|
+
* The line goes before the first trailer line, with that line's comment
|
|
25
|
+
* prefix, so it matches the header's indentation and trailer spacing. A
|
|
26
|
+
* header without a trailer gets a `#` line (unless its last line is already
|
|
27
|
+
* an empty comment) and then the Id line, at the end of the header. An entry
|
|
28
|
+
* that has an Id, and every other part of the file, is left unchanged.
|
|
29
|
+
*
|
|
30
|
+
* @param text - The file text (LF or CRLF).
|
|
31
|
+
* @param entries - The entries parsed from `text`.
|
|
32
|
+
* @param generateUlid - ULID generator.
|
|
33
|
+
*/
|
|
34
|
+
export function formatFeatureFile(text, entries, generateUlid = defaultUlid) {
|
|
35
|
+
const ending = detectLineEnding(text);
|
|
36
|
+
const lines = normalizeLineEndings(text).split("\n");
|
|
37
|
+
const missing = entries
|
|
38
|
+
.filter((e) => e.source.kind === "feature-file" && e.id === undefined &&
|
|
39
|
+
e.shape === "Authored")
|
|
40
|
+
.sort((a, b) => b.location.line - a.location.line);
|
|
41
|
+
if (missing.length === 0)
|
|
42
|
+
return { output: text, changed: false };
|
|
43
|
+
let changed = false;
|
|
44
|
+
for (const entry of missing) {
|
|
45
|
+
const titleIdx = entry.location.line - 1;
|
|
46
|
+
if (!isComment(lines[titleIdx]))
|
|
47
|
+
continue;
|
|
48
|
+
// End of the header run: consecutive comment lines, up to the next
|
|
49
|
+
// header start or a `# language:` line.
|
|
50
|
+
const endIdx = featureHeaderRunEnd(lines, titleIdx) - 1;
|
|
51
|
+
const firstTrailer = entry.attributeLines?.[0];
|
|
52
|
+
const trailerIdx = firstTrailer === undefined
|
|
53
|
+
? undefined
|
|
54
|
+
: firstTrailer - 1;
|
|
55
|
+
if (trailerIdx !== undefined && trailerIdx > titleIdx &&
|
|
56
|
+
trailerIdx <= endIdx) {
|
|
57
|
+
const prefix = COMMENT_PREFIX_RE.exec(lines[trailerIdx])[1];
|
|
58
|
+
lines.splice(trailerIdx, 0, `${prefix}Id: ${generateUlid()}`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const indent = /^\s*/.exec(lines[titleIdx])[0];
|
|
62
|
+
const added = [];
|
|
63
|
+
if (lines[endIdx].trim() !== "#")
|
|
64
|
+
added.push(`${indent}#`);
|
|
65
|
+
added.push(`${indent}# Id: ${generateUlid()}`);
|
|
66
|
+
lines.splice(endIdx + 1, 0, ...added);
|
|
67
|
+
}
|
|
68
|
+
changed = true;
|
|
69
|
+
}
|
|
70
|
+
if (!changed)
|
|
71
|
+
return { output: text, changed: false };
|
|
72
|
+
return {
|
|
73
|
+
output: applyLineEnding(lines.join("\n"), ending),
|
|
74
|
+
changed: true,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Parse a `.feature` file and stamp the missing Ids of its entries. A file
|
|
79
|
+
* that does not parse has no entries, so it comes back unchanged.
|
|
80
|
+
*
|
|
81
|
+
* @param text - The file text.
|
|
82
|
+
* @param file - File path, used for parsing and diagnostics.
|
|
83
|
+
* @param generateUlid - ULID generator.
|
|
84
|
+
*/
|
|
85
|
+
export async function formatFeatureText(text, file, generateUlid = defaultUlid) {
|
|
86
|
+
const { entries } = await parseFile(text, { file });
|
|
87
|
+
return formatFeatureFile(text, entries, generateUlid);
|
|
88
|
+
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* @module formatter/md_equiv
|
|
3
3
|
*
|
|
4
4
|
* CommonMark-semantic Markdown equivalence — the gate for the ADR-029
|
|
5
|
-
* dprint pass. Two fragments are equivalent
|
|
6
|
-
* same mdast structure after eliding source `position`s
|
|
5
|
+
* dprint pass and entry tab-marker normalization. Two fragments are equivalent
|
|
6
|
+
* when they parse to the same mdast structure after eliding source `position`s
|
|
7
|
+
* and collapsing
|
|
7
8
|
* ASCII whitespace runs inside `text` node values. Only ASCII
|
|
8
9
|
* whitespace is collapsed — NBSP (U+00A0) and Unicode spaces are
|
|
9
10
|
* content, not wrap artifacts, and must not compare equal to a plain
|
|
@@ -15,9 +16,9 @@
|
|
|
15
16
|
* and definition `url`s stay byte-exact.
|
|
16
17
|
*
|
|
17
18
|
* DELIBERATELY weaker than ADR-015's `astEquivalent` (byte-verbatim on
|
|
18
|
-
* inline markup). Used
|
|
19
|
-
* ADR-015 relation still guards §5.2 body emission (MSL-F900) and must
|
|
20
|
-
*
|
|
19
|
+
* inline markup). Used to accept/reject dprint output and tab-marker rewrites.
|
|
20
|
+
* The ADR-015 relation still guards §5.2 body emission (MSL-F900) and must not
|
|
21
|
+
* be modified.
|
|
21
22
|
*/
|
|
22
23
|
/** True when `a` and `b` are the same Markdown, modulo presentation. */
|
|
23
24
|
export declare function markdownSemanticallyEquivalent(a: string, b: string): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"md_equiv.d.ts","sourceRoot":"","sources":["../../src/formatter/md_equiv.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"md_equiv.d.ts","sourceRoot":"","sources":["../../src/formatter/md_equiv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAQH,wEAAwE;AACxE,wBAAgB,8BAA8B,CAC5C,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,OAAO,CAMT"}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* @module formatter/md_equiv
|
|
3
3
|
*
|
|
4
4
|
* CommonMark-semantic Markdown equivalence — the gate for the ADR-029
|
|
5
|
-
* dprint pass. Two fragments are equivalent
|
|
6
|
-
* same mdast structure after eliding source `position`s
|
|
5
|
+
* dprint pass and entry tab-marker normalization. Two fragments are equivalent
|
|
6
|
+
* when they parse to the same mdast structure after eliding source `position`s
|
|
7
|
+
* and collapsing
|
|
7
8
|
* ASCII whitespace runs inside `text` node values. Only ASCII
|
|
8
9
|
* whitespace is collapsed — NBSP (U+00A0) and Unicode spaces are
|
|
9
10
|
* content, not wrap artifacts, and must not compare equal to a plain
|
|
@@ -15,9 +16,9 @@
|
|
|
15
16
|
* and definition `url`s stay byte-exact.
|
|
16
17
|
*
|
|
17
18
|
* DELIBERATELY weaker than ADR-015's `astEquivalent` (byte-verbatim on
|
|
18
|
-
* inline markup). Used
|
|
19
|
-
* ADR-015 relation still guards §5.2 body emission (MSL-F900) and must
|
|
20
|
-
*
|
|
19
|
+
* inline markup). Used to accept/reject dprint output and tab-marker rewrites.
|
|
20
|
+
* The ADR-015 relation still guards §5.2 body emission (MSL-F900) and must not
|
|
21
|
+
* be modified.
|
|
21
22
|
*/
|
|
22
23
|
import { unified } from "unified";
|
|
23
24
|
import remarkParse from "remark-parse";
|
package/esm/formatter/mod.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* and requirement block insertion.
|
|
7
7
|
*/
|
|
8
8
|
import type { Attribute, Diagnostic } from "../model/mod.js";
|
|
9
|
+
import { type EntryExtent } from "./prose.js";
|
|
9
10
|
import { type ProseFormatter } from "./dprint.js";
|
|
10
11
|
/**
|
|
11
12
|
* Decide whether the EARS keyword at `offset` in `line` is at sentence
|
|
@@ -76,6 +77,8 @@ export interface FormatResult {
|
|
|
76
77
|
readonly diagnostics: readonly Diagnostic[];
|
|
77
78
|
/** Whether any changes were made. */
|
|
78
79
|
readonly changed: boolean;
|
|
80
|
+
/** Output line spans (0-based, end exclusive) kept unchanged after refusal. */
|
|
81
|
+
readonly preservedRanges?: readonly EntryExtent[];
|
|
79
82
|
}
|
|
80
83
|
/**
|
|
81
84
|
* Format a Markdown string — normalize attribute blocks,
|
|
@@ -90,7 +93,9 @@ export declare function format(markdown: string, options?: FormatOptions): Forma
|
|
|
90
93
|
* Expand CSV values on repeatable-type attributes into one entry per value
|
|
91
94
|
* per ADR-002 §2.6. `id-list` / `tag-list` / `external-id` accept CSV input
|
|
92
95
|
* but must round-trip as multi-line output; `citation` is left alone
|
|
93
|
-
* because locators may contain commas.
|
|
96
|
+
* because locators may contain commas. `id-list` values split with
|
|
97
|
+
* {@linkcode splitTraceValues}, so a comma inside a scenario locator does
|
|
98
|
+
* not split.
|
|
94
99
|
*/
|
|
95
100
|
export declare function expandCsvValues(attrs: Attribute[]): Attribute[];
|
|
96
101
|
/**
|
|
@@ -141,9 +146,26 @@ export declare function findItemEnd(lines: readonly string[], startIdx: number,
|
|
|
141
146
|
* for an entry starting at the given line.
|
|
142
147
|
*
|
|
143
148
|
* Scans forward from the entry start to find the list item boundary,
|
|
144
|
-
* then
|
|
149
|
+
* then passes the entry content below the last preserved range, with the
|
|
150
|
+
* list-item indent removed, to the parser's {@linkcode findTrailerStart}.
|
|
151
|
+
* The formatter and the parser therefore agree on which lines are the
|
|
152
|
+
* trailer, so `markspec fmt` never rewrites a line that the parser read as
|
|
153
|
+
* body, and never drops an attribute line that the parser read (#916).
|
|
154
|
+
* The LSP MSL-P023 quick fix uses it too.
|
|
155
|
+
*
|
|
156
|
+
* @param lines - Raw lines of the whole file.
|
|
157
|
+
* @param entryStartLine - 1-based line of the entry's title (`- [ID] ...`).
|
|
158
|
+
* @param indent - Content column of the list item: the 0-based column of
|
|
159
|
+
* the `[` that opens the display ID.
|
|
160
|
+
* @param itemEndFloor - Pass the parser's `Entry.endLine` (0 when unknown):
|
|
161
|
+
* the item end scan starts no earlier than this line index, so a lazy
|
|
162
|
+
* continuation line does not end the item early (see `findItemEnd`).
|
|
163
|
+
* @param preservedRanges - Ranges inside the entry that are kept verbatim
|
|
164
|
+
* (nested entries); the trailer is searched below the last one.
|
|
165
|
+
* @returns The 0-based, half-open line range `[start, end)` of the trailer
|
|
166
|
+
* over `lines`, or `undefined` when the entry has no trailer.
|
|
145
167
|
*/
|
|
146
|
-
export declare function findAttributeBlockRange(lines: readonly string[], entryStartLine: number, indent: number, itemEndFloor?: number): {
|
|
168
|
+
export declare function findAttributeBlockRange(lines: readonly string[], entryStartLine: number, indent: number, itemEndFloor?: number, preservedRanges?: readonly EntryExtent[]): {
|
|
147
169
|
start: number;
|
|
148
170
|
end: number;
|
|
149
171
|
} | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/formatter/mod.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAGX,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/formatter/mod.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAGX,MAAM,iBAAiB,CAAC;AA8BzB,OAAO,EAAE,KAAK,WAAW,EAAuB,MAAM,YAAY,CAAC;AAOnE,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,aAAa,CAAC;AAGrB;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE/D;AA4WD,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,MAAM,CAAC;IACrC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IAC9B;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,cAAc,CAAC;CAC/C;AAED,oCAAoC;AACpC,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,+EAA+E;IAC/E,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;CACnD;AA2ID;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,aAAa,GACtB,YAAY,CAuBd;AA2aD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAuB/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,SAAS,EAAE,GACtB,SAAS,EAAE,CA2Bb;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,SAAS,EAAE,EACvB,MAAM,EAAE,MAAM,GACb,MAAM,CAKR;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,YAAY,SAAI,GACf,MAAM,CAkBR;AA0FD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,YAAY,SAAI,EAChB,eAAe,GAAE,SAAS,WAAW,EAAO,GAC3C;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CA8B5C"}
|