@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
@@ -25,6 +25,7 @@ const attributes_js_1 = require("../parser/attributes.js");
25
25
  const frontmatter_js_1 = require("../parser/frontmatter.js");
26
26
  const markdown_js_1 = require("../parser/markdown.js");
27
27
  const fence_js_1 = require("../util/fence.js");
28
+ const split_js_1 = require("../refs/split.js");
28
29
  const line_endings_js_1 = require("../util/line_endings.js");
29
30
  const modals_js_1 = require("../util/modals.js");
30
31
  const synth_ulid_js_1 = require("./synth_ulid.js");
@@ -34,6 +35,7 @@ const normalize_js_1 = require("../ast/normalize.js");
34
35
  const equivalence_js_1 = require("../ast/equivalence.js");
35
36
  const prose_js_1 = require("./prose.js");
36
37
  const entry_body_js_1 = require("./entry_body.js");
38
+ const tab_markers_js_1 = require("./tab_markers.js");
37
39
  const dprint_js_1 = require("./dprint.js");
38
40
  const md_equiv_js_1 = require("./md_equiv.js");
39
41
  /**
@@ -220,10 +222,60 @@ function emitBodyViaAst(lines, file, diagnostics, cachedEntries, proseFormat) {
220
222
  // Process bottom-to-top so splices don't shift earlier entry positions.
221
223
  const sorted = [...entries].sort((a, b) => b.location.line - a.location.line);
222
224
  for (const entry of sorted) {
225
+ const protectedRanges = (0, tab_markers_js_1.protectedTabRanges)(lines);
226
+ const start = entry.location.line - 1;
227
+ if (protectedRanges.some((range) => start >= range.start && start < range.end))
228
+ continue;
229
+ const children = protectedRanges.filter((range, index) => range.start > start && range.start < (entry.endLine ?? start) &&
230
+ !protectedRanges.some((outer, other) => other !== index &&
231
+ outer.start < range.start && outer.end >= range.end));
232
+ if (children.length > 0) {
233
+ // Format the parent's prose with each refused child represented by a
234
+ // verbatim block, then restore the original child lines.
235
+ const end = entry.endLine;
236
+ const fragment = lines.slice(start, end);
237
+ const indent = (0, entry_body_js_1.contentColumn)(lines[start], entry.location.column - 1);
238
+ const replacements = [];
239
+ for (const child of children.toReversed()) {
240
+ const childEnd = Math.min(child.end, end);
241
+ let token = "<!-- markspec-preserved-child -->";
242
+ while (lines.some((line) => line.includes(token)) ||
243
+ replacements.some((r) => r.token === token))
244
+ token = token.replace(" -->", "- -->");
245
+ replacements.push({
246
+ token,
247
+ original: lines.slice(child.start, childEnd),
248
+ });
249
+ fragment.splice(child.start - start, childEnd - child.start, " ".repeat(indent) + token, "");
250
+ }
251
+ const nestedDiagnostics = [];
252
+ emitBodyViaAst(fragment, file, nestedDiagnostics, undefined, proseFormat);
253
+ for (const { token, original } of replacements) {
254
+ const at = fragment.findIndex((line) => line.trim() === token);
255
+ if (at < 0)
256
+ throw new Error("Preserved child placeholder was lost");
257
+ let after = at + 1;
258
+ while (after < fragment.length && fragment[after].trim() === "") {
259
+ after++;
260
+ }
261
+ fragment.splice(at, after - at, ...original);
262
+ }
263
+ diagnostics.push(...nestedDiagnostics.map((d) => ({
264
+ ...d,
265
+ location: d.location
266
+ ? { ...d.location, line: d.location.line + start }
267
+ : undefined,
268
+ })));
269
+ if (fragment.join("\n") !== lines.slice(start, end).join("\n")) {
270
+ lines.splice(start, end - start, ...fragment);
271
+ bodyChanged = true;
272
+ }
273
+ continue;
274
+ }
223
275
  if (!entry.body.trim())
224
276
  continue; // empty or whitespace-only body
225
277
  // List-item continuation indent: the item's content column, which
226
- // follows every space after the marker (#865).
278
+ // counts every space and tab after the marker (#865).
227
279
  const indent = (0, entry_body_js_1.contentColumn)(lines[entry.location.line - 1] ?? "", entry.location.column - 1);
228
280
  const indentStr = " ".repeat(indent);
229
281
  const titleLineIdx = entry.location.line - 1; // 0-based
@@ -365,6 +417,97 @@ function stampDisciplineFrozen(value, today) {
365
417
  }
366
418
  return value;
367
419
  }
420
+ /**
421
+ * Normalize tab markers before any pass can stamp or splice their entries.
422
+ * Compare whole documents so a neighbouring list cannot become a child.
423
+ */
424
+ function normalizeTabMarkers(markdown, options, diagnostics) {
425
+ const lines = markdown.split("\n");
426
+ const original = [...lines];
427
+ const markers = (0, tab_markers_js_1.tabMarkers)(lines).sort((a, b) => b.start - a.start);
428
+ if (markers.length === 0)
429
+ return markdown;
430
+ const accepted = new Set();
431
+ const refused = new Set();
432
+ for (const marker of markers) {
433
+ const before = lines.join("\n");
434
+ const candidate = [...lines];
435
+ const title = lines[marker.start];
436
+ const indent = (0, entry_body_js_1.contentColumn)(title, marker.column);
437
+ const delta = indent - (marker.column + 2);
438
+ candidate[marker.start] = title.slice(0, marker.column) + "- " +
439
+ title.slice(marker.column + 1 + marker.whitespace.length);
440
+ for (let i = marker.start + 1; i < marker.end; i++) {
441
+ if (candidate[i].startsWith(" ".repeat(indent))) {
442
+ candidate[i] = candidate[i].slice(delta);
443
+ }
444
+ }
445
+ const after = candidate.join("\n");
446
+ const beforeEntries = (0, markdown_js_1.parseMarkdown)(before).entries;
447
+ const afterEntries = (0, markdown_js_1.parseMarkdown)(after).entries;
448
+ const identitiesKept = beforeEntries.length === afterEntries.length &&
449
+ beforeEntries.every((entry, i) => entry.displayId === afterEntries[i].displayId &&
450
+ entry.id === afterEntries[i].id);
451
+ const containsRefused = [...refused].some((start) => start > marker.start && start < marker.end);
452
+ if (containsRefused || !(0, md_equiv_js_1.markdownSemanticallyEquivalent)(before, after) ||
453
+ !identitiesKept) {
454
+ // Refusing an enclosing entry must also undo admitted changes to its
455
+ // descendants. No identities have been stamped at this point.
456
+ lines.splice(marker.start, marker.end - marker.start, ...original.slice(marker.start, marker.end));
457
+ for (const start of accepted) {
458
+ if (start >= marker.start && start < marker.end)
459
+ accepted.delete(start);
460
+ }
461
+ refused.add(marker.start);
462
+ diagnostics.push({
463
+ code: "MSL-F013",
464
+ severity: "warning",
465
+ message: "Tab-separated entry marker cannot be normalized without " +
466
+ "changing CommonMark structure; kept the entry unchanged",
467
+ location: {
468
+ file: options?.file ?? "<unknown>",
469
+ line: marker.start + 1,
470
+ column: marker.column + 1,
471
+ },
472
+ });
473
+ continue;
474
+ }
475
+ lines.splice(0, lines.length, ...candidate);
476
+ accepted.add(marker.start);
477
+ }
478
+ const indexedStarts = new Set((0, markdown_js_1.parseMarkdown)(lines.join("\n")).entries.map((entry) => entry.location.line - 1));
479
+ for (const start of [...accepted].sort((a, b) => b - a)) {
480
+ // Re-read extents after each nested splice. Admission itself never
481
+ // changes line counts, so earlier title positions remain valid.
482
+ const marker = (0, tab_markers_js_1.entryListItems)(lines).find((item) => item.start === start);
483
+ // Nested entries are outside the parser's top-level entry index. Format
484
+ // their normalized item separately, then restore the enclosing indent.
485
+ if (marker.container.start !== marker.start &&
486
+ !indexedStarts.has(marker.container.start)) {
487
+ const prefix = " ".repeat(marker.column);
488
+ const fragment = lines.slice(marker.start, marker.end)
489
+ .map((line) => line.startsWith(prefix) ? line.slice(prefix.length) : line)
490
+ .join("\n");
491
+ const nested = formatEntries(fragment, options);
492
+ const replacement = nested.output.split("\n")
493
+ .map((line) => line === "" ? "" : prefix + line);
494
+ lines.splice(marker.start, marker.end - marker.start, ...replacement);
495
+ diagnostics.push(...nested.diagnostics.map((diagnostic) => ({
496
+ ...diagnostic,
497
+ ...(diagnostic.location
498
+ ? {
499
+ location: {
500
+ ...diagnostic.location,
501
+ line: diagnostic.location.line + marker.start,
502
+ column: diagnostic.location.column + marker.column,
503
+ },
504
+ }
505
+ : {}),
506
+ })));
507
+ }
508
+ }
509
+ return lines.join("\n");
510
+ }
368
511
  /**
369
512
  * Format a Markdown string — normalize attribute blocks,
370
513
  * fix indentation, enforce canonical ordering.
@@ -374,6 +517,25 @@ function stampDisciplineFrozen(value, today) {
374
517
  * @returns Format result with output text and diagnostics
375
518
  */
376
519
  function format(markdown, options) {
520
+ // A `.feature` file is Gherkin, not Markdown: neither the entry formatter
521
+ // nor the prose pass may touch it. Its Id stamping is `formatFeatureText`.
522
+ if ((0, path_1.extname)(options?.file ?? "").toLowerCase() === ".feature") {
523
+ return { output: markdown, diagnostics: [], changed: false };
524
+ }
525
+ const diagnostics = [];
526
+ const ending = (0, line_endings_js_1.detectLineEnding)(markdown);
527
+ const prepared = normalizeTabMarkers((0, line_endings_js_1.normalizeLineEndings)(markdown), options, diagnostics);
528
+ const result = formatEntries(prepared, options);
529
+ const output = (0, line_endings_js_1.applyLineEnding)(result.output, ending);
530
+ return {
531
+ output,
532
+ diagnostics: [...diagnostics, ...result.diagnostics],
533
+ changed: output !== markdown,
534
+ preservedRanges: (0, tab_markers_js_1.protectedTabRanges)((0, line_endings_js_1.normalizeLineEndings)(output).split("\n")),
535
+ };
536
+ }
537
+ /** Run the entry and prose passes after tab-marker admission. */
538
+ function formatEntries(markdown, options) {
377
539
  const file = options?.file ?? "<unknown>";
378
540
  // Detect the source file's line-ending convention up front so we can
379
541
  // restore it on write-back. The rest of the formatter operates on a
@@ -418,7 +580,11 @@ function format(markdown, options) {
418
580
  // Process bottom-to-top so line splicing doesn't shift earlier entries.
419
581
  const sorted = [...entries].sort((a, b) => b.location.line - a.location.line);
420
582
  const genUlid = options?.generateUlid ?? ulid_1.ulid;
583
+ const protectedRanges = (0, tab_markers_js_1.protectedTabRanges)(lines);
421
584
  for (const entry of sorted) {
585
+ if (protectedRanges.some((range) => entry.location.line - 1 >= range.start &&
586
+ entry.location.line - 1 < range.end))
587
+ continue;
422
588
  const indent = (0, entry_body_js_1.contentColumn)(lines[entry.location.line - 1] ?? "", entry.location.column - 1);
423
589
  // `entry.endLine` comes from the parse of the unedited buffer. Entries
424
590
  // are processed bottom to top, so only this entry's own edits move its
@@ -427,7 +593,14 @@ function format(markdown, options) {
427
593
  const itemEndFloor = () => entry.endLine === undefined
428
594
  ? 0
429
595
  : entry.endLine + (lines.length - lengthAtStart);
430
- let attrs = [...entry.rawAttributes];
596
+ const existingTrailer = protectedRanges.length > 0
597
+ ? findAttributeBlockRange(lines, entry.location.line, indent, itemEndFloor(), protectedRanges)
598
+ : undefined;
599
+ let attrs = protectedRanges.length > 0
600
+ ? existingTrailer
601
+ ? (0, attributes_js_1.parseAttributes)(lines.slice(existingTrailer.start, existingTrailer.end))
602
+ : []
603
+ : [...entry.rawAttributes];
431
604
  const titleLineIdx = entry.location.line - 1;
432
605
  // #686: a title that soft-wraps onto extra physical lines is a single
433
606
  // Markdown paragraph, but the line-based passes here and in
@@ -480,6 +653,14 @@ function format(markdown, options) {
480
653
  // input reproduces the same identity. Falls back to fresh random
481
654
  // when `Source:` is missing — synthesizing without a source pointer
482
655
  // makes no sense, but the formatter never fails a stamp.
656
+ // A trailer holding a line the attribute parser cannot read (a
657
+ // continuation of a value) is left exactly as it is: rewriting it
658
+ // would drop that line, and stamping an Id would replace the
659
+ // identity the author wrote. The parser reports the line as MSL-P021.
660
+ const trailerRange = findAttributeBlockRange(lines, entry.location.line, indent, itemEndFloor(), protectedRanges);
661
+ if (trailerRange &&
662
+ lines.slice(trailerRange.start, trailerRange.end).some((l) => l.trim() !== "" && !attributes_js_1.ATTR_LINE_RE.test(l.trim())))
663
+ continue;
483
664
  const hasIdentity = attrs.some((a) => a.key === mod_js_1.IDENTITY_KEY);
484
665
  if (!hasIdentity && entry.shape === "Authored") {
485
666
  const origin = attrs.find((a) => a.key === "Origin")?.value.trim();
@@ -523,13 +704,22 @@ function format(markdown, options) {
523
704
  if (attrs.length === 0)
524
705
  continue;
525
706
  const normalized = sortAttributes(expandCsvValues(attrs));
526
- const range = findAttributeBlockRange(lines, entry.location.line, indent, itemEndFloor());
707
+ const range = findAttributeBlockRange(lines, entry.location.line, indent, itemEndFloor(), protectedRanges);
527
708
  if (range) {
528
709
  // Replace existing attribute block.
529
710
  const newBlock = renderAttributeBlock(normalized, indent);
530
711
  const oldBlock = lines.slice(range.start, range.end).join("\n");
531
- if (newBlock !== oldBlock) {
532
- lines.splice(range.start, range.end - range.start, ...newBlock.split("\n"));
712
+ // A block directly under body prose (no blank line), indented or
713
+ // not, is not a code block in CommonMark: it continues the
714
+ // paragraph. The canonical layout separates it (#916). A line above
715
+ // that belongs to a preserved range (a refused child entry) is left
716
+ // as it is.
717
+ const above = range.start - 1;
718
+ const needsBlank = above > titleLineIdx &&
719
+ lines[above].trim() !== "" &&
720
+ !protectedRanges.some((r) => above >= r.start && above < r.end);
721
+ if (newBlock !== oldBlock || needsBlank) {
722
+ lines.splice(range.start, range.end - range.start, ...(needsBlank ? [""] : []), ...newBlock.split("\n"));
533
723
  changed = true;
534
724
  }
535
725
  }
@@ -582,7 +772,26 @@ function format(markdown, options) {
582
772
  end: findItemEnd(collapsedLines, start, entryIndent, e.endLine ?? 0),
583
773
  };
584
774
  });
585
- const prose = (0, prose_js_1.formatProseSegments)(collapsedLines, extents, proseFormat);
775
+ if ((0, tab_markers_js_1.tabMarkers)(collapsedLines).length > 0) {
776
+ // Title-only entry items are outside the entry index. Keep their list
777
+ // context too: isolated prose formatting can move adjacent entries.
778
+ const indexedStarts = new Set(proseEntries.map((entry) => entry.location.line - 1));
779
+ extents.push(...(0, tab_markers_js_1.entryListItems)(collapsedLines)
780
+ .filter((item) => !indexedStarts.has(item.start))
781
+ .map((item) => item.listContext));
782
+ extents.push(...(0, tab_markers_js_1.protectedTabRanges)(collapsedLines, true));
783
+ }
784
+ extents.sort((a, b) => a.start - b.start);
785
+ const merged = [];
786
+ for (const extent of extents) {
787
+ const previous = merged.at(-1);
788
+ if (previous && extent.start <= previous.end) {
789
+ previous.end = Math.max(previous.end, extent.end);
790
+ }
791
+ else
792
+ merged.push({ ...extent });
793
+ }
794
+ const prose = (0, prose_js_1.formatProseSegments)(collapsedLines, merged, proseFormat);
586
795
  if (prose.changed)
587
796
  changed = true;
588
797
  for (const fallback of prose.fallbacks) {
@@ -646,9 +855,11 @@ function renderFrontMatter(attrs) {
646
855
  function collapseBlankLines(lines) {
647
856
  const out = [];
648
857
  const fencedLines = (0, fence_js_1.fencedCodeLines)(lines.join("\n"));
858
+ const protectedRanges = (0, tab_markers_js_1.protectedTabRanges)(lines, true);
649
859
  let prevBlank = false;
650
860
  for (const [i, line] of lines.entries()) {
651
- if (fencedLines.has(i)) {
861
+ if (fencedLines.has(i) ||
862
+ protectedRanges.some((range) => i >= range.start && i < range.end)) {
652
863
  out.push(line);
653
864
  prevBlank = false;
654
865
  continue;
@@ -665,17 +876,23 @@ function collapseBlankLines(lines) {
665
876
  * Expand CSV values on repeatable-type attributes into one entry per value
666
877
  * per ADR-002 §2.6. `id-list` / `tag-list` / `external-id` accept CSV input
667
878
  * but must round-trip as multi-line output; `citation` is left alone
668
- * because locators may contain commas.
879
+ * because locators may contain commas. `id-list` values split with
880
+ * {@linkcode splitTraceValues}, so a comma inside a scenario locator does
881
+ * not split.
669
882
  */
670
883
  function expandCsvValues(attrs) {
671
884
  const result = [];
672
885
  for (const attr of attrs) {
673
886
  const spec = (0, mod_js_1.attributeSpec)(attr.key);
674
887
  if (spec && mod_js_1.CSV_SPLITTABLE_TYPES.has(spec.type) && attr.value.includes(",")) {
675
- const values = attr.value
676
- .split(",")
677
- .map((s) => s.trim())
678
- .filter((s) => s.length > 0);
888
+ // An id-list value keeps commas inside a bracket locator
889
+ // (`A [x, y], B`, #915); the locator text is kept as authored.
890
+ const values = spec.type === "id-list"
891
+ ? (0, split_js_1.splitTraceValues)(attr.value)
892
+ : attr.value
893
+ .split(",")
894
+ .map((s) => s.trim())
895
+ .filter((s) => s.length > 0);
679
896
  for (const value of values) {
680
897
  result.push({ key: attr.key, value });
681
898
  }
@@ -809,19 +1026,26 @@ function removeEmptyTrailerLines(body, entries, diagnostics) {
809
1026
  const lines = body.split("\n");
810
1027
  let removedAny = false;
811
1028
  const sorted = [...entries].sort((a, b) => b.location.line - a.location.line);
1029
+ const protectedRanges = (0, tab_markers_js_1.protectedTabRanges)(lines);
812
1030
  for (const entry of sorted) {
1031
+ if (protectedRanges.some((range) => entry.location.line - 1 >= range.start &&
1032
+ entry.location.line - 1 < range.end))
1033
+ continue;
813
1034
  const indent = (0, entry_body_js_1.contentColumn)(lines[entry.location.line - 1] ?? "", entry.location.column - 1);
814
1035
  const startIdx = entry.location.line - 1;
815
1036
  let end = findItemEnd(lines, startIdx, indent, entry.endLine ?? 0);
816
1037
  while (end > startIdx && lines[end - 1].trim() === "")
817
1038
  end--;
818
1039
  let start = end;
819
- while (start - 1 > startIdx && lines[start - 1].trim() !== "")
1040
+ while (start - 1 > startIdx && lines[start - 1].trim() !== "" &&
1041
+ !protectedRanges.some((range) => start - 1 >= range.start && start - 1 < range.end))
820
1042
  start--;
821
1043
  if (start >= end || start - 1 <= startIdx)
822
1044
  continue;
823
1045
  const trailerIndent = " ".repeat(indent + 4);
824
1046
  const block = lines.slice(start, end);
1047
+ if (protectedRanges.some((range) => range.start > startIdx && start < range.end && end > range.start))
1048
+ continue;
825
1049
  const isTrailerBlock = block.every((l) => l.startsWith(trailerIndent) && TRAILER_SHAPED_RE.test(l.trim()));
826
1050
  if (!isTrailerBlock)
827
1051
  continue;
@@ -856,9 +1080,26 @@ function removeEmptyTrailerLines(body, entries, diagnostics) {
856
1080
  * for an entry starting at the given line.
857
1081
  *
858
1082
  * Scans forward from the entry start to find the list item boundary,
859
- * then walks backwards to find the contiguous trailing attribute block.
1083
+ * then passes the entry content below the last preserved range, with the
1084
+ * list-item indent removed, to the parser's {@linkcode findTrailerStart}.
1085
+ * The formatter and the parser therefore agree on which lines are the
1086
+ * trailer, so `markspec fmt` never rewrites a line that the parser read as
1087
+ * body, and never drops an attribute line that the parser read (#916).
1088
+ * The LSP MSL-P023 quick fix uses it too.
1089
+ *
1090
+ * @param lines - Raw lines of the whole file.
1091
+ * @param entryStartLine - 1-based line of the entry's title (`- [ID] ...`).
1092
+ * @param indent - Content column of the list item: the 0-based column of
1093
+ * the `[` that opens the display ID.
1094
+ * @param itemEndFloor - Pass the parser's `Entry.endLine` (0 when unknown):
1095
+ * the item end scan starts no earlier than this line index, so a lazy
1096
+ * continuation line does not end the item early (see `findItemEnd`).
1097
+ * @param preservedRanges - Ranges inside the entry that are kept verbatim
1098
+ * (nested entries); the trailer is searched below the last one.
1099
+ * @returns The 0-based, half-open line range `[start, end)` of the trailer
1100
+ * over `lines`, or `undefined` when the entry has no trailer.
860
1101
  */
861
- function findAttributeBlockRange(lines, entryStartLine, indent, itemEndFloor = 0) {
1102
+ function findAttributeBlockRange(lines, entryStartLine, indent, itemEndFloor = 0, preservedRanges = []) {
862
1103
  const startIdx = entryStartLine - 1;
863
1104
  const itemEnd = findItemEnd(lines, startIdx, indent, itemEndFloor);
864
1105
  // Walk backwards from itemEnd, skip trailing blank lines.
@@ -868,19 +1109,18 @@ function findAttributeBlockRange(lines, entryStartLine, indent, itemEndFloor = 0
868
1109
  }
869
1110
  if (scanEnd <= startIdx)
870
1111
  return undefined;
871
- // Walk backwards collecting attribute lines.
872
- let attrStart = scanEnd;
873
- for (let i = scanEnd - 1; i > startIdx; i--) {
874
- const trimmed = lines[i].trim();
875
- if (trimmed === "")
876
- break;
877
- if (attributes_js_1.ATTR_LINE_RE.test(trimmed)) {
878
- attrStart = i;
879
- }
880
- else {
881
- break;
1112
+ // Content lines of the entry body, below the last preserved range, with
1113
+ // the list-item indent removed as the parser does. The shared trailer
1114
+ // detection decides where the attribute block starts (#916).
1115
+ let floor = startIdx + 1;
1116
+ for (let i = startIdx + 1; i < scanEnd; i++) {
1117
+ if (preservedRanges.some((range) => i >= range.start && i < range.end)) {
1118
+ floor = i + 1;
882
1119
  }
883
1120
  }
1121
+ const indentStr = " ".repeat(indent);
1122
+ const content = lines.slice(floor, scanEnd).map((l) => l.startsWith(indentStr) ? l.slice(indent) : l);
1123
+ const attrStart = floor + (0, attributes_js_1.findTrailerStart)(content);
884
1124
  if (attrStart >= scanEnd)
885
1125
  return undefined;
886
1126
  return { start: attrStart, end: scanEnd };
@@ -0,0 +1,15 @@
1
+ import type { EntryExtent } from "./prose.js";
2
+ /** An entry title and the list context that controls its indentation. */
3
+ export interface EntryListItem extends EntryExtent {
4
+ readonly column: number;
5
+ readonly whitespace: string;
6
+ readonly container: EntryExtent;
7
+ readonly listContext: EntryExtent;
8
+ }
9
+ /** Find actual unordered list items, excluding code, HTML, and task lists. */
10
+ export declare function entryListItems(lines: readonly string[]): EntryListItem[];
11
+ /** Find entry list items with a tab in the whitespace after the marker. */
12
+ export declare function tabMarkers(lines: readonly string[]): EntryListItem[];
13
+ /** Ranges kept out of every formatter pass after a tab rewrite is refused. */
14
+ export declare function protectedTabRanges(lines: readonly string[], preserveListContext?: boolean): EntryExtent[];
15
+ //# sourceMappingURL=tab_markers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tab_markers.d.ts","sourceRoot":"","sources":["../../src/formatter/tab_markers.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C,yEAAyE;AACzE,MAAM,WAAW,aAAc,SAAQ,WAAW;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CACnC;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,aAAa,EAAE,CAoFxE;AAED,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,aAAa,EAAE,CAKpE;AAED,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,mBAAmB,UAAQ,GAC1B,WAAW,EAAE,CA4Cf"}
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.entryListItems = entryListItems;
7
+ exports.tabMarkers = tabMarkers;
8
+ exports.protectedTabRanges = protectedTabRanges;
9
+ const unified_1 = require("unified");
10
+ const remark_parse_1 = __importDefault(require("remark-parse"));
11
+ const remark_gfm_1 = __importDefault(require("remark-gfm"));
12
+ const entry_body_js_1 = require("./entry_body.js");
13
+ const parser = (0, unified_1.unified)().use(remark_parse_1.default).use(remark_gfm_1.default);
14
+ /** Find actual unordered list items, excluding code, HTML, and task lists. */
15
+ function entryListItems(lines) {
16
+ const markers = [];
17
+ const visit = (node, container, enclosingList) => {
18
+ if (node.type === "list") {
19
+ for (const item of node.children) {
20
+ const outer = container ?? item;
21
+ const start = (item.position?.start.line ?? 1) - 1;
22
+ const column = (item.position?.start.column ?? 1) - 1;
23
+ const match = /^[-*+]([ \t]+)\[[^\]\s]+\](?:\s|$)/.exec((lines[start] ?? "").slice(column));
24
+ if (!node.ordered && item.checked == null && match &&
25
+ item.children[0]?.type === "paragraph") {
26
+ markers.push({
27
+ start,
28
+ end: item.position?.end.line ?? start + 1,
29
+ column,
30
+ whitespace: match[1],
31
+ container: {
32
+ start: (outer.position?.start.line ?? 1) - 1,
33
+ end: outer.position?.end.line ?? lines.length,
34
+ },
35
+ listContext: enclosingList ?? {
36
+ start: (node.position?.start.line ?? 1) - 1,
37
+ end: node.position?.end.line ?? lines.length,
38
+ },
39
+ });
40
+ }
41
+ for (const child of item.children) {
42
+ visit(child, outer, enclosingList ?? {
43
+ start: (node.position?.start.line ?? 1) - 1,
44
+ end: node.position?.end.line ?? lines.length,
45
+ });
46
+ }
47
+ }
48
+ }
49
+ else if ("children" in node) {
50
+ for (const [index, child] of node.children.entries()) {
51
+ let context = enclosingList;
52
+ if (!context && child.type === "list") {
53
+ // A marker change (for example `*` to `-`) splits adjacent
54
+ // items into separate mdast lists. Their indentation still
55
+ // affects admission of a tab rewrite across that boundary.
56
+ let first = index;
57
+ let last = index;
58
+ while (first > 0 && node.children[first - 1].type === "list")
59
+ first--;
60
+ while (node.children[last + 1]?.type === "list")
61
+ last++;
62
+ // Indented blocks after the list can move into an entry when its
63
+ // content column shrinks. Formatting them in isolation can remove
64
+ // that indentation and admit a refused rewrite on the next run.
65
+ // Keep complete blocks, including unindented lazy continuations.
66
+ const contentColumn = Math.min(...node.children.slice(first, last + 1).flatMap((sibling) => sibling.type === "list"
67
+ ? sibling.children.map((item) => (item.position?.start.column ?? 1) + 1)
68
+ : []));
69
+ while ((node.children[last + 1]?.position?.start.column ?? 0) >=
70
+ contentColumn)
71
+ last++;
72
+ context = {
73
+ start: (node.children[first].position?.start.line ?? 1) - 1,
74
+ end: node.children[last].position?.end.line ?? lines.length,
75
+ };
76
+ }
77
+ visit(child, container, context);
78
+ }
79
+ }
80
+ };
81
+ visit(parser.parse(lines.join("\n")));
82
+ return markers;
83
+ }
84
+ /** Find entry list items with a tab in the whitespace after the marker. */
85
+ function tabMarkers(lines) {
86
+ if (!lines.some((line) => /[-*+][ \t]*\t[ \t]*\[/.test(line)))
87
+ return [];
88
+ return entryListItems(lines).filter((marker) => marker.whitespace.includes("\t"));
89
+ }
90
+ /** Ranges kept out of every formatter pass after a tab rewrite is refused. */
91
+ function protectedTabRanges(lines, preserveListContext = false) {
92
+ const markers = tabMarkers(lines);
93
+ const items = markers.length > 0 ? entryListItems(lines) : [];
94
+ const ranges = markers.map((marker) => {
95
+ // A prose rewrite of a neighbouring item can make a refused marker
96
+ // eligible on the next run. Keep the containing list and the following
97
+ // indented blocks stable, even when CommonMark puts them outside it.
98
+ const range = preserveListContext ? marker.listContext : marker;
99
+ let start = range.start;
100
+ if (!preserveListContext && marker.column > 0) {
101
+ for (let i = start - 1; i >= marker.container.start; i--) {
102
+ if (lines[i].trim() === "")
103
+ continue;
104
+ if (!lines[i].startsWith(" ".repeat(marker.column)))
105
+ break;
106
+ if (/^[-*+][ \t]/.test(lines[i].slice(marker.column)))
107
+ start = i;
108
+ else if (!lines[i].startsWith(" ".repeat(marker.column + 2)))
109
+ break;
110
+ }
111
+ }
112
+ let end = range.end;
113
+ const nextEntry = items.find((item) => item.start > marker.start)?.start ??
114
+ lines.length;
115
+ const trailerIndent = " ".repeat((0, entry_body_js_1.contentColumn)(lines[marker.start], marker.column) + 4);
116
+ for (let i = end; i < nextEntry; i++) {
117
+ if (lines[i].trim() === "")
118
+ continue;
119
+ if (!lines[i].startsWith(" ".repeat(marker.column + 2)))
120
+ break;
121
+ // A less-indented trailer belongs to an enclosing space-marker entry.
122
+ if (/^[A-Z][A-Za-z-]*:(?:\s|$)/.test(lines[i].trim()) &&
123
+ !lines[i].startsWith(trailerIndent))
124
+ break;
125
+ end = i + 1;
126
+ }
127
+ while (end < lines.length && lines[end].trim() === "")
128
+ end++;
129
+ return { start, end };
130
+ });
131
+ const merged = [];
132
+ for (const range of ranges.sort((a, b) => a.start - b.start)) {
133
+ const previous = merged.at(-1);
134
+ if (previous && range.start <= previous.end) {
135
+ previous.end = Math.max(previous.end, range.end);
136
+ }
137
+ else
138
+ merged.push({ ...range });
139
+ }
140
+ return merged;
141
+ }
@@ -29,8 +29,8 @@ import { type LockEdge, type ParseLockfileResult, type ReadFile as LockReadFile
29
29
  * `fmt --check` never disagree on what "formatted" means. `MSL-F010` is pure
30
30
  * formatter drift; `MSL-F011` is reference-canonicalization drift (a ULID or
31
31
  * stale display ID `fmt` would rewrite) — kept distinct so the author knows
32
- * which fmt concern fired. Markdown only — `markspec fmt` never rewrites source
33
- * files, so the caller passes only Markdown file contents.
32
+ * which fmt concern fired. Markdown and `.feature` files only — `markspec fmt`
33
+ * never rewrites source files, so the caller passes only those file contents.
34
34
  *
35
35
  * @param mdContents Markdown file path → current on-disk content.
36
36
  * @param entries The full parsed entry set (project + corpus). Only
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/gates/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,QAAQ,IAAI,YAAY,EAE9B,MAAM,gBAAgB,CAAC;AAGxB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACvC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,MAAM,EAAE,SAAS,QAAQ,EAAE,EAC3B,mBAAmB,EAAE,cAAc,GAAG,SAAS,GAC9C,OAAO,CAAC,UAAU,EAAE,CAAC,CAwCvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,mBAAmB,EAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,KAAK,CAAC,EAAE;IAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,GACtE,OAAO,CAAC,UAAU,EAAE,CAAC,CAuCvB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GAAG,SAAS,GACpC,OAAO,CAAC,UAAU,EAAE,CAAC,CAQvB"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/gates/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAK3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,QAAQ,IAAI,YAAY,EAE9B,MAAM,gBAAgB,CAAC;AAGxB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACvC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,MAAM,EAAE,SAAS,QAAQ,EAAE,EAC3B,mBAAmB,EAAE,cAAc,GAAG,SAAS,GAC9C,OAAO,CAAC,UAAU,EAAE,CAAC,CAsDvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,mBAAmB,EAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,KAAK,CAAC,EAAE;IAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,GACtE,OAAO,CAAC,UAAU,EAAE,CAAC,CAuCvB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GAAG,SAAS,GACpC,OAAO,CAAC,UAAU,EAAE,CAAC,CAQvB"}
@@ -23,7 +23,9 @@ exports.fmtDriftGate = fmtDriftGate;
23
23
  exports.lockfileDriftGate = lockfileDriftGate;
24
24
  exports.proseLintGate = proseLintGate;
25
25
  const mod_js_1 = require("../model/mod.js");
26
+ const path_1 = require("@std/path");
26
27
  const mod_js_2 = require("../formatter/mod.js");
28
+ const feature_file_js_1 = require("../formatter/feature_file.js");
27
29
  const mod_js_3 = require("../parser/mod.js");
28
30
  const mod_js_4 = require("../refs/mod.js");
29
31
  const mod_js_5 = require("../lock/mod.js");
@@ -37,8 +39,8 @@ const mod_js_6 = require("../lint/mod.js");
37
39
  * `fmt --check` never disagree on what "formatted" means. `MSL-F010` is pure
38
40
  * formatter drift; `MSL-F011` is reference-canonicalization drift (a ULID or
39
41
  * stale display ID `fmt` would rewrite) — kept distinct so the author knows
40
- * which fmt concern fired. Markdown only — `markspec fmt` never rewrites source
41
- * files, so the caller passes only Markdown file contents.
42
+ * which fmt concern fired. Markdown and `.feature` files only — `markspec fmt`
43
+ * never rewrites source files, so the caller passes only those file contents.
42
44
  *
43
45
  * @param mdContents Markdown file path → current on-disk content.
44
46
  * @param entries The full parsed entry set (project + corpus). Only
@@ -60,6 +62,19 @@ async function fmtDriftGate(mdContents, entries, ledger, formatMarkdownProse) {
60
62
  // `emittableEntries` (upstream-only, #771); do not "unify" it.
61
63
  const refIndex = (0, mod_js_4.buildRefIndex)(entries.filter((e) => !(0, mod_js_1.isCorpusEntry)(e)));
62
64
  for (const [filePath, content] of mdContents) {
65
+ // A `.feature` file only drifts when a headed entry lacks its Id. It has
66
+ // no prose pass and no reference canonicalisation.
67
+ if ((0, path_1.extname)(filePath).toLowerCase() === ".feature") {
68
+ if ((await (0, feature_file_js_1.formatFeatureText)(content, filePath)).changed) {
69
+ diagnostics.push({
70
+ code: "MSL-F010",
71
+ severity: "error",
72
+ message: "file is not formatted (run `markspec fmt`)",
73
+ location: { file: filePath, line: 1, column: 1 },
74
+ });
75
+ }
76
+ continue;
77
+ }
63
78
  const formatted = (0, mod_js_2.format)(content, {
64
79
  file: filePath,
65
80
  formatMarkdownProse,
@@ -73,7 +88,7 @@ async function fmtDriftGate(mdContents, entries, ledger, formatMarkdownProse) {
73
88
  });
74
89
  }
75
90
  const parsed = await (0, mod_js_3.parseFile)(formatted.output, { file: filePath });
76
- const refResult = (0, mod_js_4.canonicalizeRefs)(formatted.output, parsed.entries, refIndex, ledger);
91
+ const refResult = (0, mod_js_4.canonicalizeRefs)(formatted.output, parsed.entries, refIndex, ledger, formatted.preservedRanges);
77
92
  if (refResult.changed) {
78
93
  diagnostics.push({
79
94
  code: "MSL-F011",