question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Line wrap doesn't wrap comments

See original GitHub issue

I’m inheriting a node.js app, and it’s ridden with code and comments that exceed 79 characters, so I executed the following on all files:

js-beautify -r -s 2 -a -j -B -w 79 -n --good-stuff <file>

When I run this on all files, I’m finding that there’s 379 lines in comments that aren’t wrapped in the application:

sed -n '/\(.\)\{80\}/p' <file>

If I put this into a file test.js (and set the screen width to 79):

/*
 * This is a test line that is more than seventy-nine characters in length, inc
luding the comment start and period.
 * This is another line that is less than seventy-nine characters in length.
 *
 */

var test = 'This is a test string that is more than seventy characters in lengt
h, even without the var declaration.';

And then I run js-beautify -r -s 2 -a -j -B -w 79 -n --good-stuff test.js then the following is the modified file:

/*
 * This is a test line that is more than seventy-nine characters in length, inc
luding the comment start and period.
* This is another line that is less than seventy-nine characters in length.
*
*/

var test =
  'This is a test string that is more than seventy characters in length, even w
ithout the var declaration.';

It appears that long strings don’t get broken up either.

Is this intentional or a bug?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bitwisemancommented, Feb 1, 2016

Hey, thanks for asking.

I agree #421 covers your feature request for comment formatting, but (as you pointed out) not the behavior you described for string formatting. Leaving this open makes.

(I’ve moved your examples into the first comment and cleaned up the thread a bit. )

Unfortunately, the beautifier uses a rather simplistic engine and focuses on rearranging whitespace around tokens, rather than on rearranging tokens themselves. The string formatting you suggest is more involved requiring rewriting of tokens themselves, not just rearranging whitespace. So, it is out of scope at this time. If the beautifier reaches sufficient sophistication to be able to do token modification and we get the line wrapping from “best effort” to fully baked, this would certainly be one of the first token modification features I’d look at adding.

Thanks!

1reaction
karma0commented, Jan 27, 2016

Perhaps a desired output could be:

/*
 * This is a test line that is more than seventy-nine characters in length,
 * including the comment start and period.
 * This is another line that is less than seventy-nine characters in length.
 *
 */

var test =
  'This is a test string that is more than seventy characters in length, '+
  'even without the var declaration.';

Or similar.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Text Doesn't Wrap at Margin in Draft View - Word Ribbon Tips
Text Doesn't Wrap at Margin in Draft View · Display the Word Options dialog box. · Click Advanced at the left side of...
Read more >
Word Wrap feature not working #108326 - GitHub
Issue Type: Bug. I attempted to use [alt]Z and [alt]z tp get word wrap to work. When this failed, I clecked on View...
Read more >
Wrapping text automatically option doesn't seem to work
I've set Outlook's “Automatically wrap text at character” option to 40 instead of the default 76 but it doesn't appear to do anything....
Read more >
In Word 2010, Comments do not wrap correctly.
When using comments and viewing them as balloons, the first line of text is always wrapped incorrectly. For example, it cuts words apart, ......
Read more >
Wrapping and breaking text - CSS: Cascading Style Sheets
This guide explains the various ways in which overflowing text can be managed in CSS.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found