Add keepIndent option to toString #654
Open
+149
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[wip]
I believe this fixes #283 by adding a
keepIndentoption to toString.I temporarily enabled this
keepIndent+keepSourceTokenon by default and ran all the tests and it seems to work.Alternatively, indent could be an optional property on the AST, which is maybe better in theory but also leads to some odd situations. Another alternative to this implementation might be something more general like
keepSourceFormattingwhere in addition to formatting changes, we would attempt to keep more formatting e.g. in multiline flow text we wouldn't re-fold text if sourceToken exists.This would be really helpful for us at Stainless, as we apply "transforms" to a yaml file, but also need to textually diff the original yaml file against the transformed file to show changes to our users. Spurius diffs make this process really difficult to inspect.
And while I'm at it just want to say thank you for your work on this library, much of my work at Stainles would just not be possible without it. Diffing, transforming, adding comments, etc. to yaml files are a core part of what we do, and we use this library for things like just parsing YAML, analyzing source in our language server, showing great diffs in our transforms product, and so, so many more things.