Commit adc8d7e
committed
fix: preserve indent if possible
It's possible to preserve the indent in the original yaml when
we Unmarshal to a yaml.Node, and the structure of the original
yaml allows us to guess the indent.
The two easiest cases are when we have a nested block-style mapping,
or a sequence inside a mapping and the sequence is indented. For
those, the node tells us the parsed column (starting at 1) and we
use that indent.
However: if we parse to some other data structure (as we do with
Kustomize) or the original yaml has some structure where the indentation
is unclear, eg:
root:
- unguessable indent
- deeper:
guessable: but requires deeper traversal
... then we just guess '2'.
This should generate _fewer_ useless whitespace changes, but cannot
prevent them all.
Signed-off-by: Brian Ewins <bewins@nerdwallet.com>1 parent b49a6c3 commit adc8d7e
2 files changed
+89
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
| 426 | + | |
426 | 427 | | |
427 | 428 | | |
428 | 429 | | |
| |||
433 | 434 | | |
434 | 435 | | |
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 | + | |
436 | 461 | | |
437 | 462 | | |
438 | 463 | | |
| |||
479 | 504 | | |
480 | 505 | | |
481 | 506 | | |
| 507 | + | |
482 | 508 | | |
483 | 509 | | |
484 | 510 | | |
| |||
520 | 546 | | |
521 | 547 | | |
522 | 548 | | |
523 | | - | |
| 549 | + | |
524 | 550 | | |
525 | 551 | | |
526 | 552 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2439 | 2439 | | |
2440 | 2440 | | |
2441 | 2441 | | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
| 2500 | + | |
| 2501 | + | |
| 2502 | + | |
| 2503 | + | |
2442 | 2504 | | |
2443 | 2505 | | |
2444 | 2506 | | |
| |||
0 commit comments