diff --git a/CHANGELOG.md b/CHANGELOG.md index 675928713..f08fbfda1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,7 +64,7 @@ - Better handling of trailing spaces in Markdown ([#4593](https://github.com/prettier/prettier/pull/4593)) - Fix empty file error in JSON and GraphQL ([#4553](https://github.com/prettier/prettier/pull/4553)) - Preserve decorator on TypeScript interfaces ([#4632](https://github.com/prettier/prettier/pull/4632)) -- Inline \_ or $ in the root of a method chain ([#4621](https://github.com/prettier/prettier/pull/4621)) +- Inline \_ or \$ in the root of a method chain ([#4621](https://github.com/prettier/prettier/pull/4621)) # 1.13.4 diff --git a/package.json b/package.json index 77f242d38..8c7fe269b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prettier", - "version": "1.15.0", + "version": "1.16.0-dev", "description": "Prettier is an opinionated code formatter", "bin": { "prettier": "./bin/prettier.js" @@ -96,7 +96,7 @@ "jest-snapshot-serializer-raw": "1.1.0", "jest-watch-typeahead": "0.1.0", "mkdirp": "0.5.1", - "prettier": "1.14.3", + "prettier": "1.15.0", "prettylint": "1.0.0", "rimraf": "2.6.2", "rollup": "0.47.6", diff --git a/src/cli/util.js b/src/cli/util.js index 081fd9b05..cb69ac233 100644 --- a/src/cli/util.js +++ b/src/cli/util.js @@ -25,13 +25,15 @@ const CHOICE_USAGE_MARGIN = 3; const CHOICE_USAGE_INDENTATION = 2; function getOptions(argv, detailedOptions) { - return detailedOptions.filter(option => option.forwardToApi).reduce( - (current, option) => - Object.assign(current, { - [option.forwardToApi]: argv[option.name] - }), - {} - ); + return detailedOptions + .filter(option => option.forwardToApi) + .reduce( + (current, option) => + Object.assign(current, { + [option.forwardToApi]: argv[option.name] + }), + {} + ); } function cliifyOptions(object, apiDetailedOptionMap) { diff --git a/src/common/util.js b/src/common/util.js index bea82d170..f6d22b65f 100644 --- a/src/common/util.js +++ b/src/common/util.js @@ -476,8 +476,8 @@ function printString(raw, options, isDirectiveLiteral) { options.parser === "json" ? '"' : options.__isInHtmlAttribute - ? "'" - : getPreferredQuote(raw, options.singleQuote ? "'" : '"'); + ? "'" + : getPreferredQuote(raw, options.singleQuote ? "'" : '"'); // Directives are exact code unit sequences, which means that you can't // change the escape sequences they use. diff --git a/src/config/resolve-config.js b/src/config/resolve-config.js index ef6898dc4..0c3ab33e8 100644 --- a/src/config/resolve-config.js +++ b/src/config/resolve-config.js @@ -78,11 +78,10 @@ function _resolveConfig(filePath, opts, sync) { ["plugins", "pluginSearchDirs"].forEach(optionName => { if (Array.isArray(merged[optionName])) { - merged[optionName] = merged[optionName].map( - value => - typeof value === "string" && value.startsWith(".") // relative path - ? path.resolve(path.dirname(result.filepath), value) - : value + merged[optionName] = merged[optionName].map(value => + typeof value === "string" && value.startsWith(".") // relative path + ? path.resolve(path.dirname(result.filepath), value) + : value ); } }); diff --git a/src/doc/doc-debug.js b/src/doc/doc-debug.js index 51d57e61a..1f8accd62 100644 --- a/src/doc/doc-debug.js +++ b/src/doc/doc-debug.js @@ -75,14 +75,10 @@ function printDoc(doc) { return doc.n === -Infinity ? "dedentToRoot(" + printDoc(doc.contents) + ")" : doc.n < 0 - ? "dedent(" + printDoc(doc.contents) + ")" - : doc.n.type === "root" - ? "markAsRoot(" + printDoc(doc.contents) + ")" - : "align(" + - JSON.stringify(doc.n) + - ", " + - printDoc(doc.contents) + - ")"; + ? "dedent(" + printDoc(doc.contents) + ")" + : doc.n.type === "root" + ? "markAsRoot(" + printDoc(doc.contents) + ")" + : "align(" + JSON.stringify(doc.n) + ", " + printDoc(doc.contents) + ")"; } if (doc.type === "if-break") { diff --git a/src/doc/doc-printer.js b/src/doc/doc-printer.js index 6050b7b75..65e1096cf 100644 --- a/src/doc/doc-printer.js +++ b/src/doc/doc-printer.js @@ -22,14 +22,14 @@ function makeAlign(ind, n, options) { return n === -Infinity ? ind.root || rootIndent() : n < 0 - ? generateInd(ind, { type: "dedent" }, options) - : !n - ? ind - : n.type === "root" - ? Object.assign({}, ind, { root: ind }) - : typeof n === "string" - ? generateInd(ind, { type: "stringAlign", n }, options) - : generateInd(ind, { type: "numberAlign", n }, options); + ? generateInd(ind, { type: "dedent" }, options) + : !n + ? ind + : n.type === "root" + ? Object.assign({}, ind, { root: ind }) + : typeof n === "string" + ? generateInd(ind, { type: "stringAlign", n }, options) + : generateInd(ind, { type: "numberAlign", n }, options); } function generateInd(ind, newPart, options) { diff --git a/src/language-css/embed.js b/src/language-css/embed.js index b2648bc8f..6d2ad0142 100644 --- a/src/language-css/embed.js +++ b/src/language-css/embed.js @@ -27,16 +27,14 @@ function embed(path, print, textToDoc /*, options */) { return null; function replaceNewlinesWithLiterallines(doc) { - return mapDoc( - doc, - currentDoc => - typeof currentDoc === "string" && currentDoc.includes("\n") - ? concat( - currentDoc - .split(/(\n)/g) - .map((v, i) => (i % 2 === 0 ? v : literalline)) - ) - : currentDoc + return mapDoc(doc, currentDoc => + typeof currentDoc === "string" && currentDoc.includes("\n") + ? concat( + currentDoc + .split(/(\n)/g) + .map((v, i) => (i % 2 === 0 ? v : literalline)) + ) + : currentDoc ); } } diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index c10054bb3..b6b26562f 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -164,18 +164,18 @@ function genericPrint(path, options, print) { node.raws.important ? node.raws.important.replace(/\s*!\s*important/i, " !important") : node.important - ? " !important" - : "", + ? " !important" + : "", node.raws.scssDefault ? node.raws.scssDefault.replace(/\s*!default/i, " !default") : node.scssDefault - ? " !default" - : "", + ? " !default" + : "", node.raws.scssGlobal ? node.raws.scssGlobal.replace(/\s*!global/i, " !global") : node.scssGlobal - ? " !global" - : "", + ? " !global" + : "", node.nodes ? concat([ " {", @@ -188,8 +188,8 @@ function genericPrint(path, options, print) { : isTemplatePropNode(node) && !parentNode.raws.semicolon && options.originalText[options.locEnd(node) - 1] !== ";" - ? "" - : ";" + ? "" + : ";" ]); } case "css-atrule": { @@ -208,8 +208,8 @@ function genericPrint(path, options, print) { isDetachedRulesetCallNode(node) ? "" : isTemplatePlaceholderNode(node) - ? node.raws.afterName - : " ", + ? node.raws.afterName + : " ", path.call(print, "params") ]) : "", @@ -229,8 +229,8 @@ function genericPrint(path, options, print) { ]) ) : node.name === "else" - ? " " - : "", + ? " " + : "", node.nodes ? concat([ isSCSSControlDirectiveNode(node) ? "" : " ", @@ -247,8 +247,8 @@ function genericPrint(path, options, print) { : isTemplatePlaceholderNode(node) && !parentNode.raws.semicolon && options.originalText[options.locEnd(node) - 1] !== ";" - ? "" - : ";" + ? "" + : ";" ]); } // postcss-media-query-parser @@ -343,7 +343,7 @@ function genericPrint(path, options, print) { ? node.value : adjustNumbers( isHTMLTag(node.value) || - isKeyframeAtRuleKeywords(path, node.value) + isKeyframeAtRuleKeywords(path, node.value) ? node.value.toLowerCase() : node.value ) @@ -759,8 +759,8 @@ function genericPrint(path, options, print) { ), ifBreak( isSCSS(options.parser, options.originalText) && - isSCSSMapItem && - shouldPrintComma(options) + isSCSSMapItem && + shouldPrintComma(options) ? "," : "" ), diff --git a/src/language-html/ast.js b/src/language-html/ast.js index 13b6c9ba8..830cba529 100644 --- a/src/language-html/ast.js +++ b/src/language-html/ast.js @@ -99,8 +99,8 @@ function mapNodesIfChanged(nodes, fn) { } function cloneAndUpdateNodes(nodes, parent) { - const siblings = nodes.map( - node => (node instanceof Node ? node.clone() : new Node(node)) + const siblings = nodes.map(node => + node instanceof Node ? node.clone() : new Node(node) ); let prev = null; diff --git a/src/language-html/printer-html.js b/src/language-html/printer-html.js index 990b78fe1..fb5f58c32 100644 --- a/src/language-html/printer-html.js +++ b/src/language-html/printer-html.js @@ -47,8 +47,8 @@ function concat(parts) { return newParts.length === 0 ? "" : newParts.length === 1 - ? newParts[0] - : builders.concat(newParts); + ? newParts[0] + : builders.concat(newParts); } function embed(path, print, textToDoc, options) { @@ -81,8 +81,8 @@ function embed(path, print, textToDoc, options) { options.parser === "angular" ? { parser: "__ng_interpolation", trailingComma: "none" } : options.parser === "vue" - ? { parser: "__vue_expression" } - : { parser: "__js_expression" } + ? { parser: "__vue_expression" } + : { parser: "__js_expression" } ) ]) ), @@ -110,9 +110,8 @@ function embed(path, print, textToDoc, options) { return concat([ node.rawName, '="', - mapDoc( - embeddedAttributeValueDoc, - doc => (typeof doc === "string" ? doc.replace(/"/g, """) : doc) + mapDoc(embeddedAttributeValueDoc, doc => + typeof doc === "string" ? doc.replace(/"/g, """) : doc ), '"' ]); @@ -193,21 +192,21 @@ function genericPrint(path, options, print) { : isScriptLikeTag(node) && node.parent.type === "root" && options.parser === "vue" - ? childrenDoc - : indent(childrenDoc))( + ? childrenDoc + : indent(childrenDoc))( concat([ shouldHugContent ? ifBreak(softline, "", { groupId: attrGroupId }) : node.firstChild.type === "text" && node.firstChild.isWhitespaceSensitive && node.firstChild.isIndentationSensitive - ? node.firstChild.value.indexOf("\n") === -1 - ? "" - : literalline - : node.firstChild.hasLeadingSpaces && - node.firstChild.isLeadingSpaceSensitive - ? line - : softline, + ? node.firstChild.value.indexOf("\n") === -1 + ? "" + : literalline + : node.firstChild.hasLeadingSpaces && + node.firstChild.isLeadingSpaceSensitive + ? line + : softline, printChildren(path, options, print) ]) ), @@ -219,31 +218,31 @@ function genericPrint(path, options, print) { ? " " : "" : shouldHugContent - ? ifBreak(softline, "", { groupId: attrGroupId }) - : node.lastChild.hasTrailingSpaces && - node.lastChild.isTrailingSpaceSensitive - ? line - : node.type === "element" && - isPreLikeNode(node) && - node.lastChild.type === "text" && - (node.lastChild.value.indexOf("\n") === -1 || - new RegExp( - `\\n\\s{${options.tabWidth * - countParents( - path, - n => n.parent && n.parent.type !== "root" - )}}$` - ).test(node.lastChild.value)) - ? /** - *
- *
-                             *         something
-                             *       
- * ~ - *
- */ - "" - : softline + ? ifBreak(softline, "", { groupId: attrGroupId }) + : node.lastChild.hasTrailingSpaces && + node.lastChild.isTrailingSpaceSensitive + ? line + : node.type === "element" && + isPreLikeNode(node) && + node.lastChild.type === "text" && + (node.lastChild.value.indexOf("\n") === -1 || + new RegExp( + `\\n\\s{${options.tabWidth * + countParents( + path, + n => n.parent && n.parent.type !== "root" + )}}$` + ).test(node.lastChild.value)) + ? /** + *
+ *
+                       *         something
+                       *       
+ * ~ + *
+ */ + "" + : softline ]) ]) ), @@ -504,10 +503,10 @@ function printChildren(path, options, print) { needsToBorrowParentClosingTagStartMarker( prevNode.lastChild.lastChild )) - ? hardline - : nextNode.hasLeadingSpaces - ? line - : softline; + ? hardline + : nextNode.hasLeadingSpaces + ? line + : softline; } } @@ -540,9 +539,8 @@ function printOpeningTag(path, options, print) { typeof ignoreAttributeData === "boolean" ? () => ignoreAttributeData : Array.isArray(ignoreAttributeData) - ? attr => - ignoreAttributeData.indexOf(attr.rawName) !== -1 - : () => false; + ? attr => ignoreAttributeData.indexOf(attr.rawName) !== -1 + : () => false; return path.map(attrPath => { const attr = attrPath.getValue(); return hasPrettierIgnoreAttribute(attr) @@ -578,12 +576,12 @@ function printOpeningTag(path, options, print) { needsToBorrowLastChildClosingTagEndMarker(node.parent)) ? "" : node.isSelfClosing - ? forceNotToBreakAttrContent - ? " " - : line - : forceNotToBreakAttrContent - ? "" - : softline + ? forceNotToBreakAttrContent + ? " " + : line + : forceNotToBreakAttrContent + ? "" + : softline ]), node.isSelfClosing ? "" : printOpeningTagEnd(node) ]); @@ -704,8 +702,8 @@ function printOpeningTagPrefix(node) { return needsToBorrowParentOpeningTagEndMarker(node) ? printOpeningTagEndMarker(node.parent) : needsToBorrowPrevClosingTagEndMarker(node) - ? printClosingTagEndMarker(node.prev) - : ""; + ? printClosingTagEndMarker(node.prev) + : ""; } function printClosingTagPrefix(node) { @@ -718,8 +716,8 @@ function printClosingTagSuffix(node) { return needsToBorrowParentClosingTagStartMarker(node) ? printClosingTagStartMarker(node.parent) : needsToBorrowNextOpeningTagStartMarker(node) - ? printOpeningTagStartMarker(node.next) - : ""; + ? printOpeningTagStartMarker(node.next) + : ""; } function printOpeningTagStartMarker(node) { @@ -804,8 +802,8 @@ function printEmbeddedAttributeValue(node, originalTextToDoc, options) { ? root.node.body[0].expression : root.node : root.type === "JsExpressionRoot" - ? root.node - : root; + ? root.node + : root; if ( rootNode && (rootNode.type === "ObjectExpression" || diff --git a/src/language-html/utils.js b/src/language-html/utils.js index cd50b31a1..9dd78fecf 100644 --- a/src/language-html/utils.js +++ b/src/language-html/utils.js @@ -195,12 +195,10 @@ function replaceNewlines(text, replacement) { } function replaceDocNewlines(doc, replacement) { - return mapDoc( - doc, - currentDoc => - typeof currentDoc === "string" && currentDoc.includes("\n") - ? concat(replaceNewlines(currentDoc, replacement)) - : currentDoc + return mapDoc(doc, currentDoc => + typeof currentDoc === "string" && currentDoc.includes("\n") + ? concat(replaceNewlines(currentDoc, replacement)) + : currentDoc ); } diff --git a/src/language-js/embed.js b/src/language-js/embed.js index a338e4c40..fa8c337d1 100644 --- a/src/language-js/embed.js +++ b/src/language-js/embed.js @@ -308,23 +308,25 @@ function printGraphqlComments(lines) { const parts = []; let seenComment = false; - lines.map(textLine => textLine.trim()).forEach((textLine, i, array) => { - // Lines are either whitespace only, or a comment (with poential whitespace - // around it). Drop whitespace-only lines. - if (textLine === "") { - return; - } + lines + .map(textLine => textLine.trim()) + .forEach((textLine, i, array) => { + // Lines are either whitespace only, or a comment (with poential whitespace + // around it). Drop whitespace-only lines. + if (textLine === "") { + return; + } - if (array[i - 1] === "" && seenComment) { - // If a non-first comment is preceded by a blank (whitespace only) line, - // add in a blank line. - parts.push(concat([hardline, textLine])); - } else { - parts.push(textLine); - } + if (array[i - 1] === "" && seenComment) { + // If a non-first comment is preceded by a blank (whitespace only) line, + // add in a blank line. + parts.push(concat([hardline, textLine])); + } else { + parts.push(textLine); + } - seenComment = true; - }); + seenComment = true; + }); // If `lines` was whitespace only, return `null`. return parts.length === 0 ? null : join(hardline, parts); @@ -572,11 +574,10 @@ function printHtmlTemplateLiteral(path, print, textToDoc, parser) { ); const text = node.quasis - .map( - (quasi, index, quasis) => - index === quasis.length - 1 - ? quasi.value.raw - : quasi.value.raw + placeholders[index] + .map((quasi, index, quasis) => + index === quasis.length - 1 + ? quasi.value.raw + : quasi.value.raw + placeholders[index] ) .join(""); diff --git a/src/language-js/loc.js b/src/language-js/loc.js index f2efd155d..e2d0e9586 100644 --- a/src/language-js/loc.js +++ b/src/language-js/loc.js @@ -45,8 +45,8 @@ function locEnd(node) { const loc = node.range ? node.range[1] : typeof node.end === "number" - ? node.end - : null; + ? node.end + : null; if (node.typeAnnotation) { return Math.max(loc, locEnd(node.typeAnnotation)); diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index b3b2ea4ee..d2836a670 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -308,7 +308,7 @@ function printTernaryOperator(path, options, print, operatorOptions) { : wrap(path.call(print, operatorOptions.consequentNodePropertyName)), " : ", alternateNode.type === operatorOptions.conditionalNodeType || - isNull(alternateNode) + isNull(alternateNode) ? path.call(print, operatorOptions.alternateNodePropertyName) : wrap(path.call(print, operatorOptions.alternateNodePropertyName)) ); @@ -332,11 +332,11 @@ function printTernaryOperator(path, options, print, operatorOptions) { ]); parts.push( parent.type !== operatorOptions.conditionalNodeType || - parent[operatorOptions.alternateNodePropertyName] === node + parent[operatorOptions.alternateNodePropertyName] === node ? part : options.useTabs - ? dedent(indent(part)) - : align(Math.max(0, options.tabWidth - 2), part) + ? dedent(indent(part)) + : align(Math.max(0, options.tabWidth - 2), part) ); } @@ -1281,8 +1281,8 @@ function printPathNoParens(path, options, print, args) { const separator = isFlowInterfaceLikeBody ? ";" : n.type === "TSInterfaceBody" || n.type === "TSTypeLiteral" - ? ifBreak(semi, ";") - : ","; + ? ifBreak(semi, ";") + : ","; const leftBrace = n.exact ? "{|" : "{"; const rightBrace = n.exact ? "|}" : "}"; @@ -1302,21 +1302,23 @@ function printPathNoParens(path, options, print, args) { }); let separatorParts = []; - const props = propsAndLoc.sort((a, b) => a.loc - b.loc).map(prop => { - const result = concat(separatorParts.concat(group(prop.printed))); - separatorParts = [separator, line]; - if ( - (prop.node.type === "TSPropertySignature" || - prop.node.type === "TSMethodSignature") && - hasNodeIgnoreComment(prop.node) - ) { - separatorParts.shift(); - } - if (isNextLineEmpty(options.originalText, prop.node, options)) { - separatorParts.push(hardline); - } - return result; - }); + const props = propsAndLoc + .sort((a, b) => a.loc - b.loc) + .map(prop => { + const result = concat(separatorParts.concat(group(prop.printed))); + separatorParts = [separator, line]; + if ( + (prop.node.type === "TSPropertySignature" || + prop.node.type === "TSMethodSignature") && + hasNodeIgnoreComment(prop.node) + ) { + separatorParts.shift(); + } + if (isNextLineEmpty(options.originalText, prop.node, options)) { + separatorParts.push(hardline); + } + return result; + }); if (n.inexact) { props.push(concat(separatorParts.concat(group("...")))); @@ -1355,7 +1357,7 @@ function printPathNoParens(path, options, print, args) { ), ifBreak( canHaveTrailingSeparator && - (separator !== "," || shouldPrintComma(options)) + (separator !== "," || shouldPrintComma(options)) ? separator : "" ), @@ -1479,8 +1481,8 @@ function printPathNoParens(path, options, print, args) { needsForcedTrailingComma ? "," : "", ifBreak( canHaveTrailingComma && - !needsForcedTrailingComma && - shouldPrintComma(options) + !needsForcedTrailingComma && + shouldPrintComma(options) ? "," : "" ), @@ -1998,22 +2000,25 @@ function printPathNoParens(path, options, print, args) { case "JSXSpreadChild": { return concat([ "{", - path.call(p => { - const printed = concat(["...", print(p)]); - const n = p.getValue(); - if (!n.comments || !n.comments.length) { - return printed; - } - return concat([ - indent( - concat([ - softline, - comments.printComments(p, () => printed, options) - ]) - ), - softline - ]); - }, n.type === "JSXSpreadAttribute" ? "argument" : "expression"), + path.call( + p => { + const printed = concat(["...", print(p)]); + const n = p.getValue(); + if (!n.comments || !n.comments.length) { + return printed; + } + return concat([ + indent( + concat([ + softline, + comments.printComments(p, () => printed, options) + ]) + ), + softline + ]); + }, + n.type === "JSXSpreadAttribute" ? "argument" : "expression" + ), "}" ]); } @@ -2179,8 +2184,8 @@ function printPathNoParens(path, options, print, args) { hasOwnLineComment ? hardline : hasComment && !isOpeningFragment - ? " " - : "", + ? " " + : "", comments.printDanglingComments(path, options, true) ]) ), @@ -2362,14 +2367,16 @@ function printPathNoParens(path, options, print, args) { const table = [{ cells: headerNames }].concat( tableBody.filter(row => row.cells.length !== 0) ); - table.filter(row => !row.hasLineBreak).forEach(row => { - row.cells.forEach((cell, index) => { - maxColumnWidths[index] = Math.max( - maxColumnWidths[index], - getStringWidth(cell) - ); + table + .filter(row => !row.hasLineBreak) + .forEach(row => { + row.cells.forEach((cell, index) => { + maxColumnWidths[index] = Math.max( + maxColumnWidths[index], + getStringWidth(cell) + ); + }); }); - }); parts.push( "`", @@ -2381,14 +2388,13 @@ function printPathNoParens(path, options, print, args) { table.map(row => join( " | ", - row.cells.map( - (cell, index) => - row.hasLineBreak - ? cell - : cell + - " ".repeat( - maxColumnWidths[index] - getStringWidth(cell) - ) + row.cells.map((cell, index) => + row.hasLineBreak + ? cell + : cell + + " ".repeat( + maxColumnWidths[index] - getStringWidth(cell) + ) ) ) ) @@ -3458,8 +3464,8 @@ function printPathNoParens(path, options, print, args) { index === 0 ? "" : isNgForOf(childPath) - ? " " - : concat([";", line]), + ? " " + : concat([";", line]), print(childPath) ]), "body" @@ -6359,11 +6365,10 @@ function printIndentableBlockComment(comment) { "/*", join( hardline, - lines.map( - (line, index) => - index === 0 - ? line.trimRight() - : " " + (index < lines.length - 1 ? line.trim() : line.trimLeft()) + lines.map((line, index) => + index === 0 + ? line.trimRight() + : " " + (index < lines.length - 1 ? line.trim() : line.trimLeft()) ) ), "*/" diff --git a/src/language-markdown/embed.js b/src/language-markdown/embed.js index 916176160..3c8068b06 100644 --- a/src/language-markdown/embed.js +++ b/src/language-markdown/embed.js @@ -81,16 +81,14 @@ function embed(path, print, textToDoc, options) { } function replaceNewlinesWithLiterallines(doc) { - return mapDoc( - doc, - currentDoc => - typeof currentDoc === "string" && currentDoc.includes("\n") - ? concat( - currentDoc - .split(/(\n)/g) - .map((v, i) => (i % 2 === 0 ? v : literalline)) - ) - : currentDoc + return mapDoc(doc, currentDoc => + typeof currentDoc === "string" && currentDoc.includes("\n") + ? concat( + currentDoc + .split(/(\n)/g) + .map((v, i) => (i % 2 === 0 ? v : literalline)) + ) + : currentDoc ); } } diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index ad7cca4de..4a7477d1d 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -70,13 +70,12 @@ function genericPrint(path, options, print) { node.position.end.offset ), options - ).map( - node => - node.type === "word" - ? node.value - : node.value === "" - ? "" - : printLine(path, node.value, options) + ).map(node => + node.type === "word" + ? node.value + : node.value === "" + ? "" + : printLine(path, node.value, options) ) ); } @@ -281,12 +280,12 @@ function genericPrint(path, options, print) { ? (index === 0 ? node.start : isGitDiffFriendlyOrderedList - ? 1 - : node.start + index) + + ? 1 + : node.start + index) + (nthSiblingIndex % 2 === 0 ? ". " : ") ") : nthSiblingIndex % 2 === 0 - ? "- " - : "* "; + ? "- " + : "* "; return node.isAligned || /* workaround for https://github.com/remarkjs/remark/issues/315 */ node.hasIndentedCodeblock @@ -315,8 +314,8 @@ function genericPrint(path, options, print) { node.referenceType === "full" ? concat(["[", node.identifier, "]"]) : node.referenceType === "collapsed" - ? "[]" - : "" + ? "[]" + : "" ]); case "imageReference": switch (node.referenceType) { @@ -524,8 +523,8 @@ function printLine(path, value, options) { ? line : " " : isBreakable - ? softline - : ""; + ? softline + : ""; } function printTable(path, options, print) { @@ -868,10 +867,10 @@ function printTitle(title, options, printSpace) { singleCount > doubleCount ? '"' : doubleCount > singleCount - ? "'" - : options.singleQuote - ? "'" - : '"'; + ? "'" + : options.singleQuote + ? "'" + : '"'; title = title.replace(new RegExp(`(${quote})`, "g"), "\\$1"); return `${quote}${title}${quote}`; } diff --git a/src/language-yaml/printer-yaml.js b/src/language-yaml/printer-yaml.js index 69b0bd8bf..a8fad8f64 100644 --- a/src/language-yaml/printer-yaml.js +++ b/src/language-yaml/printer-yaml.js @@ -152,8 +152,8 @@ function _print(node, parentNode, path, options, print) { : "" ]) : !nextDocument || hasTrailingComment(nextDocument.head) - ? "" - : concat([hardline, "---"]) + ? "" + : concat([hardline, "---"]) ]); }, "children") ), @@ -331,10 +331,10 @@ function _print(node, parentNode, path, options, print) { ? hardline : markAsRoot(literalline) : node.chomping === "keep" && isLastDescendant - ? lineWords.length === 0 - ? dedentToRoot(hardline) - : dedentToRoot(literalline) - : "" + ? lineWords.length === 0 + ? dedentToRoot(hardline) + : dedentToRoot(literalline) + : "" ), [] ) @@ -377,12 +377,8 @@ function _print(node, parentNode, path, options, print) { !hasTrailingComment(node.key.content) && (!parentNode.tag || parentNode.tag.value !== "tag:yaml.org,2002:set") - ? concat([ - key, - needsSpaceInFrontOfMappingValue(node) ? " " : "", - ":" - ]) - : concat(["? ", align(2, key)]); + ? concat([key, needsSpaceInFrontOfMappingValue(node) ? " " : "", ":"]) + : concat(["? ", align(2, key)]); } if (isEmptyMappingKey) { @@ -409,7 +405,7 @@ function _print(node, parentNode, path, options, print) { align(2, value) ]) : // force singleline - isSingleLineNode(node.key.content) && + isSingleLineNode(node.key.content) && !hasLeadingComments(node.key.content) && !hasMiddleComments(node.key.content) && !hasTrailingComment(node.key.content) && @@ -418,44 +414,44 @@ function _print(node, parentNode, path, options, print) { !hasMiddleComments(node.value.content) && !hasEndComments(node.value) && isAbsolutelyPrintedAsSingleLineNode(node.value.content, options) - ? concat([ - key, - needsSpaceInFrontOfMappingValue(node) ? " " : "", - ": ", - value - ]) - : conditionalGroup([ - concat([ - group( - concat([ifBreak("? "), group(align(2, key), { id: groupId })]) + ? concat([ + key, + needsSpaceInFrontOfMappingValue(node) ? " " : "", + ": ", + value + ]) + : conditionalGroup([ + concat([ + group( + concat([ifBreak("? "), group(align(2, key), { id: groupId })]) + ), + ifBreak( + concat([hardline, ": ", align(2, value)]), + indent( + concat([ + needsSpaceInFrontOfMappingValue(node) ? " " : "", + ":", + hasLeadingComments(node.value.content) || + (hasEndComments(node.value) && + node.value.content && + !isNode(node.value.content, ["mapping", "sequence"])) || + (parentNode.type === "mapping" && + hasTrailingComment(node.key.content) && + isInlineNode(node.value.content)) || + (isNode(node.value.content, ["mapping", "sequence"]) && + node.value.content.tag === null && + node.value.content.anchor === null) + ? hardline + : !node.value.content + ? "" + : line, + value + ]) ), - ifBreak( - concat([hardline, ": ", align(2, value)]), - indent( - concat([ - needsSpaceInFrontOfMappingValue(node) ? " " : "", - ":", - hasLeadingComments(node.value.content) || - (hasEndComments(node.value) && - node.value.content && - !isNode(node.value.content, ["mapping", "sequence"])) || - (parentNode.type === "mapping" && - hasTrailingComment(node.key.content) && - isInlineNode(node.value.content)) || - (isNode(node.value.content, ["mapping", "sequence"]) && - node.value.content.tag === null && - node.value.content.anchor === null) - ? hardline - : !node.value.content - ? "" - : line, - value - ]) - ), - { groupId } - ) - ]) - ]); + { groupId } + ) + ]) + ]); } case "flowMapping": case "flowSequence": { diff --git a/src/language-yaml/utils.js b/src/language-yaml/utils.js index dbaca57dd..fc3f82444 100644 --- a/src/language-yaml/utils.js +++ b/src/language-yaml/utils.js @@ -194,27 +194,25 @@ function splitWithSingleSpace(text) { function getFlowScalarLineContents(nodeType, content, options) { const rawLineContents = content .split("\n") - .map( - (lineContent, index, lineContents) => - index === 0 && index === lineContents.length - 1 - ? lineContent - : index !== 0 && index !== lineContents.length - 1 - ? lineContent.trim() - : index === 0 - ? lineContent.trimRight() - : lineContent.trimLeft() + .map((lineContent, index, lineContents) => + index === 0 && index === lineContents.length - 1 + ? lineContent + : index !== 0 && index !== lineContents.length - 1 + ? lineContent.trim() + : index === 0 + ? lineContent.trimRight() + : lineContent.trimLeft() ); if (options.proseWrap === "preserve") { - return rawLineContents.map( - lineContent => (lineContent.length === 0 ? [] : [lineContent]) + return rawLineContents.map(lineContent => + lineContent.length === 0 ? [] : [lineContent] ); } return rawLineContents - .map( - lineContent => - lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent) + .map(lineContent => + lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent) ) .reduce( (reduced, lineContentWords, index) => @@ -227,11 +225,10 @@ function getFlowScalarLineContents(nodeType, content, options) { : reduced.concat([lineContentWords]), [] ) - .map( - lineContentWords => - options.proseWrap === "never" - ? [lineContentWords.join(" ")] - : lineContentWords + .map(lineContentWords => + options.proseWrap === "never" + ? [lineContentWords.join(" ")] + : lineContentWords ); } @@ -260,17 +257,16 @@ function getBlockValueLineContents( if (options.proseWrap === "preserve" || node.type === "blockLiteral") { return removeUnnecessaryTrailingNewlines( - rawLineContents.map( - lineContent => (lineContent.length === 0 ? [] : [lineContent]) + rawLineContents.map(lineContent => + lineContent.length === 0 ? [] : [lineContent] ) ); } return removeUnnecessaryTrailingNewlines( rawLineContents - .map( - lineContent => - lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent) + .map(lineContent => + lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent) ) .reduce( (reduced, lineContentWords, index) => @@ -293,11 +289,10 @@ function getBlockValueLineContents( [] ) ) - .map( - lineContentWords => - options.proseWrap === "never" - ? [lineContentWords.join(" ")] - : lineContentWords + .map(lineContentWords => + options.proseWrap === "never" + ? [lineContentWords.join(" ")] + : lineContentWords ) ); @@ -320,9 +315,9 @@ function getBlockValueLineContents( return trailingNewlineCount === 0 ? lineContents : trailingNewlineCount >= 2 && !isLastDescendant - ? // next empty line - lineContents.slice(0, -(trailingNewlineCount - 1)) - : lineContents.slice(0, -trailingNewlineCount); + ? // next empty line + lineContents.slice(0, -(trailingNewlineCount - 1)) + : lineContents.slice(0, -trailingNewlineCount); } } diff --git a/src/main/options-normalizer.js b/src/main/options-normalizer.js index 13515d7a7..c0e3484e3 100644 --- a/src/main/options-normalizer.js +++ b/src/main/options-normalizer.js @@ -11,10 +11,10 @@ const cliDescriptor = { value === false ? `--no-${key}` : value === true - ? cliDescriptor.key(key) - : value === "" - ? `${cliDescriptor.key(key)} without an argument` - : `${cliDescriptor.key(key)}=${value}` + ? cliDescriptor.key(key) + : value === "" + ? `${cliDescriptor.key(key)} without an argument` + : `${cliDescriptor.key(key)}=${value}` }; class FlagSchema extends vnopts.ChoiceSchema { @@ -54,9 +54,9 @@ function normalizeOptions( const unknown = !passThrough ? vnopts.levenUnknownHandler : Array.isArray(passThrough) - ? (key, value) => - passThrough.indexOf(key) === -1 ? undefined : { [key]: value } - : (key, value) => ({ [key]: value }); + ? (key, value) => + passThrough.indexOf(key) === -1 ? undefined : { [key]: value } + : (key, value) => ({ [key]: value }); const descriptor = isCLI ? cliDescriptor : vnopts.apiDescriptor; const schemas = optionInfosToSchemas(optionInfos, { isCLI }); @@ -100,15 +100,14 @@ function optionInfoToSchema(optionInfo, { isCLI, optionInfos }) { break; case "choice": SchemaConstructor = vnopts.ChoiceSchema; - parameters.choices = optionInfo.choices.map( - choiceInfo => - typeof choiceInfo === "object" && choiceInfo.redirect - ? Object.assign({}, choiceInfo, { - redirect: { - to: { key: optionInfo.name, value: choiceInfo.redirect } - } - }) - : choiceInfo + parameters.choices = optionInfo.choices.map(choiceInfo => + typeof choiceInfo === "object" && choiceInfo.redirect + ? Object.assign({}, choiceInfo, { + redirect: { + to: { key: optionInfo.name, value: choiceInfo.redirect } + } + }) + : choiceInfo ); break; case "boolean": diff --git a/tests_integration/__tests__/support-info.js b/tests_integration/__tests__/support-info.js index cb763fd91..eecbdc034 100644 --- a/tests_integration/__tests__/support-info.js +++ b/tests_integration/__tests__/support-info.js @@ -55,8 +55,8 @@ function getCoreInfo(version) { option.type === "int" ? { range: option.range } : option.type === "choice" - ? { choices: option.choices.map(choice => choice.value) } - : null + ? { choices: option.choices.map(choice => choice.value) } + : null ) }, obj diff --git a/website/playground/Playground.js b/website/playground/Playground.js index a08a2d047..eb0c8939e 100644 --- a/website/playground/Playground.js +++ b/website/playground/Playground.js @@ -273,8 +273,8 @@ function getSecondFormat(formatted, reformatted) { return formatted === "" ? "" : formatted === reformatted - ? "✓ Second format is unchanged." - : reformatted; + ? "✓ Second format is unchanged." + : reformatted; } export default Playground; diff --git a/website/playground/sidebar/SidebarOptions.js b/website/playground/sidebar/SidebarOptions.js index a0b69cfb3..5ad82d97e 100644 --- a/website/playground/sidebar/SidebarOptions.js +++ b/website/playground/sidebar/SidebarOptions.js @@ -11,19 +11,18 @@ export default function({ onOptionValueChange }) { const options = groupBy(availableOptions, "category"); - return categories.map( - category => - options[category] ? ( - - {options[category].map(option => ( - - ) : null + return categories.map(category => + options[category] ? ( + + {options[category].map(option => ( + + ) : null ); } diff --git a/yarn.lock b/yarn.lock index f07a8f3c6..3f67b73ef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4657,9 +4657,9 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" -prettier@1.14.3: - version "1.14.3" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.14.3.tgz#90238dd4c0684b7edce5f83b0fb7328e48bd0895" +prettier@1.15.0: + version "1.15.0" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.15.0.tgz#c6191a50fbc9056ff770577d64ebd9987cca1dd7" pretty-format@^23.0.1: version "23.0.1"