-
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
Line wrapping breaks at the wrong place when the line is indented. #691
Comments
I sort of managed to follow this with a bunch of
|
@redapple - I'm having trouble following your print statement debugging, but thanks for trying. |
@bitwiseman I totally understand that wrap might occur sooner than the exact column if line length is longer than "wrap_line_length". However, this is a different case. Per my understanding of the specification; a line should never be wrapped if it's shorter than "wrap_line_length", i.e. there should not be any approximation/uncertainty about whether to wrap, but only where to wrap. |
No, unfortunately. At this time, we have a process of indenting where we indent all blocks, and when a block closes we look at the contents and remove the redundant indents. This results in some cases where we will indent before expected. Note: this was not one of those cases and is now fixed. (function() {
var dummy2 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBB';
var dummy3 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBB';
})
// This has an intermediate state that looks like this
(function() {
var dummy2 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBB';
var dummy3 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBB';
})
// At the end the enclosing (), the beautifier removes the extra indent,
// but it doesn't currently have the functionality to go back and re-evaluate all the line wraps.
// The result is this:
(function() {
var dummy2 =
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBB';
var dummy3 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBB';
}) That is unfortunate, but a known issue - This on the other hand, is a new bug. dummyFunction(function() {
var dummy2 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBB';
var dummy3 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBB';
})
// Second line should really not wrap, but does...
// There still an extra intermediate indent in here somewhere.
dummyFunction(function() {
var dummy2 =
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBB';
var dummy3 =
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBB';
}) |
The problem is related to indentation. It's as if js-beautify "double counts" indent spaces while calculating where to break the line.
If you beautify the following code with "wrap_line_length" set to 80, dummy2 and dummy3 lines get wrapped even though they should not. There are the same number of B's in each string as the number of indent spaces in that line and if you remove all the B's from those strings they won't be wrapped.
This bug does not exist in version 1.5.1, but it exists in every version released since.
Output from jsbeautifier.org
The text was updated successfully, but these errors were encountered: