Fix formatting with --range-start / --range-end (#5632)

This change avoids collapsing an already-formatted range into a single
overlong line when --range-start / --range-end are provided.

Fixes: #4923
master
lhchavez 2018-12-17 04:59:20 -08:00 committed by Lucas Duailibe
parent 6a45924379
commit 911d6c88e5
3 changed files with 37 additions and 1 deletions

View File

@ -78,7 +78,7 @@ function printAstToDoc(ast, options, alignmentSize = 0) {
// Add a hardline to make the indents take effect
// It should be removed in index.js format()
doc = addAlignmentToDoc(
docUtils.removeLines(concat([hardline, doc])),
concat([hardline, doc]),
alignmentSize,
options.tabWidth
);

View File

@ -88,6 +88,34 @@ function ugly ( {a=1, b = 2 } ) {
================================================================================
`;
exports[`large-dict.js 1`] = `
====================================options=====================================
parsers: ["flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
function ugly() {
const dictWithSeveralEntries = {
key: "value",
anotherKey: "another value",
firstNumber: 1,
secondNumber: 2
};
}
=====================================output=====================================
function ugly() {
const dictWithSeveralEntries = {
key: "value",
anotherKey: "another value",
firstNumber: 1,
secondNumber: 2
};
}
================================================================================
`;
exports[`module-export1.js 1`] = `
====================================options=====================================
parsers: ["flow", "typescript"]

View File

@ -0,0 +1,8 @@
function ugly() {
const dictWithSeveralEntries = {
key: "value",
<<<PRETTIER_RANGE_START>>> anotherKey: "another value",
firstNumber: 1,
secondNumber: 2<<<PRETTIER_RANGE_END>>>
};
}