Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a mode which preserves carriage returns #2

Open
nedtwigg opened this issue Aug 9, 2023 · 0 comments
Open

Add a mode which preserves carriage returns #2

nedtwigg opened this issue Aug 9, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@nedtwigg
Copy link
Member

nedtwigg commented Aug 9, 2023

Here are two important properties of the .ss snapshot files:

  • exactly character-for-character accurate, no slop around leading or trailing whitespace, no forbidden characters
  • what you see in the snapshot file is exactly what you get, except for the following escaping rules which preserve the above
    • the following characters are escaped: 𐝃 -> 𐝃𐝃, 𐝁 -> 𐝃𐝁 (they are from an untranslated dead language)
    • if the first character on a line within a snapshot is then it is replaced with 𐝁 (this preserves ASCII art within snapshots)

This combination of character-accurate + WYSIWYG breaks down in only one place - line endings. You can't see them, and git's complex and poorly understood line-ending-mutation rules mean that most teams can't reliably do source control that differentiates between \n and \r\n.

Rather than randomly punch users in the face with this triviality, we do the following:

  • Internally, every text-based snapshot in spotless-snapshot has a .replace("\r", ""), so snapshots will never fail because of line-ending differences
  • New .ss files are always written using \n line endings
  • If an .ss file is loaded from disk with \r\n, it is converted and parsed using \n, but will be written back to disk as \r\n

However, this means that the snapshots are not exactly character-for-character accurate because they do not preserve \r. For users that want to preserve \r, we could add a mode which preserves the \r character if the user uses the .ss.asar format

Adding support for storing \r within .ss files might be possible (maybe encode them as 𐝃r?), but doesn't seem like a good idea.

@nedtwigg nedtwigg added the enhancement New feature or request label Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant