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

Feature for distributing comments to lists with separators. #6

Open
jordwalke opened this issue May 9, 2015 · 2 comments
Open

Feature for distributing comments to lists with separators. #6

jordwalke opened this issue May 9, 2015 · 2 comments

Comments

@jordwalke
Copy link
Collaborator

I've found that in formatting source code, you often want to have delimiters (such as commas etc). But you often also have other items in the list for which there should not be any delimiters (comments etc). They should "break" just like any other item in the list, and a break of one item in the list should imply the break of every item in the list equally - but some of these items should not have delimiters after them.

 var myObject = {/*firstField */ fieldOne: blah, /*secondField */ fieldTwo: foo};

You'd like to separate each object key/value pair with a comma, but you want the comments before each key-value pair to break along with each of the items (as follows):

 var myObject = {
   /*firstField */
   fieldOne: blah,
   /*secondField */
   fieldTwo: foo
};

So the comments have spaces separating them from any other key-value pair in the sequence, but should be immune to any delimiters.

My only solution was to create this intermediate representation (wrapping EasyFormat) but that was so cumbersome.

@mjambon
Copy link
Member

mjambon commented Nov 28, 2015

This looks like it can be achieved without intrusive changes. Perhaps a good helper library that comes with easy-format is the way to go.

@jordwalke
Copy link
Collaborator Author

I'll try to share my solution, but the downside is that in order to get the comments to break as regular list items would, you have to forgo the separators and hand roll them yourself - placing each one manually. This could be in a helper library, but I like that Easyformat accepts separators "declaratively" and handles their placement. It's not just about convenience. I suspect there are certain things that only Easyformat could possibly be in the position to do. For example, imagine a separator rule that only places the trailing separator if the line actually breaks - that kind of "dry run/propagating" logic sounds similar to what the BreakAlways_rec feature required.
Anyways, in the absence of features such as "trailing separator only if line breaks", I believe you are correct that this can be in a helper library.

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

2 participants