Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion python/jsbeautifier/javascript/beautifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ def allow_wrap_or_preserved_newline(self, current_token, force_linewrap=False):
if shouldPreserveOrForce:
self.print_newline(preserve_statement_flags=True)
elif self._options.wrap_line_length > 0:
if reserved_array(self._flags.last_token, self._newline_restricted_tokens):
if (
reserved_array(self._flags.last_token, self._newline_restricted_tokens)
or self._flags.last_token.type == TOKEN.OPERATOR
):
# These tokens should never have a newline inserted between
# them and the following expression.
return
Expand Down
25 changes: 25 additions & 0 deletions python/jsbeautifier/tests/core/test_wrap_line_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import jsbeautifier
import json
import unittest


class TestWrapLineLength(unittest.TestCase):
@classmethod
def setUpClass(cls):
pass

def test_wrap_line_does_not_create_invalid_json(self):
options = jsbeautifier.default_options()
options.indent_size = 4
options.brace_style = "expand"
options.wrap_line_length = 40
obj = {
"1234567891234567891234567891234": -4
}
# make sure exception is not raised due to bad json (line break after -):
# {
# "1234567891234567891234567891234": -
# 4
# }
# json.decoder.JSONDecodeError: Expecting value: line 2 column 40 (char 41)
json.loads(jsbeautifier.beautify(json.dumps(obj), options))