diffplug / diffplug/selfie

Add a mode which preserves carriage returns

未关闭
#2 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
Kotlin
星标
101
派生
18
PR 合并指标
30 天内没有已合并 PR

描述

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](https://en.wikipedia.org/wiki/Linear_A))
- 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

- #1

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

贡献指南

打开贡献指南

调研方向

首先追踪 .ss 文件和 .ss.asar 格式的加载、解析和写入方式,包括此处所述的回车符规范化。定义该模式在保留 \r 以及对文件进行往返处理方面的行为,同时不改变其他转义规则;完成的标准是 .ss.asar 快照保留回车符,而普通快照保持当前行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
kotlin
领域
testing
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。