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

Cannot dump no values with comments #196

Closed
acierto opened this issue Jul 2, 2015 · 11 comments
Closed

Cannot dump no values with comments #196

acierto opened this issue Jul 2, 2015 · 11 comments

Comments

@acierto
Copy link

acierto commented Jul 2, 2015

It is not possible currently to achieve such result:

common:
apiKey: # This is a required field

@dervus
Copy link
Collaborator

dervus commented Jul 2, 2015

I don't understand what do you want to achieve. JS-YAML dumps given data exactly as is.

@acierto
Copy link
Author

acierto commented Jul 2, 2015

If now I try to dump the object it will write to the file:

common:
apiKey: "# This is a required field"

I want

common:
apiKey: # This is a required field

So with another words, js-yaml always put value in quotes if you have any special character. So if you want to have a comment, you can't use any special characters including spaces, etc. Kinda limitation

@dervus
Copy link
Collaborator

dervus commented Jul 2, 2015

You want to add comments to the dump?

@acierto
Copy link
Author

acierto commented Jul 2, 2015

yes, now I'm missing this functionality in this library. I want to create a configuration file where some fields don't have any values and provide a comment for the user to fill it in. But instead I have quoted value :(

@dervus
Copy link
Collaborator

dervus commented Jul 2, 2015

I think JS-YAML is not suitable for such tasks by design. It targets to fast data (de)serialization and therefore misses fine configuration. I mean that in order to generate a dump that looks like it was written by a human, you will need AST access, which JS-YAML cannot provide. It is possible to add option that will accept object of the same structure as data to dump and write it's values as comments, but I don't think that it will have much sense, and I don't think I like the idea of adding such weird stuff to the library.

@puzrin What do you think about this?

@puzrin
Copy link
Member

puzrin commented Jul 2, 2015

That's out of this library scope.

@lipis
Copy link

lipis commented Nov 21, 2017

Can we reevaluate the need of supporting comments?! It would be great, because by doing that it can be used in Prettier to start supporting and formatting YAML files with it: prettier/prettier#3017

@puzrin
Copy link
Member

puzrin commented Nov 21, 2017

No, because that requires completely different architecture, and this one is focused on speed.

@lipis
Copy link

lipis commented Nov 21, 2017

I have no idea how it's done.. but I'm sure there is a way to fix it without compromising speed.. it's 2017 :)

@puzrin
Copy link
Member

puzrin commented Nov 21, 2017

Development is clear technical process, not religion. We can operate only materializable things, beliefs are not enougth to take into account :)

@lipis
Copy link

lipis commented Nov 21, 2017

thanks for the info.. I wasn't aware.. :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants