@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.
Files changed (279) 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/criteria/scenarios.d.ts +55 -0
  15. package/esm/criteria/scenarios.d.ts.map +1 -0
  16. package/esm/criteria/scenarios.js +133 -0
  17. package/esm/discovery/mod.d.ts +20 -1
  18. package/esm/discovery/mod.d.ts.map +1 -1
  19. package/esm/discovery/mod.js +105 -17
  20. package/esm/formatter/entry_body.d.ts +8 -5
  21. package/esm/formatter/entry_body.d.ts.map +1 -1
  22. package/esm/formatter/entry_body.js +12 -8
  23. package/esm/formatter/feature_file.d.ts +40 -0
  24. package/esm/formatter/feature_file.d.ts.map +1 -0
  25. package/esm/formatter/feature_file.js +88 -0
  26. package/esm/formatter/mod.d.ts +21 -2
  27. package/esm/formatter/mod.d.ts.map +1 -1
  28. package/esm/formatter/mod.js +64 -22
  29. package/esm/gates/mod.d.ts +2 -2
  30. package/esm/gates/mod.d.ts.map +1 -1
  31. package/esm/gates/mod.js +17 -2
  32. package/esm/gherkin/load.d.ts +35 -0
  33. package/esm/gherkin/load.d.ts.map +1 -0
  34. package/esm/gherkin/load.js +39 -0
  35. package/esm/gherkin/parse.d.ts +11 -0
  36. package/esm/gherkin/parse.d.ts.map +1 -0
  37. package/esm/gherkin/parse.js +311 -0
  38. package/esm/gherkin/position.d.ts +23 -0
  39. package/esm/gherkin/position.d.ts.map +1 -0
  40. package/esm/gherkin/position.js +21 -0
  41. package/esm/gherkin/procedure.d.ts +76 -0
  42. package/esm/gherkin/procedure.d.ts.map +1 -0
  43. package/esm/gherkin/procedure.js +164 -0
  44. package/esm/gherkin/project.d.ts +35 -0
  45. package/esm/gherkin/project.d.ts.map +1 -0
  46. package/esm/gherkin/project.js +64 -0
  47. package/esm/gherkin/role.d.ts +23 -0
  48. package/esm/gherkin/role.d.ts.map +1 -0
  49. package/esm/gherkin/role.js +28 -0
  50. package/esm/gherkin/types.d.ts +118 -0
  51. package/esm/gherkin/types.d.ts.map +1 -0
  52. package/esm/gherkin/types.js +12 -0
  53. package/esm/lock/acquire_compile.d.ts +12 -4
  54. package/esm/lock/acquire_compile.d.ts.map +1 -1
  55. package/esm/lock/acquire_compile.js +15 -5
  56. package/esm/lock/canonical_edges.d.ts +6 -2
  57. package/esm/lock/canonical_edges.d.ts.map +1 -1
  58. package/esm/lock/canonical_edges.js +10 -3
  59. package/esm/lock/model.d.ts +5 -0
  60. package/esm/lock/model.d.ts.map +1 -1
  61. package/esm/lock/parser.d.ts.map +1 -1
  62. package/esm/lock/parser.js +2 -0
  63. package/esm/lock/resolve.d.ts +6 -2
  64. package/esm/lock/resolve.d.ts.map +1 -1
  65. package/esm/lock/resolve.js +36 -4
  66. package/esm/lock/serializer.d.ts.map +1 -1
  67. package/esm/lock/serializer.js +7 -1
  68. package/esm/mod.d.ts +23 -6
  69. package/esm/mod.d.ts.map +1 -1
  70. package/esm/mod.js +18 -5
  71. package/esm/model/mod.d.ts +42 -1
  72. package/esm/model/mod.d.ts.map +1 -1
  73. package/esm/model/mod.js +1 -1
  74. package/esm/model/relations.d.ts +9 -0
  75. package/esm/model/relations.d.ts.map +1 -1
  76. package/esm/model/relations.js +16 -1
  77. package/esm/parser/attributes.d.ts +82 -3
  78. package/esm/parser/attributes.d.ts.map +1 -1
  79. package/esm/parser/attributes.js +199 -32
  80. package/esm/parser/body_tokens.d.ts +1 -1
  81. package/esm/parser/body_tokens.d.ts.map +1 -1
  82. package/esm/parser/body_tokens.js +49 -35
  83. package/esm/parser/feature_file.d.ts +116 -0
  84. package/esm/parser/feature_file.d.ts.map +1 -0
  85. package/esm/parser/feature_file.js +540 -0
  86. package/esm/parser/markdown.d.ts +7 -0
  87. package/esm/parser/markdown.d.ts.map +1 -1
  88. package/esm/parser/markdown.js +129 -40
  89. package/esm/parser/mod.d.ts +18 -0
  90. package/esm/parser/mod.d.ts.map +1 -1
  91. package/esm/parser/mod.js +51 -0
  92. package/esm/parser/translate.d.ts.map +1 -1
  93. package/esm/parser/translate.js +5 -0
  94. package/esm/refs/mod.d.ts +2 -1
  95. package/esm/refs/mod.d.ts.map +1 -1
  96. package/esm/refs/mod.js +12 -4
  97. package/esm/refs/split.d.ts +58 -0
  98. package/esm/refs/split.d.ts.map +1 -0
  99. package/esm/refs/split.js +137 -0
  100. package/esm/reporter/mod.d.ts +7 -0
  101. package/esm/reporter/mod.d.ts.map +1 -1
  102. package/esm/reporter/mod.js +113 -3
  103. package/esm/validator/attributes.d.ts.map +1 -1
  104. package/esm/validator/attributes.js +4 -1
  105. package/esm/validator/block_role.d.ts +40 -0
  106. package/esm/validator/block_role.d.ts.map +1 -0
  107. package/esm/validator/block_role.js +109 -0
  108. package/esm/validator/feature_ac.d.ts.map +1 -1
  109. package/esm/validator/feature_ac.js +6 -1
  110. package/esm/validator/feature_parse.d.ts +35 -0
  111. package/esm/validator/feature_parse.d.ts.map +1 -0
  112. package/esm/validator/feature_parse.js +69 -0
  113. package/esm/validator/locators.d.ts +36 -0
  114. package/esm/validator/locators.d.ts.map +1 -0
  115. package/esm/validator/locators.js +184 -0
  116. package/esm/validator/mod.d.ts +10 -1
  117. package/esm/validator/mod.d.ts.map +1 -1
  118. package/esm/validator/mod.js +38 -14
  119. package/esm/validator/normalize.d.ts.map +1 -1
  120. package/esm/validator/normalize.js +8 -3
  121. package/esm/validator/per_type_attrs.d.ts +3 -3
  122. package/esm/validator/per_type_attrs.js +3 -3
  123. package/esm/validator/pipeline.d.ts +4 -12
  124. package/esm/validator/pipeline.d.ts.map +1 -1
  125. package/esm/validator/pipeline.js +24 -5
  126. package/esm/validator/procedure.d.ts +22 -0
  127. package/esm/validator/procedure.d.ts.map +1 -0
  128. package/esm/validator/procedure.js +58 -0
  129. package/esm/validator/trace_types.d.ts.map +1 -1
  130. package/esm/validator/trace_types.js +4 -3
  131. package/esm/validator/traceability.d.ts.map +1 -1
  132. package/esm/validator/traceability.js +4 -1
  133. package/esm/validator/type_resolution.d.ts +5 -3
  134. package/esm/validator/type_resolution.d.ts.map +1 -1
  135. package/esm/validator/type_resolution.js +14 -2
  136. package/esm/validator/types.d.ts +11 -0
  137. package/esm/validator/types.d.ts.map +1 -1
  138. package/esm/validator/types.js +26 -4
  139. package/esm/validator/uxil_family.d.ts +1 -1
  140. package/package.json +3 -1
  141. package/script/ast/build.d.ts.map +1 -1
  142. package/script/ast/build.js +19 -5
  143. package/script/ast/equivalence.js +14 -2
  144. package/script/ast/nodes.d.ts +15 -3
  145. package/script/ast/nodes.d.ts.map +1 -1
  146. package/script/compiler/inverses.d.ts.map +1 -1
  147. package/script/compiler/inverses.js +18 -3
  148. package/script/compiler/mod.d.ts +34 -1
  149. package/script/compiler/mod.d.ts.map +1 -1
  150. package/script/compiler/mod.js +110 -46
  151. package/script/compiler/schema.d.ts +3 -2
  152. package/script/compiler/schema.d.ts.map +1 -1
  153. package/script/compiler/schema.js +6 -3
  154. package/script/criteria/scenarios.d.ts +55 -0
  155. package/script/criteria/scenarios.d.ts.map +1 -0
  156. package/script/criteria/scenarios.js +139 -0
  157. package/script/discovery/mod.d.ts +20 -1
  158. package/script/discovery/mod.d.ts.map +1 -1
  159. package/script/discovery/mod.js +106 -17
  160. package/script/formatter/entry_body.d.ts +8 -5
  161. package/script/formatter/entry_body.d.ts.map +1 -1
  162. package/script/formatter/entry_body.js +12 -8
  163. package/script/formatter/feature_file.d.ts +40 -0
  164. package/script/formatter/feature_file.d.ts.map +1 -0
  165. package/script/formatter/feature_file.js +92 -0
  166. package/script/formatter/mod.d.ts +21 -2
  167. package/script/formatter/mod.d.ts.map +1 -1
  168. package/script/formatter/mod.js +63 -21
  169. package/script/gates/mod.d.ts +2 -2
  170. package/script/gates/mod.d.ts.map +1 -1
  171. package/script/gates/mod.js +17 -2
  172. package/script/gherkin/load.d.ts +35 -0
  173. package/script/gherkin/load.d.ts.map +1 -0
  174. package/script/gherkin/load.js +76 -0
  175. package/script/gherkin/parse.d.ts +11 -0
  176. package/script/gherkin/parse.d.ts.map +1 -0
  177. package/script/gherkin/parse.js +314 -0
  178. package/script/gherkin/position.d.ts +23 -0
  179. package/script/gherkin/position.d.ts.map +1 -0
  180. package/script/gherkin/position.js +24 -0
  181. package/script/gherkin/procedure.d.ts +76 -0
  182. package/script/gherkin/procedure.d.ts.map +1 -0
  183. package/script/gherkin/procedure.js +169 -0
  184. package/script/gherkin/project.d.ts +35 -0
  185. package/script/gherkin/project.d.ts.map +1 -0
  186. package/script/gherkin/project.js +67 -0
  187. package/script/gherkin/role.d.ts +23 -0
  188. package/script/gherkin/role.d.ts.map +1 -0
  189. package/script/gherkin/role.js +31 -0
  190. package/script/gherkin/types.d.ts +118 -0
  191. package/script/gherkin/types.d.ts.map +1 -0
  192. package/script/gherkin/types.js +13 -0
  193. package/script/lock/acquire_compile.d.ts +12 -4
  194. package/script/lock/acquire_compile.d.ts.map +1 -1
  195. package/script/lock/acquire_compile.js +15 -5
  196. package/script/lock/canonical_edges.d.ts +6 -2
  197. package/script/lock/canonical_edges.d.ts.map +1 -1
  198. package/script/lock/canonical_edges.js +10 -3
  199. package/script/lock/model.d.ts +5 -0
  200. package/script/lock/model.d.ts.map +1 -1
  201. package/script/lock/parser.d.ts.map +1 -1
  202. package/script/lock/parser.js +2 -0
  203. package/script/lock/resolve.d.ts +6 -2
  204. package/script/lock/resolve.d.ts.map +1 -1
  205. package/script/lock/resolve.js +36 -4
  206. package/script/lock/serializer.d.ts.map +1 -1
  207. package/script/lock/serializer.js +7 -1
  208. package/script/mod.d.ts +23 -6
  209. package/script/mod.d.ts.map +1 -1
  210. package/script/mod.js +45 -6
  211. package/script/model/mod.d.ts +42 -1
  212. package/script/model/mod.d.ts.map +1 -1
  213. package/script/model/mod.js +2 -1
  214. package/script/model/relations.d.ts +9 -0
  215. package/script/model/relations.d.ts.map +1 -1
  216. package/script/model/relations.js +17 -1
  217. package/script/parser/attributes.d.ts +82 -3
  218. package/script/parser/attributes.d.ts.map +1 -1
  219. package/script/parser/attributes.js +205 -33
  220. package/script/parser/body_tokens.d.ts +1 -1
  221. package/script/parser/body_tokens.d.ts.map +1 -1
  222. package/script/parser/body_tokens.js +49 -35
  223. package/script/parser/feature_file.d.ts +116 -0
  224. package/script/parser/feature_file.d.ts.map +1 -0
  225. package/script/parser/feature_file.js +548 -0
  226. package/script/parser/markdown.d.ts +7 -0
  227. package/script/parser/markdown.d.ts.map +1 -1
  228. package/script/parser/markdown.js +128 -39
  229. package/script/parser/mod.d.ts +18 -0
  230. package/script/parser/mod.d.ts.map +1 -1
  231. package/script/parser/mod.js +52 -1
  232. package/script/parser/translate.d.ts.map +1 -1
  233. package/script/parser/translate.js +5 -0
  234. package/script/refs/mod.d.ts +2 -1
  235. package/script/refs/mod.d.ts.map +1 -1
  236. package/script/refs/mod.js +12 -4
  237. package/script/refs/split.d.ts +58 -0
  238. package/script/refs/split.d.ts.map +1 -0
  239. package/script/refs/split.js +145 -0
  240. package/script/reporter/mod.d.ts +7 -0
  241. package/script/reporter/mod.d.ts.map +1 -1
  242. package/script/reporter/mod.js +113 -3
  243. package/script/validator/attributes.d.ts.map +1 -1
  244. package/script/validator/attributes.js +4 -1
  245. package/script/validator/block_role.d.ts +40 -0
  246. package/script/validator/block_role.d.ts.map +1 -0
  247. package/script/validator/block_role.js +112 -0
  248. package/script/validator/feature_ac.d.ts.map +1 -1
  249. package/script/validator/feature_ac.js +6 -1
  250. package/script/validator/feature_parse.d.ts +35 -0
  251. package/script/validator/feature_parse.d.ts.map +1 -0
  252. package/script/validator/feature_parse.js +73 -0
  253. package/script/validator/locators.d.ts +36 -0
  254. package/script/validator/locators.d.ts.map +1 -0
  255. package/script/validator/locators.js +188 -0
  256. package/script/validator/mod.d.ts +10 -1
  257. package/script/validator/mod.d.ts.map +1 -1
  258. package/script/validator/mod.js +38 -14
  259. package/script/validator/normalize.d.ts.map +1 -1
  260. package/script/validator/normalize.js +8 -3
  261. package/script/validator/per_type_attrs.d.ts +3 -3
  262. package/script/validator/per_type_attrs.js +3 -3
  263. package/script/validator/pipeline.d.ts +4 -12
  264. package/script/validator/pipeline.d.ts.map +1 -1
  265. package/script/validator/pipeline.js +23 -5
  266. package/script/validator/procedure.d.ts +22 -0
  267. package/script/validator/procedure.d.ts.map +1 -0
  268. package/script/validator/procedure.js +61 -0
  269. package/script/validator/trace_types.d.ts.map +1 -1
  270. package/script/validator/trace_types.js +4 -3
  271. package/script/validator/traceability.d.ts.map +1 -1
  272. package/script/validator/traceability.js +4 -1
  273. package/script/validator/type_resolution.d.ts +5 -3
  274. package/script/validator/type_resolution.d.ts.map +1 -1
  275. package/script/validator/type_resolution.js +14 -2
  276. package/script/validator/types.d.ts +11 -0
  277. package/script/validator/types.d.ts.map +1 -1
  278. package/script/validator/types.js +27 -4
  279. package/script/validator/uxil_family.d.ts +1 -1
@@ -19,8 +19,9 @@
19
19
  * Node-compatible; entry points supply the Deno implementation.
20
20
  */
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.RELEVANT_EXTENSIONS = exports.MARKDOWN_EXTENSIONS = exports.SOURCE_EXTENSIONS = exports.parseGitignore = exports.isIgnored = void 0;
22
+ exports.RELEVANT_EXTENSIONS = exports.FEATURE_EXTENSIONS = exports.MARKDOWN_EXTENSIONS = exports.SOURCE_EXTENSIONS = exports.parseGitignore = exports.isIgnored = void 0;
23
23
  exports.discoverFiles = discoverFiles;
24
+ exports.isDiscoverable = isDiscoverable;
24
25
  const path_1 = require("@std/path");
25
26
  const gitignore_js_1 = require("./gitignore.js");
26
27
  var gitignore_js_2 = require("./gitignore.js");
@@ -53,10 +54,17 @@ exports.SOURCE_EXTENSIONS = new Set([
53
54
  ]);
54
55
  /** Markdown only — the `fmt` scope (the formatter never rewrites source). */
55
56
  exports.MARKDOWN_EXTENSIONS = new Set([".md"]);
56
- /** Everything MarkSpec-relevant: markdown + source families. */
57
+ /**
58
+ * Gherkin `.feature` files, whose `# [ID]` header comments define entries
59
+ * (ADR-038). Not part of {@linkcode SOURCE_EXTENSIONS}: that set drives the
60
+ * tree-sitter grammars and the LSP, and `.feature` files use neither.
61
+ */
62
+ exports.FEATURE_EXTENSIONS = new Set([".feature"]);
63
+ /** Everything MarkSpec-relevant: markdown, source and `.feature` files. */
57
64
  exports.RELEVANT_EXTENSIONS = new Set([
58
65
  ...exports.MARKDOWN_EXTENSIONS,
59
66
  ...exports.SOURCE_EXTENSIONS,
67
+ ...exports.FEATURE_EXTENSIONS,
60
68
  ]);
61
69
  /**
62
70
  * Directory names pruned by default, in addition to the hidden-dir skip.
@@ -88,16 +96,104 @@ const BUILTIN_SKIP_RULES = (0, gitignore_js_1.parseGitignore)(BUILTIN_SKIP_DIRS.
88
96
  */
89
97
  async function* discoverFiles(root, io, options = {}) {
90
98
  const extensions = options.extensions ?? exports.RELEVANT_EXTENSIONS;
99
+ const start = await walkStart(root, io, options);
100
+ // Carry excludes separately: they must stay after every `.gitignore`,
101
+ // including ones loaded deeper in the walk.
102
+ yield* walk(root, start.prefix, start.rules, start.excludeRules, io, extensions);
103
+ }
104
+ /**
105
+ * Report whether {@linkcode discoverFiles} with the same `root`, `io` and
106
+ * `options` would yield `path`. It applies the same rules as the walk: the
107
+ * extension filter, hidden directories, the built-in build-output skips, the
108
+ * `.gitignore` chain and `exclude`. It checks the directories from `root`
109
+ * down to the file, so a file under an ignored directory is not included.
110
+ * The file must exist as a regular file: a path that does not exist, a
111
+ * symbolic link, and a path outside `root` are not included. It lists every
112
+ * ancestor directory of the file, so it is meant for per-file checks, not
113
+ * bulk use. It compares paths as given: case and symbolic links in the
114
+ * directories above the file are not resolved.
115
+ */
116
+ async function isDiscoverable(path, root, io, options = {}) {
117
+ const extensions = options.extensions ?? exports.RELEVANT_EXTENSIONS;
118
+ if (!isRelevantFile(path, extensions))
119
+ return false;
120
+ const rel = (0, path_1.relative)((0, path_1.resolve)(root), (0, path_1.resolve)(path));
121
+ if (rel === "" || rel === ".." || rel.startsWith(`..${path_1.SEPARATOR}`) ||
122
+ (0, path_1.isAbsolute)(rel)) {
123
+ return false;
124
+ }
125
+ const segments = rel.split(path_1.SEPARATOR);
126
+ const start = await walkStart(root, io, options);
127
+ let rules = start.rules;
128
+ let absDir = root;
129
+ let relDir = start.prefix;
130
+ for (let i = 0; i < segments.length; i++) {
131
+ const gitignoreRules = await rulesForDirectory(absDir, relDir, rules, io);
132
+ const active = [...gitignoreRules, ...start.excludeRules];
133
+ const name = segments[i];
134
+ const entryRel = relDir === "" ? name : `${relDir}/${name}`;
135
+ const isLast = i === segments.length - 1;
136
+ // The walk yields only entries that report isFile or isDirectory, so a
137
+ // symbolic link, or a path that does not exist, is not discoverable.
138
+ const kind = await entryKind(absDir, name, io);
139
+ if (isLast ? kind !== "file" : kind !== "directory")
140
+ return false;
141
+ if (isLast)
142
+ return !(0, gitignore_js_1.isIgnored)(entryRel, false, active);
143
+ if (isPrunedDirectory(name, entryRel, active))
144
+ return false;
145
+ rules = gitignoreRules;
146
+ absDir = (0, path_1.join)(absDir, name);
147
+ relDir = entryRel;
148
+ }
149
+ return false;
150
+ }
151
+ /** The kind of the entry `name` in `absDir`, as the walk sees it. */
152
+ async function entryKind(absDir, name, io) {
153
+ try {
154
+ for await (const e of io.readDir(absDir)) {
155
+ if (e.name !== name)
156
+ continue;
157
+ return e.isDirectory ? "directory" : e.isFile ? "file" : undefined;
158
+ }
159
+ }
160
+ catch {
161
+ // An unreadable directory is skipped by the walk.
162
+ }
163
+ return undefined;
164
+ }
165
+ /** The starting rule state of a walk of `root`, shared by the walk and
166
+ * {@linkcode isDiscoverable}. `prefix` is the path of `root` below the
167
+ * folder the rules are anchored at. */
168
+ async function walkStart(root, io, options) {
91
169
  const inherited = options.inheritGitignoreFrom === undefined
92
170
  ? { rules: [], prefix: "" }
93
171
  : await inheritedGitignoreRules(options.inheritGitignoreFrom, root, io);
94
172
  // With inherited rules, every rule is matched against paths relative to
95
173
  // the enclosing folder, so `prefix` is the path from it down to `root`.
96
- const prefix = inherited.prefix;
97
- const excludeRules = (0, gitignore_js_1.parseGitignore)((options.exclude ?? []).join("\n"), prefix);
98
- // Carry excludes separately: they must stay after every `.gitignore`,
99
- // including ones loaded deeper in the walk.
100
- yield* walk(root, prefix, [...BUILTIN_SKIP_RULES, ...inherited.rules], excludeRules, io, extensions);
174
+ return {
175
+ prefix: inherited.prefix,
176
+ rules: [...BUILTIN_SKIP_RULES, ...inherited.rules],
177
+ excludeRules: (0, gitignore_js_1.parseGitignore)((options.exclude ?? []).join("\n"), inherited.prefix),
178
+ };
179
+ }
180
+ /** `true` when a file has one of the `extensions`. */
181
+ function isRelevantFile(path, extensions) {
182
+ return extensions.has((0, path_1.extname)(path).toLowerCase());
183
+ }
184
+ /** `true` when the walk does not enter a directory: hidden, or ignored.
185
+ * Git semantics: paths under an ignored directory cannot be re-included, so
186
+ * pruning is correct. */
187
+ function isPrunedDirectory(name, rel, active) {
188
+ return name.startsWith(".") || (0, gitignore_js_1.isIgnored)(rel, true, active);
189
+ }
190
+ /** The `.gitignore` rules in force inside `absDir`: the inherited `rules`
191
+ * followed by the directory's own `.gitignore`, so deeper rules win. */
192
+ async function rulesForDirectory(absDir, relDir, rules, io) {
193
+ const raw = await io.readFile((0, path_1.join)(absDir, ".gitignore"));
194
+ return raw !== undefined && raw.length > 0
195
+ ? [...rules, ...(0, gitignore_js_1.parseGitignore)(raw, relDir)]
196
+ : rules;
101
197
  }
102
198
  /**
103
199
  * Collect the `.gitignore` rules of the folders from `from` down to the
@@ -128,10 +224,7 @@ async function inheritedGitignoreRules(from, root, io) {
128
224
  async function* walk(absDir, relDir, rules, excludeRules, io, extensions) {
129
225
  // Deeper `.gitignore` rules win over inherited ones. Excludes stay last
130
226
  // for this directory's decisions, but are not inherited as gitignore rules.
131
- const raw = await io.readFile((0, path_1.join)(absDir, ".gitignore"));
132
- const gitignoreRules = raw !== undefined && raw.length > 0
133
- ? [...rules, ...(0, gitignore_js_1.parseGitignore)(raw, relDir)]
134
- : rules;
227
+ const gitignoreRules = await rulesForDirectory(absDir, relDir, rules, io);
135
228
  const active = [...gitignoreRules, ...excludeRules];
136
229
  const entries = [];
137
230
  try {
@@ -145,16 +238,12 @@ async function* walk(absDir, relDir, rules, excludeRules, io, extensions) {
145
238
  for (const entry of entries) {
146
239
  const rel = relDir === "" ? entry.name : `${relDir}/${entry.name}`;
147
240
  if (entry.isDirectory) {
148
- if (entry.name.startsWith("."))
149
- continue; // built-in: hidden dirs
150
- // Git semantics: paths under an ignored directory cannot be
151
- // re-included, so pruning here is correct (and fast).
152
- if ((0, gitignore_js_1.isIgnored)(rel, true, active))
241
+ if (isPrunedDirectory(entry.name, rel, active))
153
242
  continue;
154
243
  yield* walk((0, path_1.join)(absDir, entry.name), rel, gitignoreRules, excludeRules, io, extensions);
155
244
  }
156
245
  else if (entry.isFile) {
157
- if (!extensions.has((0, path_1.extname)(entry.name).toLowerCase()))
246
+ if (!isRelevantFile(entry.name, extensions))
158
247
  continue;
159
248
  if ((0, gitignore_js_1.isIgnored)(rel, false, active))
160
249
  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 paragraph starts with a recognized trailer key, so such an
78
- * entry is refused too. The file already fails `markspec check` there.
79
- * An entry whose trailer-looking lines use only unrecognized keys, and
80
- * that the parser reads as body without a diagnostic, is edited as the
81
- * parser sees it: those lines are body.
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;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"}
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"}
@@ -176,11 +176,14 @@ function dedent(line, indent) {
176
176
  * before or after the edit. So the edit is refused when an `MSL-P020`,
177
177
  * `MSL-P021` or `MSL-P022` names the entry (the message starts with
178
178
  * `<displayId>:`). This is broader than that case: `MSL-P020` also fires
179
- * when a body paragraph starts with a recognized trailer key, so such an
180
- * entry is refused too. The file already fails `markspec check` there.
181
- * An entry whose trailer-looking lines use only unrecognized keys, and
182
- * that the parser reads as body without a diagnostic, is edited as the
183
- * parser sees it: those lines are body.
179
+ * when a body `Id:` or trace-relation line has other content after it,
180
+ * when an `Id:` run sits directly under prose (warning), and when a
181
+ * trailing trace-relation line is body prose (warning), so such an entry
182
+ * is refused too. An entry whose trailer-looking lines the parser reads as
183
+ * body without a diagnostic (for example `Note:` lines, or `Status:`
184
+ * directly under prose) is edited as the parser sees it: those lines are
185
+ * body. A final paragraph of only core keys after a blank line, such as a
186
+ * lone `Rationale:` line, is the trailer, not body.
184
187
  */
185
188
  async function replaceEntryBody(text, file, displayId, body) {
186
189
  const before = await locate(text, file, displayId);
@@ -277,9 +280,10 @@ function sameEntries(before, after, target, targetAfter) {
277
280
  * blank line between them, raises no diagnostic; the parser keeps it as
278
281
  * body text and adds no entry, so the edit is accepted.
279
282
  *
280
- * Known limit: the parser raises at most one MSL-P020 per entry, so when
281
- * the target body already has a trailer-like line, a proposal that adds
282
- * more such lines raises no new MSL-P020 and is accepted. The lines stay
283
+ * Known limit: the body scan raises at most one MSL-P020 per entry (the
284
+ * under-prose warning can add a second one), so when the target body
285
+ * already has a trailer-like line, a proposal that adds more such lines
286
+ * raises no new MSL-P020 and is accepted. The lines stay
283
287
  * body text; no trailer or entry changes.
284
288
  */
285
289
  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,92 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/formatter/feature_file
4
+ *
5
+ * Write-back for `.feature` files (epic #915, Case B). The only change
6
+ * `fmt` makes is to insert a missing `# Id: <ULID>` line into the header
7
+ * comment of a headed entry. Gherkin text, other comments and line endings
8
+ * stay as they are. The Markdown entry formatter and the ADR-029 prose pass
9
+ * never run on `.feature` text.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.formatFeatureFile = formatFeatureFile;
13
+ exports.formatFeatureText = formatFeatureText;
14
+ const ulid_1 = require("@std/ulid");
15
+ const mod_js_1 = require("../parser/mod.js");
16
+ const feature_file_js_1 = require("../parser/feature_file.js");
17
+ const line_endings_js_1 = require("../util/line_endings.js");
18
+ /** Leading whitespace, `#`, and the spaces after it. */
19
+ const COMMENT_PREFIX_RE = /^(\s*#[ \t]*)/;
20
+ /** `true` when `line` is a comment line. */
21
+ function isComment(line) {
22
+ return line !== undefined && line.trimStart().startsWith("#");
23
+ }
24
+ /**
25
+ * Insert a missing `# Id: <ULID>` line into the header of each entry of a
26
+ * `.feature` file.
27
+ *
28
+ * The line goes before the first trailer line, with that line's comment
29
+ * prefix, so it matches the header's indentation and trailer spacing. A
30
+ * header without a trailer gets a `#` line (unless its last line is already
31
+ * an empty comment) and then the Id line, at the end of the header. An entry
32
+ * that has an Id, and every other part of the file, is left unchanged.
33
+ *
34
+ * @param text - The file text (LF or CRLF).
35
+ * @param entries - The entries parsed from `text`.
36
+ * @param generateUlid - ULID generator.
37
+ */
38
+ function formatFeatureFile(text, entries, generateUlid = ulid_1.ulid) {
39
+ const ending = (0, line_endings_js_1.detectLineEnding)(text);
40
+ const lines = (0, line_endings_js_1.normalizeLineEndings)(text).split("\n");
41
+ const missing = entries
42
+ .filter((e) => e.source.kind === "feature-file" && e.id === undefined &&
43
+ e.shape === "Authored")
44
+ .sort((a, b) => b.location.line - a.location.line);
45
+ if (missing.length === 0)
46
+ return { output: text, changed: false };
47
+ let changed = false;
48
+ for (const entry of missing) {
49
+ const titleIdx = entry.location.line - 1;
50
+ if (!isComment(lines[titleIdx]))
51
+ continue;
52
+ // End of the header run: consecutive comment lines, up to the next
53
+ // header start or a `# language:` line.
54
+ const endIdx = (0, feature_file_js_1.featureHeaderRunEnd)(lines, titleIdx) - 1;
55
+ const firstTrailer = entry.attributeLines?.[0];
56
+ const trailerIdx = firstTrailer === undefined
57
+ ? undefined
58
+ : firstTrailer - 1;
59
+ if (trailerIdx !== undefined && trailerIdx > titleIdx &&
60
+ trailerIdx <= endIdx) {
61
+ const prefix = COMMENT_PREFIX_RE.exec(lines[trailerIdx])[1];
62
+ lines.splice(trailerIdx, 0, `${prefix}Id: ${generateUlid()}`);
63
+ }
64
+ else {
65
+ const indent = /^\s*/.exec(lines[titleIdx])[0];
66
+ const added = [];
67
+ if (lines[endIdx].trim() !== "#")
68
+ added.push(`${indent}#`);
69
+ added.push(`${indent}# Id: ${generateUlid()}`);
70
+ lines.splice(endIdx + 1, 0, ...added);
71
+ }
72
+ changed = true;
73
+ }
74
+ if (!changed)
75
+ return { output: text, changed: false };
76
+ return {
77
+ output: (0, line_endings_js_1.applyLineEnding)(lines.join("\n"), ending),
78
+ changed: true,
79
+ };
80
+ }
81
+ /**
82
+ * Parse a `.feature` file and stamp the missing Ids of its entries. A file
83
+ * that does not parse has no entries, so it comes back unchanged.
84
+ *
85
+ * @param text - The file text.
86
+ * @param file - File path, used for parsing and diagnostics.
87
+ * @param generateUlid - ULID generator.
88
+ */
89
+ async function formatFeatureText(text, file, generateUlid = ulid_1.ulid) {
90
+ const { entries } = await (0, mod_js_1.parseFile)(text, { file });
91
+ return formatFeatureFile(text, entries, generateUlid);
92
+ }
@@ -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 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.
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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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"}
@@ -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");
@@ -516,6 +517,11 @@ function normalizeTabMarkers(markdown, options, diagnostics) {
516
517
  * @returns Format result with output text and diagnostics
517
518
  */
518
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
+ }
519
525
  const diagnostics = [];
520
526
  const ending = (0, line_endings_js_1.detectLineEnding)(markdown);
521
527
  const prepared = normalizeTabMarkers((0, line_endings_js_1.normalizeLineEndings)(markdown), options, diagnostics);
@@ -647,6 +653,14 @@ function formatEntries(markdown, options) {
647
653
  // input reproduces the same identity. Falls back to fresh random
648
654
  // when `Source:` is missing — synthesizing without a source pointer
649
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;
650
664
  const hasIdentity = attrs.some((a) => a.key === mod_js_1.IDENTITY_KEY);
651
665
  if (!hasIdentity && entry.shape === "Authored") {
652
666
  const origin = attrs.find((a) => a.key === "Origin")?.value.trim();
@@ -695,8 +709,17 @@ function formatEntries(markdown, options) {
695
709
  // Replace existing attribute block.
696
710
  const newBlock = renderAttributeBlock(normalized, indent);
697
711
  const oldBlock = lines.slice(range.start, range.end).join("\n");
698
- if (newBlock !== oldBlock) {
699
- 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"));
700
723
  changed = true;
701
724
  }
702
725
  }
@@ -853,17 +876,23 @@ function collapseBlankLines(lines) {
853
876
  * Expand CSV values on repeatable-type attributes into one entry per value
854
877
  * per ADR-002 §2.6. `id-list` / `tag-list` / `external-id` accept CSV input
855
878
  * but must round-trip as multi-line output; `citation` is left alone
856
- * 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.
857
882
  */
858
883
  function expandCsvValues(attrs) {
859
884
  const result = [];
860
885
  for (const attr of attrs) {
861
886
  const spec = (0, mod_js_1.attributeSpec)(attr.key);
862
887
  if (spec && mod_js_1.CSV_SPLITTABLE_TYPES.has(spec.type) && attr.value.includes(",")) {
863
- const values = attr.value
864
- .split(",")
865
- .map((s) => s.trim())
866
- .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);
867
896
  for (const value of values) {
868
897
  result.push({ key: attr.key, value });
869
898
  }
@@ -1051,7 +1080,24 @@ function removeEmptyTrailerLines(body, entries, diagnostics) {
1051
1080
  * for an entry starting at the given line.
1052
1081
  *
1053
1082
  * Scans forward from the entry start to find the list item boundary,
1054
- * 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.
1055
1101
  */
1056
1102
  function findAttributeBlockRange(lines, entryStartLine, indent, itemEndFloor = 0, preservedRanges = []) {
1057
1103
  const startIdx = entryStartLine - 1;
@@ -1063,22 +1109,18 @@ function findAttributeBlockRange(lines, entryStartLine, indent, itemEndFloor = 0
1063
1109
  }
1064
1110
  if (scanEnd <= startIdx)
1065
1111
  return undefined;
1066
- // Walk backwards collecting attribute lines.
1067
- let attrStart = scanEnd;
1068
- for (let i = scanEnd - 1; i > startIdx; i--) {
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++) {
1069
1117
  if (preservedRanges.some((range) => i >= range.start && i < range.end)) {
1070
- break;
1071
- }
1072
- const trimmed = lines[i].trim();
1073
- if (trimmed === "")
1074
- break;
1075
- if (attributes_js_1.ATTR_LINE_RE.test(trimmed)) {
1076
- attrStart = i;
1077
- }
1078
- else {
1079
- break;
1118
+ floor = i + 1;
1080
1119
  }
1081
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);
1082
1124
  if (attrStart >= scanEnd)
1083
1125
  return undefined;
1084
1126
  return { start: attrStart, end: scanEnd };
@@ -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,CAyCvB;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,