beautifier/js-beautify

Line wrap breaks signed numbers

Opened this issue · 1 comments

Description

At the end of the 1st line in the Actual Output we see a stray hyphen which belongs to the Number wrapped to the line after.

Input

[-0.49673205000000004, -0.49038462, -0.006536000000000042, -0.336538, 0.49673199999999995, -0.5, 0.40522899999999995, 0, 0.11764699999999995, -0.05769200000000002, -0.006536000000000042, 0.5, -0.03268000000000004, -0.19230799999999998, -0.42483660000000006, 0]

Expected Output

[-0.49673205000000004, -0.49038462, -0.006536000000000042, -0.336538, 0.49673199999999995, -0.5, 0.40522899999999995, 0, 0.11764699999999995,
    -0.05769200000000002, -0.006536000000000042, 0.5, -0.03268000000000004, -0.19230799999999998, -0.42483660000000006, 0
]

Actual Output

[-0.49673205000000004, -0.49038462, -0.006536000000000042, -0.336538, 0.49673199999999995, -0.5, 0.40522899999999995, 0, 0.11764699999999995, -
    0.05769200000000002, -0.006536000000000042, 0.5, -0.03268000000000004, -0.19230799999999998, -0.42483660000000006, 0
]

Steps to Reproduce

input = JSON.stringify([-0.49673205000000004, -0.49038462, -0.006536000000000042, -0.336538, 0.49673199999999995, -0.5, 0.40522899999999995, 0, 0.11764699999999995, -0.05769200000000002, -0.006536000000000042, 0.5, -0.03268000000000004, -0.19230799999999998, -0.42483660000000006, 0]);
console.log(js_beautify(input, { wrap_line_length: 160 }));

Environment

OS: Win10
Node: 20.7.0
js-beautify: 1.15.1 from cdnjs

Settings

{
    "wrap_line_length": 160
}

I just bumped into this in the Python version (jsbeautifier). It wouldn't matter except that the JSON spec apparently disallows whitespace between the sign and the rest of a number; I wouldn't have noticed except that Python's json.load complains about it. Thank you for your attention to this.