-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Comments attached to array list elements #702
Comments
Interesting. Some notes: var lst = [ /* 0 */ foo, /* 1 */ bar(with, many, args), /* 2 */ baz]; Your second input is definitely an enhancement - aligning all the comments at the end of lines is a quite a bit more complex and lower priority. If you want that addressed, you should add it to #421. Your first example, looks like bug in the existing behavior. We determine whether a comment is inline based on newlines appearing before before the comment, but we should also look after the comment. |
It's annoyingly hard to get these formatted in such a way that js-beautify doesn't break alignment. See beautifier/js-beautify#702
The first example in this bug might benefit from the fix proposed in #1069. |
I'm not sure I understand how #1069 would apply here. I thought that was all about the indentation of comments which are on separate lines, while this issue here is looking for ways how the comments could stay on the same line as the actual array elements and still be aligned to a common column. |
@gagern - The reason why #1069 exists is due in part to cases where the engine does not end statements/expressions until after the following comments have been printed. As long as we're changing the set of rules, I want to make sure I had linked in all the comment related issues for examples of what cases needed to be handled. |
Sometimes there is a lengthy list in code, and one wants to comment on each list item. Once case I recently had was where I wanted to simply include the index for each element, to match that up later on. However, I couldn't get this formatted in a reasonable way.
got turned into
while
became
There are many ways how this could be achieved. You could keep short
/* … */
comments in line. You could detect aligned//
comments in consecutive rows and preserve that. You could offer some mechanism to exempt these lines from beautification, as #384 and #575 requested. Having any of these mechanisms available would in my opinion be important for use cases like this.The text was updated successfully, but these errors were encountered: