Repository navigation
Commit cff612f
committed
fix(format): stop deleting sections and duplicating labels
Two bugs, both of which made `lash format` unsafe to run on a file it did
not fully model.
`format_file` rebuilt the file from the parsed model alone, and the model
holds the header, the Description section and the task tree and nothing
else. Every other section was silently deleted: a file with `## Notes`
and `## References` came back with only the header and the tasks, exit
code 0, no warning. This turned out to be broader than filed. A section
*above* `## Tasks` went too, because the parser folds it into "overview"
text that `TaskFile` never stored and the formatter never emitted.
`format_file` now takes the source alongside the parsed file. It
regenerates only the spans it owns — the H1 plus annotation block, the
Description section, the Tasks section — and copies every other line
through unchanged. Section boundaries come from
`parser::header::section_span`, which runs through pulldown-cmark, so a
`##` inside a fenced code block neither opens nor closes a section.
Passing an empty source keeps the old model-only behaviour, which is what
the existing unit tests want.
The second bug: the parser records inline labels in metadata without
removing them from the title, and the formatter wrote both. Every run
appended another copy of every label, so `- [ ] one #docs` became
`#docs #docs` and then `#docs #docs #docs`, and `format --check` reported
the file as needing formatting forever. The formatter strips inline
labels from the title and writes the sorted metadata list as the only
place they appear. The parsed title keeps them, so `lash list` and search
behave as they do today.
Each generated block ends with its own blank separator and the source's
is skipped rather than copied. Emitting both would add a blank line per
run, which is the same non-idempotence in a different coat.
Tests: sections above and below `## Tasks` survive and keep their order,
a fenced heading does not split a section, labels are emitted once, an
already-canonical file comes back byte-identical, and an idempotence
property test over six shapes asserting `format(format(x)) ==
format(x)`. All six fail against the old behaviour.
Also ticks off three items in lash.index.md that were fixed in #34 and
#35 but never marked done.1 parent c6afbc7 commit cff612f
5 files changed
Lines changed: 391 additions & 92 deletions
File tree
- crates
- lash-cli/src/commands
- lash-core
- src
- formatter
- parser
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
350 | 355 | | |
351 | 356 | | |
352 | 357 | | |
353 | | - | |
| 358 | + | |
354 | 359 | | |
355 | 360 | | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | 361 | | |
361 | 362 | | |
362 | 363 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
128 | | - | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
132 | | - | |
| 133 | + | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
140 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
141 | 146 | | |
142 | 147 | | |
143 | | - | |
| 148 | + | |
144 | 149 | | |
145 | 150 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
150 | 163 | | |
151 | | - | |
152 | | - | |
| 164 | + | |
| 165 | + | |
153 | 166 | | |
154 | | - | |
155 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
156 | 183 | | |
157 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
158 | 197 | | |
159 | 198 | | |
160 | 199 | | |
161 | 200 | | |
162 | | - | |
| 201 | + | |
163 | 202 | | |
164 | 203 | | |
165 | 204 | | |
| |||
206 | 245 | | |
207 | 246 | | |
208 | 247 | | |
209 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
210 | 256 | | |
211 | 257 | | |
212 | 258 | | |
213 | | - | |
| 259 | + | |
214 | 260 | | |
215 | 261 | | |
216 | 262 | | |
| |||
525 | 571 | | |
526 | 572 | | |
527 | 573 | | |
528 | | - | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
529 | 583 | | |
530 | 584 | | |
531 | 585 | | |
532 | | - | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
533 | 589 | | |
534 | 590 | | |
535 | 591 | | |
| |||
679 | 735 | | |
680 | 736 | | |
681 | 737 | | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
682 | 752 | | |
683 | 753 | | |
684 | 754 | | |
| |||
779 | 849 | | |
780 | 850 | | |
781 | 851 | | |
782 | | - | |
| 852 | + | |
783 | 853 | | |
784 | 854 | | |
785 | 855 | | |
| |||
800 | 870 | | |
801 | 871 | | |
802 | 872 | | |
803 | | - | |
| 873 | + | |
804 | 874 | | |
805 | 875 | | |
806 | 876 | | |
| |||
822 | 892 | | |
823 | 893 | | |
824 | 894 | | |
825 | | - | |
| 895 | + | |
826 | 896 | | |
827 | 897 | | |
828 | 898 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
351 | | - | |
| 351 | + | |
352 | 352 | | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
358 | 358 | | |
359 | 359 | | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
364 | 363 | | |
365 | 364 | | |
366 | 365 | | |
367 | 366 | | |
368 | | - | |
| 367 | + | |
369 | 368 | | |
370 | 369 | | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
378 | 373 | | |
379 | 374 | | |
380 | | - | |
| 375 | + | |
381 | 376 | | |
382 | 377 | | |
383 | | - | |
384 | | - | |
| 378 | + | |
385 | 379 | | |
386 | 380 | | |
387 | 381 | | |
388 | 382 | | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
393 | 388 | | |
394 | 389 | | |
395 | 390 | | |
396 | 391 | | |
397 | 392 | | |
398 | 393 | | |
399 | | - | |
| 394 | + | |
400 | 395 | | |
401 | | - | |
| 396 | + | |
402 | 397 | | |
403 | | - | |
| 398 | + | |
| 399 | + | |
404 | 400 | | |
405 | 401 | | |
406 | 402 | | |
407 | 403 | | |
408 | 404 | | |
409 | 405 | | |
410 | 406 | | |
411 | | - | |
412 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
413 | 488 | | |
414 | 489 | | |
415 | 490 | | |
| |||
0 commit comments