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

fix: guess line ending before preprocess #4957

Merged
merged 3 commits into from Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/core.js
Expand Up @@ -71,6 +71,8 @@ function coreFormat(text, opts, addAlignmentSize) {

const parsed = parser.parse(text, opts);
const ast = parsed.ast;

const originalText = text;
text = parsed.text;

if (opts.cursorOffset >= 0) {
Expand All @@ -82,7 +84,7 @@ function coreFormat(text, opts, addAlignmentSize) {

const astComments = attachComments(text, ast, opts);
const doc = printAstToDoc(ast, opts, addAlignmentSize);
opts.newLine = guessLineEnding(text);
opts.newLine = guessLineEnding(originalText);

const result = printDocToString(doc, opts);

Expand Down
5 changes: 1 addition & 4 deletions tests_integration/__tests__/__snapshots__/format.js.snap
Expand Up @@ -9,7 +9,4 @@ exports[`typescript parser should throw the first error when both JSX and non-JS
10 | "
`;

exports[`yaml parser should handle CRLF correctly 1`] = `
"a: 123
"
`;
exports[`yaml parser should handle CRLF correctly 1`] = `"\\"a: 123\\\\r\\\\n\\""`;
5 changes: 4 additions & 1 deletion tests_integration/__tests__/format.js
Expand Up @@ -4,7 +4,10 @@ const prettier = require("prettier/local");

test("yaml parser should handle CRLF correctly", () => {
const input = "a:\r\n 123\r\n";
expect(prettier.format(input, { parser: "yaml" })).toMatchSnapshot();
expect(
// use JSON.stringify to observe CRLF
JSON.stringify(prettier.format(input, { parser: "yaml" }))
).toMatchSnapshot();
});

test("typescript parser should throw the first error when both JSX and non-JSX mode failed", () => {
Expand Down