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

Pretty please can we keep comments in pubspec.yaml #4

Closed
rubenvereecken opened this issue Jul 30, 2020 · 7 comments
Closed

Pretty please can we keep comments in pubspec.yaml #4

rubenvereecken opened this issue Jul 30, 2020 · 7 comments
Labels
help wanted Extra attention is needed

Comments

@rubenvereecken
Copy link

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.

@f3ath
Copy link
Owner

f3ath commented Jul 30, 2020

There is an upstream feature request alexei-sintotski/pubspec_yaml#22
Also the discussion on the preceding project f3ath/pubspec-version#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.

@f3ath f3ath added the help wanted Extra attention is needed label Jul 31, 2020
@rubenvereecken
Copy link
Author

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.

@f3ath
Copy link
Owner

f3ath commented Jul 31, 2020

@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?

@rubenvereecken
Copy link
Author

rubenvereecken commented Jul 31, 2020 via email

@f3ath
Copy link
Owner

f3ath commented Jul 31, 2020

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.

@f3ath
Copy link
Owner

f3ath commented Aug 9, 2020

The issue should be fixed in 0.0.3. Please confirm.

@rubenvereecken
Copy link
Author

Beautiful

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants