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

HTML: wrap_line_length is handled incorrectly #1401

Closed
vvs opened this issue May 30, 2018 · 5 comments
Closed

HTML: wrap_line_length is handled incorrectly #1401

vvs opened this issue May 30, 2018 · 5 comments

Comments

@vvs
Copy link

vvs commented May 30, 2018

Description

js-beautify doesn't handle wrap_line_length properly. Say, I have set it to 40. But the beautifier breaks the line not on 40th character. In my case it is on 50th character. In fact, the text content of the span tag is broken exactly on 40th character, but the setting should be related to the whole line, not to the length of the content inside the tag.

Input

The code looked like this before beautification:

<html lang="en">
<head>Test</head>
<body>
  <span>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24</span>
</body>
</html>

Expected Output

The code should have looked like this after beautification:

<html lang="en">

<head>Test</head>

<body>
  <span>1 2 3 4 5 6 7 8 9 10 11 12 13
    14 15 16 17 18 19 20 21 22 23 24</span>
</body>

</html>

Actual Output

The code actually looked like this after beautification:

<html lang="en">

<head>Test</head>

<body>
  <span>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
    17 18 19 20 21 22 23 24</span>
</body>

</html>

Environment

OS: Windows 10

Settings

Example:

{
    "html": {
        "indent_size": 2,
        "unformatted": [],
        "wrap_line_length": 40
    }
}
@vvs
Copy link
Author

vvs commented May 30, 2018

This is a smallest test case I could come up with, but I am seeing this problem A LOT, inside VS Code, when reformatting some long lines. The setting is set to 80, but I am seeing lines up to 150 characters!

When I set it to 40, I see lines up to 100, etc.

My expectations are that if the max line length limit is set to some value, then js-beautify should try to honor that value and only produce longer lines only if there is no other way.

@bitwiseman
Copy link
Member

@vvs The beautifier doesn't have sufficient information to do line wrapping correctly in all cases, but this is definitely a bug.

@bitwiseman
Copy link
Member

I think 35dc66a may address this issue, but I haven't written tests to check. Thanks for the good examples above, they will make good tests.

@bitwiseman
Copy link
Member

This is improved (see #1432) but still not really right.

@bitwiseman bitwiseman modified the milestones: v1.7.6, v1.7.x Jun 30, 2018
@MacKLess
Copy link
Collaborator

I ran this on v1.8.0-rc4, with the following settings:

{
  "indent_size": "2",
  "wrap_line_length": "40",
}

And the actual output was this:

<html lang="en">

<head>Test</head>

<body>
  <span>1 2 3 4 5 6 7 8 9 10 11 12 13 14
    15 16 17 18 19 20 21 22 23 24</span>
</body>

</html>

It hasn't resolved the issue, but the line wraps after '14' instead of '16' so there seems to have been a shift closer to correct.

@bitwiseman bitwiseman modified the milestones: v1.8.x, 1.8.0-rc7 Aug 14, 2018
@bitwiseman bitwiseman modified the milestones: 1.8.0-rc8, 1.8.0 Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants