@driftsys/markspec 0.12.1 → 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/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/formatter/entry_body.d.ts +8 -5
- package/esm/formatter/entry_body.d.ts.map +1 -1
- package/esm/formatter/entry_body.js +12 -8
- 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/mod.d.ts +21 -2
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +64 -22
- package/esm/gates/mod.d.ts +2 -2
- package/esm/gates/mod.d.ts.map +1 -1
- package/esm/gates/mod.js +17 -2
- 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/mod.d.ts +23 -6
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +18 -5
- package/esm/model/mod.d.ts +42 -1
- 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 +2 -1
- package/esm/refs/mod.d.ts.map +1 -1
- package/esm/refs/mod.js +12 -4
- 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/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 +4 -12
- package/esm/validator/pipeline.d.ts.map +1 -1
- package/esm/validator/pipeline.js +24 -5
- 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/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/formatter/entry_body.d.ts +8 -5
- package/script/formatter/entry_body.d.ts.map +1 -1
- package/script/formatter/entry_body.js +12 -8
- 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/mod.d.ts +21 -2
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +63 -21
- package/script/gates/mod.d.ts +2 -2
- package/script/gates/mod.d.ts.map +1 -1
- package/script/gates/mod.js +17 -2
- 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/mod.d.ts +23 -6
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +45 -6
- package/script/model/mod.d.ts +42 -1
- 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 +2 -1
- package/script/refs/mod.d.ts.map +1 -1
- package/script/refs/mod.js +12 -4
- 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/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 +4 -12
- package/script/validator/pipeline.d.ts.map +1 -1
- package/script/validator/pipeline.js +23 -5
- 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
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module criteria/scenarios
|
|
3
|
+
*
|
|
4
|
+
* Scenario index. Builds the `Entry.criteria` subset
|
|
5
|
+
* `{ form: "scenario", name, addressable, location }` from the fenced
|
|
6
|
+
* `gherkin` / `feature` blocks of an entry body.
|
|
7
|
+
*
|
|
8
|
+
* Source of the scenario names, per block:
|
|
9
|
+
*
|
|
10
|
+
* - the Gherkin AST (`FeatureNode.feature`) when it is present, in any spoken
|
|
11
|
+
* language;
|
|
12
|
+
* - otherwise the line scanner ({@linkcode scanScenarioNames}, English
|
|
13
|
+
* keywords only), when the block did not parse (`parseError`) or when the
|
|
14
|
+
* parser was not loaded at parse time.
|
|
15
|
+
*
|
|
16
|
+
* `parseFile` loads the parser before it parses a text with a gherkin fence,
|
|
17
|
+
* so every entry that reaches the compiler, the validator and the reporter
|
|
18
|
+
* carries the AST or a `parseError`, unless the parser import failed. The
|
|
19
|
+
* scanner for the not-loaded case covers that failure and code that builds
|
|
20
|
+
* entries with the synchronous `parse()` before any load.
|
|
21
|
+
*/
|
|
22
|
+
import { descendantsOf } from "../model/mod.js";
|
|
23
|
+
import { extendsTransitively } from "../profile/discipline_mode.js";
|
|
24
|
+
import { normalizeLocator } from "../refs/split.js";
|
|
25
|
+
import { featureFileLine } from "../gherkin/position.js";
|
|
26
|
+
/** Matches a scenario-like keyword line. Group 2 is the raw name. */
|
|
27
|
+
const SCENARIO_RE = /^\s*(Scenario Outline|Scenario Template|Scenario|Example):\s*(.*)$/;
|
|
28
|
+
/**
|
|
29
|
+
* Collect the scenario names of one Gherkin source text, in order.
|
|
30
|
+
* `line` is the 0-based line of the keyword within `source`. Lines between
|
|
31
|
+
* doc-string delimiters (`"""` or three backticks) are skipped. `Background`
|
|
32
|
+
* and `Rule` are not scenarios. Names are trimmed but not otherwise
|
|
33
|
+
* normalized.
|
|
34
|
+
*/
|
|
35
|
+
export function scanScenarioNames(source) {
|
|
36
|
+
const found = [];
|
|
37
|
+
// The delimiter that opened the current doc string, if any. Only the same
|
|
38
|
+
// delimiter closes it.
|
|
39
|
+
let openDelimiter;
|
|
40
|
+
source.split(/\r?\n/).forEach((text, line) => {
|
|
41
|
+
const trimmed = text.trim();
|
|
42
|
+
const delimiter = trimmed.startsWith('"""')
|
|
43
|
+
? '"""'
|
|
44
|
+
: trimmed.startsWith("```")
|
|
45
|
+
? "```"
|
|
46
|
+
: undefined;
|
|
47
|
+
if (delimiter !== undefined) {
|
|
48
|
+
if (openDelimiter === undefined)
|
|
49
|
+
openDelimiter = delimiter;
|
|
50
|
+
else if (openDelimiter === delimiter)
|
|
51
|
+
openDelimiter = undefined;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (openDelimiter !== undefined)
|
|
55
|
+
return;
|
|
56
|
+
const match = SCENARIO_RE.exec(text);
|
|
57
|
+
if (match)
|
|
58
|
+
found.push({ name: match[2].trim(), line });
|
|
59
|
+
});
|
|
60
|
+
return found;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Build the criteria of an entry from its feature blocks, in source order.
|
|
64
|
+
* Only top-level fenced blocks of the body are indexed: a fence nested in a
|
|
65
|
+
* list item or another container yields no criteria.
|
|
66
|
+
* A block with an AST contributes the AST's scenarios; see the module comment
|
|
67
|
+
* for the fallback. Names are normalized with {@linkcode normalizeLocator}. The blocks of one
|
|
68
|
+
* entry form one scope: a normalized name that occurs more than once, and an
|
|
69
|
+
* empty name, are not addressable. `location.line` is the file-relative line
|
|
70
|
+
* of the keyword; `location.column` is always 1.
|
|
71
|
+
*/
|
|
72
|
+
export function buildCriteria(entry) {
|
|
73
|
+
const bodyStart = entry.bodyStartLine ?? (entry.location.line + 1);
|
|
74
|
+
const raw = [];
|
|
75
|
+
for (const block of entry.bodyAst ?? []) {
|
|
76
|
+
if (!isFeature(block))
|
|
77
|
+
continue;
|
|
78
|
+
if (block.feature !== undefined) {
|
|
79
|
+
for (const scenario of block.feature.scenarios) {
|
|
80
|
+
raw.push({
|
|
81
|
+
name: normalizeLocator(scenario.name),
|
|
82
|
+
line: featureFileLine(entry, block, scenario.range.start.line),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
// Block did not parse, or the parser was not loaded: scan it. Body-
|
|
88
|
+
// relative range line 1 is `bodyStart`; the block's first source line
|
|
89
|
+
// follows the opening fence line.
|
|
90
|
+
const firstSourceLine = bodyStart + block.range.start.line;
|
|
91
|
+
for (const { name, line } of scanScenarioNames(block.source)) {
|
|
92
|
+
raw.push({ name: normalizeLocator(name), line: firstSourceLine + line });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const counts = new Map();
|
|
96
|
+
for (const { name } of raw)
|
|
97
|
+
counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
98
|
+
return raw.map(({ name, line }) => ({
|
|
99
|
+
form: "scenario",
|
|
100
|
+
name,
|
|
101
|
+
addressable: name !== "" && counts.get(name) === 1,
|
|
102
|
+
location: { file: entry.location.file, line, column: 1 },
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
/** Core types whose descendants carry criteria. */
|
|
106
|
+
const CRITERIA_BEARING_TYPES = ["Requirement", "Contract"];
|
|
107
|
+
/** `true` when `entry`'s type resolves to core Requirement or Contract —
|
|
108
|
+
* the entries that carry criteria (epic #915, decision 3). Uses the
|
|
109
|
+
* profile extends chain when a profile is loaded, else the core hierarchy.
|
|
110
|
+
* An entry without a resolved type carries no criteria. */
|
|
111
|
+
export function isCriteriaBearing(entry, profile) {
|
|
112
|
+
const type = entry.type;
|
|
113
|
+
if (type === undefined)
|
|
114
|
+
return false;
|
|
115
|
+
return CRITERIA_BEARING_TYPES.some((core) => profile
|
|
116
|
+
? extendsTransitively(type, core, profile)
|
|
117
|
+
: descendantsOf(core).has(type));
|
|
118
|
+
}
|
|
119
|
+
function isFeature(block) {
|
|
120
|
+
return block.kind === "feature";
|
|
121
|
+
}
|
|
122
|
+
/** `true` when `entry`'s type is, or extends, the core `Test` type — the
|
|
123
|
+
* entries whose `Verifies` links count for criterion coverage (epic #915,
|
|
124
|
+
* decision 2). Uses the profile extends chain when a profile is loaded,
|
|
125
|
+
* else the core hierarchy. */
|
|
126
|
+
export function isTestEntry(entry, profile) {
|
|
127
|
+
const type = entry.type;
|
|
128
|
+
if (type === undefined)
|
|
129
|
+
return false;
|
|
130
|
+
return profile
|
|
131
|
+
? extendsTransitively(type, "Test", profile)
|
|
132
|
+
: descendantsOf("Test").has(type);
|
|
133
|
+
}
|
package/esm/discovery/mod.d.ts
CHANGED
|
@@ -26,7 +26,13 @@ export { type GitignoreRule, isIgnored, parseGitignore } from "./gitignore.js";
|
|
|
26
26
|
export declare const SOURCE_EXTENSIONS: ReadonlySet<string>;
|
|
27
27
|
/** Markdown only — the `fmt` scope (the formatter never rewrites source). */
|
|
28
28
|
export declare const MARKDOWN_EXTENSIONS: ReadonlySet<string>;
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Gherkin `.feature` files, whose `# [ID]` header comments define entries
|
|
31
|
+
* (ADR-038). Not part of {@linkcode SOURCE_EXTENSIONS}: that set drives the
|
|
32
|
+
* tree-sitter grammars and the LSP, and `.feature` files use neither.
|
|
33
|
+
*/
|
|
34
|
+
export declare const FEATURE_EXTENSIONS: ReadonlySet<string>;
|
|
35
|
+
/** Everything MarkSpec-relevant: markdown, source and `.feature` files. */
|
|
30
36
|
export declare const RELEVANT_EXTENSIONS: ReadonlySet<string>;
|
|
31
37
|
/** One directory entry from {@linkcode DiscoveryIO.readDir}.
|
|
32
38
|
* Structurally compatible with `Deno.DirEntry`. */
|
|
@@ -67,4 +73,17 @@ export interface DiscoverOptions {
|
|
|
67
73
|
* output across filesystems. Unreadable directories are skipped.
|
|
68
74
|
*/
|
|
69
75
|
export declare function discoverFiles(root: string, io: DiscoveryIO, options?: DiscoverOptions): AsyncGenerator<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Report whether {@linkcode discoverFiles} with the same `root`, `io` and
|
|
78
|
+
* `options` would yield `path`. It applies the same rules as the walk: the
|
|
79
|
+
* extension filter, hidden directories, the built-in build-output skips, the
|
|
80
|
+
* `.gitignore` chain and `exclude`. It checks the directories from `root`
|
|
81
|
+
* down to the file, so a file under an ignored directory is not included.
|
|
82
|
+
* The file must exist as a regular file: a path that does not exist, a
|
|
83
|
+
* symbolic link, and a path outside `root` are not included. It lists every
|
|
84
|
+
* ancestor directory of the file, so it is meant for per-file checks, not
|
|
85
|
+
* bulk use. It compares paths as given: case and symbolic links in the
|
|
86
|
+
* directories above the file are not resolved.
|
|
87
|
+
*/
|
|
88
|
+
export declare function isDiscoverable(path: string, root: string, io: DiscoveryIO, options?: DiscoverOptions): Promise<boolean>;
|
|
70
89
|
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/discovery/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/discovery/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAYH,OAAO,EAAE,KAAK,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAE/E;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAmBhD,CAAC;AAEH,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAAoB,CAAC;AAEzE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAAyB,CAAC;AAE7E,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAIlD,CAAC;AAEH;mDACmD;AACnD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED,kDAAkD;AAClD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC,iBAAiB,CAAC,CAAC;IACxD,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACrD;AAED,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,QAAQ,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1C;;;6EAGyE;IACzE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC;;;;;;;;OAQG;IACH,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CACxC;AA8BD;;;;GAIG;AACH,wBAAuB,aAAa,CAClC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,WAAW,EACf,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAAC,MAAM,CAAC,CAaxB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,WAAW,EACf,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,OAAO,CAAC,CAgClB"}
|
package/esm/discovery/mod.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* I/O is injected via {@linkcode DiscoveryIO} so the module stays
|
|
18
18
|
* Node-compatible; entry points supply the Deno implementation.
|
|
19
19
|
*/
|
|
20
|
-
import { extname, join, relative, resolve, SEPARATOR } from "@std/path";
|
|
20
|
+
import { extname, isAbsolute, join, relative, resolve, SEPARATOR, } from "@std/path";
|
|
21
21
|
import { isIgnored, parseGitignore } from "./gitignore.js";
|
|
22
22
|
export { isIgnored, parseGitignore } from "./gitignore.js";
|
|
23
23
|
/**
|
|
@@ -47,10 +47,17 @@ export const SOURCE_EXTENSIONS = new Set([
|
|
|
47
47
|
]);
|
|
48
48
|
/** Markdown only — the `fmt` scope (the formatter never rewrites source). */
|
|
49
49
|
export const MARKDOWN_EXTENSIONS = new Set([".md"]);
|
|
50
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Gherkin `.feature` files, whose `# [ID]` header comments define entries
|
|
52
|
+
* (ADR-038). Not part of {@linkcode SOURCE_EXTENSIONS}: that set drives the
|
|
53
|
+
* tree-sitter grammars and the LSP, and `.feature` files use neither.
|
|
54
|
+
*/
|
|
55
|
+
export const FEATURE_EXTENSIONS = new Set([".feature"]);
|
|
56
|
+
/** Everything MarkSpec-relevant: markdown, source and `.feature` files. */
|
|
51
57
|
export const RELEVANT_EXTENSIONS = new Set([
|
|
52
58
|
...MARKDOWN_EXTENSIONS,
|
|
53
59
|
...SOURCE_EXTENSIONS,
|
|
60
|
+
...FEATURE_EXTENSIONS,
|
|
54
61
|
]);
|
|
55
62
|
/**
|
|
56
63
|
* Directory names pruned by default, in addition to the hidden-dir skip.
|
|
@@ -82,16 +89,104 @@ const BUILTIN_SKIP_RULES = parseGitignore(BUILTIN_SKIP_DIRS.map((d) => `${d}/`).
|
|
|
82
89
|
*/
|
|
83
90
|
export async function* discoverFiles(root, io, options = {}) {
|
|
84
91
|
const extensions = options.extensions ?? RELEVANT_EXTENSIONS;
|
|
92
|
+
const start = await walkStart(root, io, options);
|
|
93
|
+
// Carry excludes separately: they must stay after every `.gitignore`,
|
|
94
|
+
// including ones loaded deeper in the walk.
|
|
95
|
+
yield* walk(root, start.prefix, start.rules, start.excludeRules, io, extensions);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Report whether {@linkcode discoverFiles} with the same `root`, `io` and
|
|
99
|
+
* `options` would yield `path`. It applies the same rules as the walk: the
|
|
100
|
+
* extension filter, hidden directories, the built-in build-output skips, the
|
|
101
|
+
* `.gitignore` chain and `exclude`. It checks the directories from `root`
|
|
102
|
+
* down to the file, so a file under an ignored directory is not included.
|
|
103
|
+
* The file must exist as a regular file: a path that does not exist, a
|
|
104
|
+
* symbolic link, and a path outside `root` are not included. It lists every
|
|
105
|
+
* ancestor directory of the file, so it is meant for per-file checks, not
|
|
106
|
+
* bulk use. It compares paths as given: case and symbolic links in the
|
|
107
|
+
* directories above the file are not resolved.
|
|
108
|
+
*/
|
|
109
|
+
export async function isDiscoverable(path, root, io, options = {}) {
|
|
110
|
+
const extensions = options.extensions ?? RELEVANT_EXTENSIONS;
|
|
111
|
+
if (!isRelevantFile(path, extensions))
|
|
112
|
+
return false;
|
|
113
|
+
const rel = relative(resolve(root), resolve(path));
|
|
114
|
+
if (rel === "" || rel === ".." || rel.startsWith(`..${SEPARATOR}`) ||
|
|
115
|
+
isAbsolute(rel)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
const segments = rel.split(SEPARATOR);
|
|
119
|
+
const start = await walkStart(root, io, options);
|
|
120
|
+
let rules = start.rules;
|
|
121
|
+
let absDir = root;
|
|
122
|
+
let relDir = start.prefix;
|
|
123
|
+
for (let i = 0; i < segments.length; i++) {
|
|
124
|
+
const gitignoreRules = await rulesForDirectory(absDir, relDir, rules, io);
|
|
125
|
+
const active = [...gitignoreRules, ...start.excludeRules];
|
|
126
|
+
const name = segments[i];
|
|
127
|
+
const entryRel = relDir === "" ? name : `${relDir}/${name}`;
|
|
128
|
+
const isLast = i === segments.length - 1;
|
|
129
|
+
// The walk yields only entries that report isFile or isDirectory, so a
|
|
130
|
+
// symbolic link, or a path that does not exist, is not discoverable.
|
|
131
|
+
const kind = await entryKind(absDir, name, io);
|
|
132
|
+
if (isLast ? kind !== "file" : kind !== "directory")
|
|
133
|
+
return false;
|
|
134
|
+
if (isLast)
|
|
135
|
+
return !isIgnored(entryRel, false, active);
|
|
136
|
+
if (isPrunedDirectory(name, entryRel, active))
|
|
137
|
+
return false;
|
|
138
|
+
rules = gitignoreRules;
|
|
139
|
+
absDir = join(absDir, name);
|
|
140
|
+
relDir = entryRel;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
/** The kind of the entry `name` in `absDir`, as the walk sees it. */
|
|
145
|
+
async function entryKind(absDir, name, io) {
|
|
146
|
+
try {
|
|
147
|
+
for await (const e of io.readDir(absDir)) {
|
|
148
|
+
if (e.name !== name)
|
|
149
|
+
continue;
|
|
150
|
+
return e.isDirectory ? "directory" : e.isFile ? "file" : undefined;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// An unreadable directory is skipped by the walk.
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
/** The starting rule state of a walk of `root`, shared by the walk and
|
|
159
|
+
* {@linkcode isDiscoverable}. `prefix` is the path of `root` below the
|
|
160
|
+
* folder the rules are anchored at. */
|
|
161
|
+
async function walkStart(root, io, options) {
|
|
85
162
|
const inherited = options.inheritGitignoreFrom === undefined
|
|
86
163
|
? { rules: [], prefix: "" }
|
|
87
164
|
: await inheritedGitignoreRules(options.inheritGitignoreFrom, root, io);
|
|
88
165
|
// With inherited rules, every rule is matched against paths relative to
|
|
89
166
|
// the enclosing folder, so `prefix` is the path from it down to `root`.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
167
|
+
return {
|
|
168
|
+
prefix: inherited.prefix,
|
|
169
|
+
rules: [...BUILTIN_SKIP_RULES, ...inherited.rules],
|
|
170
|
+
excludeRules: parseGitignore((options.exclude ?? []).join("\n"), inherited.prefix),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** `true` when a file has one of the `extensions`. */
|
|
174
|
+
function isRelevantFile(path, extensions) {
|
|
175
|
+
return extensions.has(extname(path).toLowerCase());
|
|
176
|
+
}
|
|
177
|
+
/** `true` when the walk does not enter a directory: hidden, or ignored.
|
|
178
|
+
* Git semantics: paths under an ignored directory cannot be re-included, so
|
|
179
|
+
* pruning is correct. */
|
|
180
|
+
function isPrunedDirectory(name, rel, active) {
|
|
181
|
+
return name.startsWith(".") || isIgnored(rel, true, active);
|
|
182
|
+
}
|
|
183
|
+
/** The `.gitignore` rules in force inside `absDir`: the inherited `rules`
|
|
184
|
+
* followed by the directory's own `.gitignore`, so deeper rules win. */
|
|
185
|
+
async function rulesForDirectory(absDir, relDir, rules, io) {
|
|
186
|
+
const raw = await io.readFile(join(absDir, ".gitignore"));
|
|
187
|
+
return raw !== undefined && raw.length > 0
|
|
188
|
+
? [...rules, ...parseGitignore(raw, relDir)]
|
|
189
|
+
: rules;
|
|
95
190
|
}
|
|
96
191
|
/**
|
|
97
192
|
* Collect the `.gitignore` rules of the folders from `from` down to the
|
|
@@ -122,10 +217,7 @@ async function inheritedGitignoreRules(from, root, io) {
|
|
|
122
217
|
async function* walk(absDir, relDir, rules, excludeRules, io, extensions) {
|
|
123
218
|
// Deeper `.gitignore` rules win over inherited ones. Excludes stay last
|
|
124
219
|
// for this directory's decisions, but are not inherited as gitignore rules.
|
|
125
|
-
const
|
|
126
|
-
const gitignoreRules = raw !== undefined && raw.length > 0
|
|
127
|
-
? [...rules, ...parseGitignore(raw, relDir)]
|
|
128
|
-
: rules;
|
|
220
|
+
const gitignoreRules = await rulesForDirectory(absDir, relDir, rules, io);
|
|
129
221
|
const active = [...gitignoreRules, ...excludeRules];
|
|
130
222
|
const entries = [];
|
|
131
223
|
try {
|
|
@@ -139,16 +231,12 @@ async function* walk(absDir, relDir, rules, excludeRules, io, extensions) {
|
|
|
139
231
|
for (const entry of entries) {
|
|
140
232
|
const rel = relDir === "" ? entry.name : `${relDir}/${entry.name}`;
|
|
141
233
|
if (entry.isDirectory) {
|
|
142
|
-
if (entry.name
|
|
143
|
-
continue; // built-in: hidden dirs
|
|
144
|
-
// Git semantics: paths under an ignored directory cannot be
|
|
145
|
-
// re-included, so pruning here is correct (and fast).
|
|
146
|
-
if (isIgnored(rel, true, active))
|
|
234
|
+
if (isPrunedDirectory(entry.name, rel, active))
|
|
147
235
|
continue;
|
|
148
236
|
yield* walk(join(absDir, entry.name), rel, gitignoreRules, excludeRules, io, extensions);
|
|
149
237
|
}
|
|
150
238
|
else if (entry.isFile) {
|
|
151
|
-
if (!
|
|
239
|
+
if (!isRelevantFile(entry.name, extensions))
|
|
152
240
|
continue;
|
|
153
241
|
if (isIgnored(rel, false, active))
|
|
154
242
|
continue;
|
|
@@ -74,11 +74,14 @@ export declare function readEntryBody(text: string, file: string, displayId: str
|
|
|
74
74
|
* before or after the edit. So the edit is refused when an `MSL-P020`,
|
|
75
75
|
* `MSL-P021` or `MSL-P022` names the entry (the message starts with
|
|
76
76
|
* `<displayId>:`). This is broader than that case: `MSL-P020` also fires
|
|
77
|
-
* when a body
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
77
|
+
* when a body `Id:` or trace-relation line has other content after it,
|
|
78
|
+
* when an `Id:` run sits directly under prose (warning), and when a
|
|
79
|
+
* trailing trace-relation line is body prose (warning), so such an entry
|
|
80
|
+
* is refused too. An entry whose trailer-looking lines the parser reads as
|
|
81
|
+
* body without a diagnostic (for example `Note:` lines, or `Status:`
|
|
82
|
+
* directly under prose) is edited as the parser sees it: those lines are
|
|
83
|
+
* body. A final paragraph of only core keys after a blank line, such as a
|
|
84
|
+
* lone `Rationale:` line, is the trailer, not body.
|
|
82
85
|
*/
|
|
83
86
|
export declare function replaceEntryBody(text: string, file: string, displayId: string, body: string): Promise<EntryBodyEdit>;
|
|
84
87
|
//# sourceMappingURL=entry_body.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry_body.d.ts","sourceRoot":"","sources":["../../src/formatter/entry_body.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH,wDAAwD;AACxD,MAAM,MAAM,gBAAgB,GACxB,iBAAiB,GACjB,YAAY,GACZ,gBAAgB,GAChB,iBAAiB,GACjB,iBAAiB,CAAC;AAEtB,8CAA8C;AAC9C,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,CAAC;AA8E/D;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAQlE;AAyCD;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAS7B;AASD
|
|
1
|
+
{"version":3,"file":"entry_body.d.ts","sourceRoot":"","sources":["../../src/formatter/entry_body.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH,wDAAwD;AACxD,MAAM,MAAM,gBAAgB,GACxB,iBAAiB,GACjB,YAAY,GACZ,gBAAgB,GAChB,iBAAiB,GACjB,iBAAiB,CAAC;AAEtB,8CAA8C;AAC9C,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,CAAC;AA8E/D;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAQlE;AAyCD;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAS7B;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,aAAa,CAAC,CAoDxB"}
|
|
@@ -171,11 +171,14 @@ function dedent(line, indent) {
|
|
|
171
171
|
* before or after the edit. So the edit is refused when an `MSL-P020`,
|
|
172
172
|
* `MSL-P021` or `MSL-P022` names the entry (the message starts with
|
|
173
173
|
* `<displayId>:`). This is broader than that case: `MSL-P020` also fires
|
|
174
|
-
* when a body
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
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.
|
|
179
182
|
*/
|
|
180
183
|
export async function replaceEntryBody(text, file, displayId, body) {
|
|
181
184
|
const before = await locate(text, file, displayId);
|
|
@@ -272,9 +275,10 @@ function sameEntries(before, after, target, targetAfter) {
|
|
|
272
275
|
* blank line between them, raises no diagnostic; the parser keeps it as
|
|
273
276
|
* body text and adds no entry, so the edit is accepted.
|
|
274
277
|
*
|
|
275
|
-
* Known limit: the
|
|
276
|
-
*
|
|
277
|
-
*
|
|
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
|
|
278
282
|
* body text; no trailer or entry changes.
|
|
279
283
|
*/
|
|
280
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
|
+
}
|
package/esm/formatter/mod.d.ts
CHANGED
|
@@ -93,7 +93,9 @@ export declare function format(markdown: string, options?: FormatOptions): Forma
|
|
|
93
93
|
* Expand CSV values on repeatable-type attributes into one entry per value
|
|
94
94
|
* per ADR-002 §2.6. `id-list` / `tag-list` / `external-id` accept CSV input
|
|
95
95
|
* but must round-trip as multi-line output; `citation` is left alone
|
|
96
|
-
* 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.
|
|
97
99
|
*/
|
|
98
100
|
export declare function expandCsvValues(attrs: Attribute[]): Attribute[];
|
|
99
101
|
/**
|
|
@@ -144,7 +146,24 @@ export declare function findItemEnd(lines: readonly string[], startIdx: number,
|
|
|
144
146
|
* for an entry starting at the given line.
|
|
145
147
|
*
|
|
146
148
|
* Scans forward from the entry start to find the list item boundary,
|
|
147
|
-
* 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.
|
|
148
167
|
*/
|
|
149
168
|
export declare function findAttributeBlockRange(lines: readonly string[], entryStartLine: number, indent: number, itemEndFloor?: number, preservedRanges?: readonly EntryExtent[]): {
|
|
150
169
|
start: number;
|
|
@@ -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"}
|