-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
(idempotence violation) Empty line after parenthesized array item #13017
Comments
I haven't been able to replicate this. I'm on macOS and ran a script to compare the output 1000 times, and they were all identical. it may be difficult to determine the cause without more information |
@solarized-fox the issue is to do with the second output not being equal to the first output, which means that idempotency is violated. This is still true for the latest Prettier: Prettier 2.8.7 --parser babel Input: [
a = b,
c //
] Output: [
(a = b),
c, //
]; Second Output: [
(a = b),
c, //
]; I checked Prettier |
hmm, what OS are you on? I'm running macOS 12.6.x, and this script:
produced this output on my machine:
could it be possible the issue is connected to the environment somehow? |
I’m on macOS too, yep. Can you try adding
instead of
If the idempotency principle is followed, we should get:
|
ohhh I understand, the second output is supposed to use the input of the first. this gives me a few ideas, I’ll see if I can’t track this bug down |
I believe I've identified the problem! the node representing it seems to me that the problem is with the range assigned to the node in the first place. for what it's worth, the actual location where the newline is omitted on the second output is line 181 in array.js, where a ternary evaluates differently between the two inputs incidentally since the problem seems to lie simply with the parens, I'm fairly confident that this issue can be boiled down to "these two statements should format the same":
I'll try and see if I can find a solution but the only part of the codebase I've really read so far is language-js/print so if the problem lies outside of that area (as I suspect it might) this might take me a bit |
okay after looking into it it appears that parens are just not (or not always) part of the character range covered by their respective node. this means that the last node on a line could be followed by a ")". so it seems the correct thing to do is just modify skipToLineEnd to also ignore ")". yay one character diff, I'll get a PR ready! |
@solarized-fox there will be comments, more parens [
(((((
a = b/* comment */))/* comment */))),
c //
] |
@fisker adding that to the tests, although it seems the code already accounts for that. it's just the parens that trip it up, apparently |
Prettier 2.7.1
Playground link
Input:
Output:
Second Output:
The text was updated successfully, but these errors were encountered: