tools icon indicating copy to clipboard operation
tools copied to clipboard

Review YamlEditor line ending to be more aligned with how the SDK does it

Open FMorschel opened this issue 6 months ago • 1 comments

Based on https://github.com/dart-lang/sdk/issues/60234 I think we can give some attention to the YamlEditor here, considering line endings.

We could probably copy the work at:

https://github.com/dart-lang/sdk/blob/1499a30cd560b93ea692b5dfa78dbd01275dd720/pkg/analysis_server_plugin/lib/edit/correction_utils.dart#L53-L73

FYI @DanTup

FMorschel avatar Aug 13 '25 19:08 FMorschel

I'm a bit hazy on this right now, but as I remember, yaml_edit does the right thing for content that has newlines:

https://github.com/dart-lang/tools/blob/24707e094cd761178eb76e725ce17f51e22fd442/pkgs/yaml_edit/lib/src/utils.dart#L265

But there's some awkwardness when the file is currently empty, because it will default to \n and not Platform.lineTerminator (or be configurable).

It would probably be useful if we could just set the default line ending for when there are zero newlines (or, when the count of windows + unit newlines are the same).

DanTup avatar Aug 26 '25 15:08 DanTup