Skip to content

Maintain windows line ending#472

Merged
vjeux merged 1 commit intoprettier:masterfrom
vjeux:windows_line_ending
Jan 26, 2017
Merged

Maintain windows line ending#472
vjeux merged 1 commit intoprettier:masterfrom
vjeux:windows_line_ending

Conversation

@vjeux
Copy link
Copy Markdown
Contributor

@vjeux vjeux commented Jan 25, 2017

It's nice that we print line endings in a single place, it was super easy to preserve them :)

Fixes #92

cat tests/windows/line-ending.js | cat -e
this;^M$
has;^M$
windows;^M$
line;^M$
endings;^M$

./bin/prettier.js tests/windows/line-ending.js | cat -e
this;^M$
has;^M$
windows;^M$
line;^M$
endings;^M$

if (text.charAt(index - 1) === "\r") {
return "\r\n";
}
return "\n";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could be simplified as:

const index = text.indexOf('\n');
if(index >= 0 && text.charAt(index - 1) === "\r") {
  return "\r\n";
}
return "\n";

@jlongster
Copy link
Copy Markdown
Member

Looks generally good, I think that function could be made a tiny bit clearer, then feel free to merge!

Copy link
Copy Markdown
Member

@jlongster jlongster left a comment

Choose a reason for hiding this comment

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

See comment

It's nice that we print line endings in a single place, it was super easy to preserve them :)

Fixes prettier#92
@vjeux vjeux force-pushed the windows_line_ending branch from 3b10dc7 to 83e3b37 Compare January 26, 2017 22:12
@vjeux
Copy link
Copy Markdown
Contributor Author

vjeux commented Jan 26, 2017

Rebased and addressed comments

@vjeux vjeux dismissed jlongster’s stale review January 26, 2017 22:16

Addressed the changes

@vjeux vjeux merged commit 6ade2a1 into prettier:master Jan 26, 2017
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 21, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants