@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.
Files changed (317) hide show
  1. package/esm/ast/build.d.ts.map +1 -1
  2. package/esm/ast/build.js +19 -5
  3. package/esm/ast/equivalence.js +14 -2
  4. package/esm/ast/nodes.d.ts +15 -3
  5. package/esm/ast/nodes.d.ts.map +1 -1
  6. package/esm/compiler/inverses.d.ts.map +1 -1
  7. package/esm/compiler/inverses.js +18 -3
  8. package/esm/compiler/mod.d.ts +34 -1
  9. package/esm/compiler/mod.d.ts.map +1 -1
  10. package/esm/compiler/mod.js +112 -48
  11. package/esm/compiler/schema.d.ts +3 -2
  12. package/esm/compiler/schema.d.ts.map +1 -1
  13. package/esm/compiler/schema.js +6 -3
  14. package/esm/config/markspec.d.ts +2 -2
  15. package/esm/config/mod.d.ts.map +1 -1
  16. package/esm/config/mod.js +47 -5
  17. package/esm/criteria/scenarios.d.ts +55 -0
  18. package/esm/criteria/scenarios.d.ts.map +1 -0
  19. package/esm/criteria/scenarios.js +133 -0
  20. package/esm/discovery/mod.d.ts +20 -1
  21. package/esm/discovery/mod.d.ts.map +1 -1
  22. package/esm/discovery/mod.js +105 -17
  23. package/esm/discovery/projects.d.ts +6 -4
  24. package/esm/discovery/projects.d.ts.map +1 -1
  25. package/esm/discovery/projects.js +27 -17
  26. package/esm/formatter/entry_body.d.ts +13 -12
  27. package/esm/formatter/entry_body.d.ts.map +1 -1
  28. package/esm/formatter/entry_body.js +25 -17
  29. package/esm/formatter/feature_file.d.ts +40 -0
  30. package/esm/formatter/feature_file.d.ts.map +1 -0
  31. package/esm/formatter/feature_file.js +88 -0
  32. package/esm/formatter/md_equiv.d.ts +6 -5
  33. package/esm/formatter/md_equiv.d.ts.map +1 -1
  34. package/esm/formatter/md_equiv.js +6 -5
  35. package/esm/formatter/mod.d.ts +25 -3
  36. package/esm/formatter/mod.d.ts.map +1 -1
  37. package/esm/formatter/mod.js +267 -27
  38. package/esm/formatter/tab_markers.d.ts +15 -0
  39. package/esm/formatter/tab_markers.d.ts.map +1 -0
  40. package/esm/formatter/tab_markers.js +133 -0
  41. package/esm/gates/mod.d.ts +2 -2
  42. package/esm/gates/mod.d.ts.map +1 -1
  43. package/esm/gates/mod.js +18 -3
  44. package/esm/gherkin/load.d.ts +35 -0
  45. package/esm/gherkin/load.d.ts.map +1 -0
  46. package/esm/gherkin/load.js +39 -0
  47. package/esm/gherkin/parse.d.ts +11 -0
  48. package/esm/gherkin/parse.d.ts.map +1 -0
  49. package/esm/gherkin/parse.js +311 -0
  50. package/esm/gherkin/position.d.ts +23 -0
  51. package/esm/gherkin/position.d.ts.map +1 -0
  52. package/esm/gherkin/position.js +21 -0
  53. package/esm/gherkin/procedure.d.ts +76 -0
  54. package/esm/gherkin/procedure.d.ts.map +1 -0
  55. package/esm/gherkin/procedure.js +164 -0
  56. package/esm/gherkin/project.d.ts +35 -0
  57. package/esm/gherkin/project.d.ts.map +1 -0
  58. package/esm/gherkin/project.js +64 -0
  59. package/esm/gherkin/role.d.ts +23 -0
  60. package/esm/gherkin/role.d.ts.map +1 -0
  61. package/esm/gherkin/role.js +28 -0
  62. package/esm/gherkin/types.d.ts +118 -0
  63. package/esm/gherkin/types.d.ts.map +1 -0
  64. package/esm/gherkin/types.js +12 -0
  65. package/esm/lock/acquire_compile.d.ts +12 -4
  66. package/esm/lock/acquire_compile.d.ts.map +1 -1
  67. package/esm/lock/acquire_compile.js +15 -5
  68. package/esm/lock/canonical_edges.d.ts +6 -2
  69. package/esm/lock/canonical_edges.d.ts.map +1 -1
  70. package/esm/lock/canonical_edges.js +10 -3
  71. package/esm/lock/model.d.ts +5 -0
  72. package/esm/lock/model.d.ts.map +1 -1
  73. package/esm/lock/parser.d.ts.map +1 -1
  74. package/esm/lock/parser.js +2 -0
  75. package/esm/lock/resolve.d.ts +6 -2
  76. package/esm/lock/resolve.d.ts.map +1 -1
  77. package/esm/lock/resolve.js +36 -4
  78. package/esm/lock/serializer.d.ts.map +1 -1
  79. package/esm/lock/serializer.js +7 -1
  80. package/esm/lock/upstream_deps.js +1 -1
  81. package/esm/mod.d.ts +24 -6
  82. package/esm/mod.d.ts.map +1 -1
  83. package/esm/mod.js +19 -5
  84. package/esm/model/mod.d.ts +43 -2
  85. package/esm/model/mod.d.ts.map +1 -1
  86. package/esm/model/mod.js +1 -1
  87. package/esm/model/relations.d.ts +9 -0
  88. package/esm/model/relations.d.ts.map +1 -1
  89. package/esm/model/relations.js +16 -1
  90. package/esm/parser/attributes.d.ts +82 -3
  91. package/esm/parser/attributes.d.ts.map +1 -1
  92. package/esm/parser/attributes.js +199 -32
  93. package/esm/parser/body_tokens.d.ts +1 -1
  94. package/esm/parser/body_tokens.d.ts.map +1 -1
  95. package/esm/parser/body_tokens.js +49 -35
  96. package/esm/parser/feature_file.d.ts +116 -0
  97. package/esm/parser/feature_file.d.ts.map +1 -0
  98. package/esm/parser/feature_file.js +540 -0
  99. package/esm/parser/markdown.d.ts +7 -0
  100. package/esm/parser/markdown.d.ts.map +1 -1
  101. package/esm/parser/markdown.js +129 -40
  102. package/esm/parser/mod.d.ts +18 -0
  103. package/esm/parser/mod.d.ts.map +1 -1
  104. package/esm/parser/mod.js +51 -0
  105. package/esm/parser/translate.d.ts.map +1 -1
  106. package/esm/parser/translate.js +5 -0
  107. package/esm/refs/mod.d.ts +8 -3
  108. package/esm/refs/mod.d.ts.map +1 -1
  109. package/esm/refs/mod.js +20 -7
  110. package/esm/refs/split.d.ts +58 -0
  111. package/esm/refs/split.d.ts.map +1 -0
  112. package/esm/refs/split.js +137 -0
  113. package/esm/reporter/mod.d.ts +7 -0
  114. package/esm/reporter/mod.d.ts.map +1 -1
  115. package/esm/reporter/mod.js +113 -3
  116. package/esm/sync/mapping.d.ts +4 -3
  117. package/esm/sync/mapping.d.ts.map +1 -1
  118. package/esm/sync/mapping.js +52 -9
  119. package/esm/util/display_id.d.ts +20 -0
  120. package/esm/util/display_id.d.ts.map +1 -0
  121. package/esm/util/display_id.js +19 -0
  122. package/esm/validator/attributes.d.ts.map +1 -1
  123. package/esm/validator/attributes.js +4 -1
  124. package/esm/validator/block_role.d.ts +40 -0
  125. package/esm/validator/block_role.d.ts.map +1 -0
  126. package/esm/validator/block_role.js +109 -0
  127. package/esm/validator/feature_ac.d.ts.map +1 -1
  128. package/esm/validator/feature_ac.js +6 -1
  129. package/esm/validator/feature_parse.d.ts +35 -0
  130. package/esm/validator/feature_parse.d.ts.map +1 -0
  131. package/esm/validator/feature_parse.js +69 -0
  132. package/esm/validator/locators.d.ts +36 -0
  133. package/esm/validator/locators.d.ts.map +1 -0
  134. package/esm/validator/locators.js +184 -0
  135. package/esm/validator/mod.d.ts +10 -1
  136. package/esm/validator/mod.d.ts.map +1 -1
  137. package/esm/validator/mod.js +38 -14
  138. package/esm/validator/normalize.d.ts.map +1 -1
  139. package/esm/validator/normalize.js +8 -3
  140. package/esm/validator/per_type_attrs.d.ts +3 -3
  141. package/esm/validator/per_type_attrs.js +3 -3
  142. package/esm/validator/pipeline.d.ts +10 -16
  143. package/esm/validator/pipeline.d.ts.map +1 -1
  144. package/esm/validator/pipeline.js +37 -16
  145. package/esm/validator/procedure.d.ts +22 -0
  146. package/esm/validator/procedure.d.ts.map +1 -0
  147. package/esm/validator/procedure.js +58 -0
  148. package/esm/validator/trace_types.d.ts.map +1 -1
  149. package/esm/validator/trace_types.js +4 -3
  150. package/esm/validator/traceability.d.ts.map +1 -1
  151. package/esm/validator/traceability.js +4 -1
  152. package/esm/validator/type_resolution.d.ts +5 -3
  153. package/esm/validator/type_resolution.d.ts.map +1 -1
  154. package/esm/validator/type_resolution.js +14 -2
  155. package/esm/validator/types.d.ts +11 -0
  156. package/esm/validator/types.d.ts.map +1 -1
  157. package/esm/validator/types.js +26 -4
  158. package/esm/validator/uxil_family.d.ts +1 -1
  159. package/package.json +3 -1
  160. package/script/ast/build.d.ts.map +1 -1
  161. package/script/ast/build.js +19 -5
  162. package/script/ast/equivalence.js +14 -2
  163. package/script/ast/nodes.d.ts +15 -3
  164. package/script/ast/nodes.d.ts.map +1 -1
  165. package/script/compiler/inverses.d.ts.map +1 -1
  166. package/script/compiler/inverses.js +18 -3
  167. package/script/compiler/mod.d.ts +34 -1
  168. package/script/compiler/mod.d.ts.map +1 -1
  169. package/script/compiler/mod.js +110 -46
  170. package/script/compiler/schema.d.ts +3 -2
  171. package/script/compiler/schema.d.ts.map +1 -1
  172. package/script/compiler/schema.js +6 -3
  173. package/script/config/markspec.d.ts +2 -2
  174. package/script/config/mod.d.ts.map +1 -1
  175. package/script/config/mod.js +47 -5
  176. package/script/criteria/scenarios.d.ts +55 -0
  177. package/script/criteria/scenarios.d.ts.map +1 -0
  178. package/script/criteria/scenarios.js +139 -0
  179. package/script/discovery/mod.d.ts +20 -1
  180. package/script/discovery/mod.d.ts.map +1 -1
  181. package/script/discovery/mod.js +106 -17
  182. package/script/discovery/projects.d.ts +6 -4
  183. package/script/discovery/projects.d.ts.map +1 -1
  184. package/script/discovery/projects.js +27 -17
  185. package/script/formatter/entry_body.d.ts +13 -12
  186. package/script/formatter/entry_body.d.ts.map +1 -1
  187. package/script/formatter/entry_body.js +25 -17
  188. package/script/formatter/feature_file.d.ts +40 -0
  189. package/script/formatter/feature_file.d.ts.map +1 -0
  190. package/script/formatter/feature_file.js +92 -0
  191. package/script/formatter/md_equiv.d.ts +6 -5
  192. package/script/formatter/md_equiv.d.ts.map +1 -1
  193. package/script/formatter/md_equiv.js +6 -5
  194. package/script/formatter/mod.d.ts +25 -3
  195. package/script/formatter/mod.d.ts.map +1 -1
  196. package/script/formatter/mod.js +266 -26
  197. package/script/formatter/tab_markers.d.ts +15 -0
  198. package/script/formatter/tab_markers.d.ts.map +1 -0
  199. package/script/formatter/tab_markers.js +141 -0
  200. package/script/gates/mod.d.ts +2 -2
  201. package/script/gates/mod.d.ts.map +1 -1
  202. package/script/gates/mod.js +18 -3
  203. package/script/gherkin/load.d.ts +35 -0
  204. package/script/gherkin/load.d.ts.map +1 -0
  205. package/script/gherkin/load.js +76 -0
  206. package/script/gherkin/parse.d.ts +11 -0
  207. package/script/gherkin/parse.d.ts.map +1 -0
  208. package/script/gherkin/parse.js +314 -0
  209. package/script/gherkin/position.d.ts +23 -0
  210. package/script/gherkin/position.d.ts.map +1 -0
  211. package/script/gherkin/position.js +24 -0
  212. package/script/gherkin/procedure.d.ts +76 -0
  213. package/script/gherkin/procedure.d.ts.map +1 -0
  214. package/script/gherkin/procedure.js +169 -0
  215. package/script/gherkin/project.d.ts +35 -0
  216. package/script/gherkin/project.d.ts.map +1 -0
  217. package/script/gherkin/project.js +67 -0
  218. package/script/gherkin/role.d.ts +23 -0
  219. package/script/gherkin/role.d.ts.map +1 -0
  220. package/script/gherkin/role.js +31 -0
  221. package/script/gherkin/types.d.ts +118 -0
  222. package/script/gherkin/types.d.ts.map +1 -0
  223. package/script/gherkin/types.js +13 -0
  224. package/script/lock/acquire_compile.d.ts +12 -4
  225. package/script/lock/acquire_compile.d.ts.map +1 -1
  226. package/script/lock/acquire_compile.js +15 -5
  227. package/script/lock/canonical_edges.d.ts +6 -2
  228. package/script/lock/canonical_edges.d.ts.map +1 -1
  229. package/script/lock/canonical_edges.js +10 -3
  230. package/script/lock/model.d.ts +5 -0
  231. package/script/lock/model.d.ts.map +1 -1
  232. package/script/lock/parser.d.ts.map +1 -1
  233. package/script/lock/parser.js +2 -0
  234. package/script/lock/resolve.d.ts +6 -2
  235. package/script/lock/resolve.d.ts.map +1 -1
  236. package/script/lock/resolve.js +36 -4
  237. package/script/lock/serializer.d.ts.map +1 -1
  238. package/script/lock/serializer.js +7 -1
  239. package/script/lock/upstream_deps.js +1 -1
  240. package/script/mod.d.ts +24 -6
  241. package/script/mod.d.ts.map +1 -1
  242. package/script/mod.js +48 -6
  243. package/script/model/mod.d.ts +43 -2
  244. package/script/model/mod.d.ts.map +1 -1
  245. package/script/model/mod.js +2 -1
  246. package/script/model/relations.d.ts +9 -0
  247. package/script/model/relations.d.ts.map +1 -1
  248. package/script/model/relations.js +17 -1
  249. package/script/parser/attributes.d.ts +82 -3
  250. package/script/parser/attributes.d.ts.map +1 -1
  251. package/script/parser/attributes.js +205 -33
  252. package/script/parser/body_tokens.d.ts +1 -1
  253. package/script/parser/body_tokens.d.ts.map +1 -1
  254. package/script/parser/body_tokens.js +49 -35
  255. package/script/parser/feature_file.d.ts +116 -0
  256. package/script/parser/feature_file.d.ts.map +1 -0
  257. package/script/parser/feature_file.js +548 -0
  258. package/script/parser/markdown.d.ts +7 -0
  259. package/script/parser/markdown.d.ts.map +1 -1
  260. package/script/parser/markdown.js +128 -39
  261. package/script/parser/mod.d.ts +18 -0
  262. package/script/parser/mod.d.ts.map +1 -1
  263. package/script/parser/mod.js +52 -1
  264. package/script/parser/translate.d.ts.map +1 -1
  265. package/script/parser/translate.js +5 -0
  266. package/script/refs/mod.d.ts +8 -3
  267. package/script/refs/mod.d.ts.map +1 -1
  268. package/script/refs/mod.js +20 -7
  269. package/script/refs/split.d.ts +58 -0
  270. package/script/refs/split.d.ts.map +1 -0
  271. package/script/refs/split.js +145 -0
  272. package/script/reporter/mod.d.ts +7 -0
  273. package/script/reporter/mod.d.ts.map +1 -1
  274. package/script/reporter/mod.js +113 -3
  275. package/script/sync/mapping.d.ts +4 -3
  276. package/script/sync/mapping.d.ts.map +1 -1
  277. package/script/sync/mapping.js +52 -9
  278. package/script/util/display_id.d.ts +20 -0
  279. package/script/util/display_id.d.ts.map +1 -0
  280. package/script/util/display_id.js +22 -0
  281. package/script/validator/attributes.d.ts.map +1 -1
  282. package/script/validator/attributes.js +4 -1
  283. package/script/validator/block_role.d.ts +40 -0
  284. package/script/validator/block_role.d.ts.map +1 -0
  285. package/script/validator/block_role.js +112 -0
  286. package/script/validator/feature_ac.d.ts.map +1 -1
  287. package/script/validator/feature_ac.js +6 -1
  288. package/script/validator/feature_parse.d.ts +35 -0
  289. package/script/validator/feature_parse.d.ts.map +1 -0
  290. package/script/validator/feature_parse.js +73 -0
  291. package/script/validator/locators.d.ts +36 -0
  292. package/script/validator/locators.d.ts.map +1 -0
  293. package/script/validator/locators.js +188 -0
  294. package/script/validator/mod.d.ts +10 -1
  295. package/script/validator/mod.d.ts.map +1 -1
  296. package/script/validator/mod.js +38 -14
  297. package/script/validator/normalize.d.ts.map +1 -1
  298. package/script/validator/normalize.js +8 -3
  299. package/script/validator/per_type_attrs.d.ts +3 -3
  300. package/script/validator/per_type_attrs.js +3 -3
  301. package/script/validator/pipeline.d.ts +10 -16
  302. package/script/validator/pipeline.d.ts.map +1 -1
  303. package/script/validator/pipeline.js +36 -16
  304. package/script/validator/procedure.d.ts +22 -0
  305. package/script/validator/procedure.d.ts.map +1 -0
  306. package/script/validator/procedure.js +61 -0
  307. package/script/validator/trace_types.d.ts.map +1 -1
  308. package/script/validator/trace_types.js +4 -3
  309. package/script/validator/traceability.d.ts.map +1 -1
  310. package/script/validator/traceability.js +4 -1
  311. package/script/validator/type_resolution.d.ts +5 -3
  312. package/script/validator/type_resolution.d.ts.map +1 -1
  313. package/script/validator/type_resolution.js +14 -2
  314. package/script/validator/types.d.ts +11 -0
  315. package/script/validator/types.d.ts.map +1 -1
  316. package/script/validator/types.js +27 -4
  317. 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 spaces
85
- * after it. So `- [ID]` gives the marker column plus 2 and `- [ID]` gives
86
- * the marker column plus 4. Only a bullet followed by one to four spaces
87
- * can start an entry: ordered lists never hold entries, and five or more
88
- * spaces make the title an indented code block. When the line does not
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
- return m ? marker + 1 + m[1].length : marker + 2;
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 paragraph starts with a recognized trailer key, so such an
171
- * entry is refused too. The file already fails `markspec check` there.
172
- * An entry whose trailer-looking lines use only unrecognized keys, and
173
- * that the parser reads as body without a diagnostic, is edited as the
174
- * parser sees it: those lines are body.
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 parser raises at most one MSL-P020 per entry, so when
272
- * the target body already has a trailer-like line, a proposal that adds
273
- * more such lines raises no new MSL-P020 and is accepted. The lines stay
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 when they parse to the
6
- * same mdast structure after eliding source `position`s and collapsing
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 ONLY to accept/reject dprint output; the
19
- * ADR-015 relation still guards §5.2 body emission (MSL-F900) and must
20
- * not be modified.
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;;;;;;;;;;;;;;;;;;;;GAoBG;AAQH,wEAAwE;AACxE,wBAAgB,8BAA8B,CAC5C,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,OAAO,CAMT"}
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 when they parse to the
6
- * same mdast structure after eliding source `position`s and collapsing
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 ONLY to accept/reject dprint output; the
19
- * ADR-015 relation still guards §5.2 body emission (MSL-F900) and must
20
- * not be modified.
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";
@@ -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 walks backwards to find the contiguous trailing attribute block.
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;AA2BzB,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;AA8SD,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;CAC3B;AA2BD;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,MA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