Skip to content
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

Uniform line endings for multi line strings/comments #7891

Merged
merged 8 commits into from
Apr 5, 2020

Conversation

sidharthv96
Copy link
Contributor

@sidharthv96 sidharthv96 commented Mar 28, 2020

Fixes #6501

  • Removed double parsing of the doc
  • Moved newline check to printDocToString
  • I’ve added tests to confirm my change works.
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/pr-XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

* Removed double parsing of the doc
* Moved newline check to printDocToString
@sidharthv96 sidharthv96 changed the title Fix #6501 Uniform line endings for multi line strings/comments - fix #6501 Mar 28, 2020
@sidharthv96 sidharthv96 changed the title Uniform line endings for multi line strings/comments - fix #6501 Uniform line endings for multi line strings/comments Mar 28, 2020
@prettier prettier deleted a comment from netlify bot Mar 28, 2020
tests/end_of_line/multiline.js Outdated Show resolved Hide resolved
Copy link
Contributor Author

@sidharthv96 sidharthv96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the test case to original code from #6501

tests/end_of_line/multiline.js Outdated Show resolved Hide resolved
@j-f1
Copy link
Member

j-f1 commented Mar 28, 2020

How does this work with e.g. template strings containing LFs? Does it preserve them or does it change their content?

@sidharthv96
Copy link
Contributor Author

sidharthv96 commented Mar 29, 2020

console.log(
        `Multiline \n string\
         Multiline string\
         Multiline string`
      );

Will have the \n preserved (As they are escaped in the text representation). This only changes the actual line endings in the file.

I've updated the test case to cover this.

@sidharthv96 sidharthv96 requested a review from thorn0 March 31, 2020 10:46
@sidharthv96
Copy link
Contributor Author

@thorn0 any pointers on how to handle the codecov failure?

@thorn0
Copy link
Member

thorn0 commented Mar 31, 2020

@sidharthv96 Failing because of "+-0.01%" looks like a misconfiguration. Ignore it.

@thorn0
Copy link
Member

thorn0 commented Mar 31, 2020

@j-f1 I think your question was about non-escaped line breaks in template literals. So I did a little research. Turns out (see the spec) template literals treat any LineTerminatorSequence as LF, no matter how it's represented in the source code:

image

In other words, eval("`\r`") === '\n'. This means it's totally safe to convert line endings in source files. Prettier's correctness goal isn't compromised.

@thorn0 thorn0 merged commit 04e4ef3 into prettier:master Apr 5, 2020
@thorn0
Copy link
Member

thorn0 commented Apr 5, 2020

@sidharthv96 Thanks for fixing this!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CRLF: CR is removed in multiline comments and strings
4 participants