Fix unstable own line comment in a for-in or for-of head - #19895
Open
Kjubikstronk wants to merge 3 commits into
Open
Fix unstable own line comment in a for-in or for-of head#19895Kjubikstronk wants to merge 3 commits into
Kjubikstronk wants to merge 3 commits into
Conversation
β Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
commit: |
β Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
js/for-of/comments.jsis one of theunstableTestsentries intests/config/format-test/failed-format-tests.js. This makes it stable and removes it from the list.An own line comment in a for-in or for-of head is unstable because printing it turns it into an end of line comment, and the two placements take different branches:
The comment starts out on its own line between
leftandright, so it becomes a leading comment ofrightand prints right afterin. That puts it at the end of a line, so the next format makes it a trailing comment ofleftinstead and moves it out of the head.There is no line inside the head to keep it on, so it ends up outside either way. This attaches it to
leftimmediately, which is where the second format already put it. Block comments were unstable the same way and are fixed by the same change:Note the old first format was not just unstable but mis-indented β
y);was printed at column 0.The handler is registered in the own line list only. End of line and remaining comments already attach to
leftby default and are unchanged:ForStatementis not included β its head already breaks, so own line comments there are stable and print in place. Comments beforeleft, and comments before the body, are also untouched, the latter being what the existinghandleForXStatementCommentsalready handles.The resulting fixpoint keeps the comment on its own line, so it differs from the old second format output for these inputs. Since the old first and second formats disagreed, neither was a settled output.
One related case is still unstable, unchanged by this PR and failing the same way on
main:It has no preceding node, so it needs different handling than this and I would rather not fold it in here.
Across the whole
tests/formatrun this changes exactly one snapshot, the fixture itself, and the failing set is the same before and after.Checklist
docs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.