Closed rubenvereecken closed 4 years ago
There is an upstream feature request https://github.com/alexei-sintotski/pubspec_yaml/issues/22 Also the discussion on the preceding project https://github.com/f3ath/pubspec-version/issues/17
Some thoughts on the topic.
I have not seen any yaml writers in Dart able to keep formatting or comments. As a workaround, we can probably search for a line like ^version: \d
without parsing yaml at all. Although that's not a perfect solution as there might technically be multiline strings with the same pattern. In such cases we perhaps can compare the read version from the one read using the yaml parser. I guess we can add a sort of --keep-formatting
flag to use the alternative algorithm.
I just had a quick look at pubspec_yaml
and it looks like it would be non-trivial to change things. They have an intermediary step which loads the yaml into JSON which would get rid of comments. They also extract everything and keep no sense of document structure so this will always rewrite things heavily.
I like the idea of heuristically and minimally changing the document. It might even be made robust, in which case you could completely get rid of the pubspec_yaml
dependency. Is this something you might be interested in? I'd be keen to chip in.
@rubenvereecken sure, contributions are always welcomed. This is one is indeed non trivial. A simple regex can probably solve 99% of the cases, but that 1% might be tricky.
name: my_silly_package
version: '1.2.3' # i am the version line
description: 'This is a hypothetical package that changes lines like
version: 1.2.3
into
version: "1.2.3"
'
homepage: https://example.com
Which line to change here?
I happen to have a bit of experience with lexers though I'm afraid Dart will have limited support in the way of packages. I'll have a look after the weekend.
On Fri, 31 Jul 2020, 20:12 The Конь, notifications@github.com wrote:
@rubenvereecken https://github.com/rubenvereecken sure, contributions are always welcomed. This is one is indeed non trivial. A simple regex can probably solve 99% of the cases, but that 1% might be tricky.
version: "1.2.3" # i am the version linedescription: 'This is a hypothetical package that changes lines likeversion: 3.2.1intoversion: "1.2.3"'
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/f3ath/cider/issues/4#issuecomment-667306839, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHZSKIBXOD53KTJASZDWHDR6MJTPANCNFSM4PNJBESA .
Yes, ideally this should be solved in the upstream dependencies. I'm not aware of any yaml parser/writer in Dart which supports comments or any extensive formatting.
Beautiful
I desperately need a tool like this. Looks clean and neat and seems to do the job well. I don't mind the reformatting, that's a result of rewriting, but pretty please can it keep comments. I've got a flutter project and there are some really good links to documentation in the
pubspec.yaml
file that I don't want to lose.