diff --git a/cspell.json b/cspell.json index f25a6716d1..171017d7b2 100644 --- a/cspell.json +++ b/cspell.json @@ -432,8 +432,11 @@ "yamafaktory", "Yatharth", "youtube", + "arijs", "brodybits", "Zatorski", + "memberexpr", + "oneline", "Zosel" ], "ignoreRegExpList": [ diff --git a/src/document/doc-builders.js b/src/document/doc-builders.js index 7ed5594950..4229e8e76c 100644 --- a/src/document/doc-builders.js +++ b/src/document/doc-builders.js @@ -96,6 +96,8 @@ function group(contents, opts = {}) { id: opts.id, contents, break: Boolean(opts.shouldBreak), + // [prettierx] for --paren-spacing option support (...) + addedLine: Boolean(opts.addedLine), expandedStates: opts.expandedStates, }; } diff --git a/src/language-js/comments.js b/src/language-js/comments.js index db830e2c6c..16ea55c2d9 100644 --- a/src/language-js/comments.js +++ b/src/language-js/comments.js @@ -170,6 +170,8 @@ function handleIfStatementComments({ enclosingNode, followingNode, text, + // [prettierx] support --break-before-else option + options, }) { if ( !enclosingNode || @@ -201,7 +203,8 @@ function handleIfStatementComments({ precedingNode === enclosingNode.consequent && followingNode === enclosingNode.alternate ) { - if (precedingNode.type === "BlockStatement") { + // [prettierx] --break-before-else option support + if (precedingNode.type === "BlockStatement" && !options.breakBeforeElse) { addTrailingComment(precedingNode, comment); } else { addDanglingComment(enclosingNode, comment); diff --git a/src/language-js/embed.js b/src/language-js/embed.js index 6b185e594e..d229a102a0 100644 --- a/src/language-js/embed.js +++ b/src/language-js/embed.js @@ -55,11 +55,13 @@ function embed(path, print, textToDoc, options) { } if (language === "css") { - return formatCss(path, print, textToDoc); + // [prettierx] templateCurlySpacing option support (...) + return formatCss(path, print, textToDoc, options); } if (language === "graphql") { - return formatGraphql(path, print, textToDoc); + // [prettierx] templateCurlySpacing option support (...) + return formatGraphql(path, print, textToDoc, options); } if (language === "html" || language === "angular") { diff --git a/src/language-js/embed/css.js b/src/language-js/embed/css.js index 7ff50144ca..1cd2319634 100644 --- a/src/language-js/embed/css.js +++ b/src/language-js/embed/css.js @@ -7,7 +7,8 @@ const { } = require("../../document"); const { printTemplateExpressions } = require("../print/template-literal"); -function format(path, print, textToDoc) { +// [prettierx] templateCurlySpacing option support (...) +function format(path, print, textToDoc, options) { const node = path.getValue(); // Get full template literal with expressions replaced by placeholders @@ -29,7 +30,8 @@ function format(path, print, textToDoc) { { parser: "scss" }, { stripTrailingHardline: true } ); - const expressionDocs = printTemplateExpressions(path, print); + // [prettierx] templateCurlySpacing option support (...) + const expressionDocs = printTemplateExpressions(path, print, options); return transformCssDoc(doc, node, expressionDocs); } diff --git a/src/language-js/embed/graphql.js b/src/language-js/embed/graphql.js index 80d9d4764d..858e2a56f7 100644 --- a/src/language-js/embed/graphql.js +++ b/src/language-js/embed/graphql.js @@ -8,7 +8,8 @@ const { printTemplateExpressions, } = require("../print/template-literal"); -function format(path, print, textToDoc) { +// [prettierx] with templateCurlySpacing option support (...) +function format(path, print, textToDoc, options) { const node = path.getValue(); const numQuasis = node.quasis.length; @@ -16,7 +17,8 @@ function format(path, print, textToDoc) { return "``"; } - const expressionDocs = printTemplateExpressions(path, print); + // [prettierx] templateCurlySpacing option support (...) + const expressionDocs = printTemplateExpressions(path, print, options); const parts = []; for (let i = 0; i < numQuasis; i++) { diff --git a/src/language-js/embed/html.js b/src/language-js/embed/html.js index 99f5d9bdef..f56f40df0c 100644 --- a/src/language-js/embed/html.js +++ b/src/language-js/embed/html.js @@ -27,7 +27,8 @@ function format(path, print, textToDoc, options, { parser }) { ) .join(""); - const expressionDocs = printTemplateExpressions(path, print); + // [prettierx] templateCurlySpacing option support (...) + const expressionDocs = printTemplateExpressions(path, print, options); if (expressionDocs.length === 0 && text.trim().length === 0) { return "``"; } diff --git a/src/language-js/index.js b/src/language-js/index.js index 36e9f68367..458c218cbd 100644 --- a/src/language-js/index.js +++ b/src/language-js/index.js @@ -31,7 +31,9 @@ const languages = [ createLanguage(require("linguist-languages/data/JavaScript.json"), () => ({ name: "Flow", since: "0.0.0", - parsers: ["flow", "babel-flow"], + // [prettierx] must use Babel by default + // (since the flow-parser is now an optional dependency in prettierx) + parsers: ["babel-flow", "flow"], vscodeLanguageIds: ["javascript"], aliases: [], filenames: [], @@ -63,12 +65,14 @@ const languages = [ })), createLanguage(require("linguist-languages/data/TypeScript.json"), () => ({ since: "1.4.0", - parsers: ["typescript", "babel-ts"], + // [prettierx] use babel-ts for TypeScript by default here + parsers: ["babel-ts", "typescript"], vscodeLanguageIds: ["typescript"], })), createLanguage(require("linguist-languages/data/TSX.json"), () => ({ since: "1.4.0", - parsers: ["typescript", "babel-ts"], + // [prettierx] use babel-ts for TypeScript by default here + parsers: ["babel-ts", "typescript"], vscodeLanguageIds: ["typescriptreact"], })), createLanguage(require("linguist-languages/data/JSON.json"), () => ({ diff --git a/src/language-js/needs-parens.js b/src/language-js/needs-parens.js index 466d05dcf4..512e171553 100644 --- a/src/language-js/needs-parens.js +++ b/src/language-js/needs-parens.js @@ -28,7 +28,8 @@ function needsParens(path, options) { // to avoid unexpected `}}` in HTML interpolations if ( options.__isInHtmlInterpolation && - !options.bracketSpacing && + // [prettierx]: objectCurlySpacing option support + !options.objectCurlySpacing && endsWithRightBracket(node) && isFollowedByRightBracket(path) ) { diff --git a/src/language-js/options.js b/src/language-js/options.js index 775d7c7ee8..66af1d7595 100644 --- a/src/language-js/options.js +++ b/src/language-js/options.js @@ -26,7 +26,110 @@ module.exports = { }, ], }, - bracketSpacing: commonOptions.bracketSpacing, + // [prettierx ...] + arrayBracketSpacing: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: + "Put spaces between array brackets (similar to the corresponding eslint option). Status: experimental, with limited testing.", + }, + computedPropertySpacing: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: + "Put spaces between computed property brackets (similar to the corresponding eslint option). Status: experimental, with limited testing.", + }, + indentChains: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: true, + description: "Put indents at the start of chained calls.", + oppositeDescription: "Disable indents at the start of chained calls.", + }, + importFormatting: { + category: CATEGORY_JAVASCRIPT, + type: "choice", + default: "auto", + description: + "Formatting of import statements, may be `oneline` to avoid conflict with" + + ' VSCode "Organize Imports" feature.', + choices: [ + { + value: "auto", + description: "automatic formatting, like Prettier", + }, + { + value: "oneline", + description: "keep import statements on one line", + }, + ], + }, + spaceInParens: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: + 'Print spaces in between parens, WordPress style (similar to the corresponding eslint option). Not recommended in combination with the default `arrowParens: "always"` option. Status: experimental, with limited testing.', + }, + spaceUnaryOps: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: + "Put spaces after unary operator symbols, except in the middle of `!!` (similar to the corresponding eslint option). Status: experimental, with limited testing.", + }, + templateCurlySpacing: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: + "Put spaces between template curly brackets (similar to the corresponding eslint option). Status: experimental, with limited testing.", + }, + typeAngleBracketSpacing: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: + "Put spaces between type angle brackets. Status: experimental, with limited testing.", + }, + typeBracketSpacing: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: + "Print spaces between type brackets. Status: experimental, with limited testing.", + }, + exportCurlySpacing: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: true, + description: "Put spaces between export curly braces.", + oppositeDescription: "Disable spaces between export curly braces.", + }, + importCurlySpacing: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: true, + description: "Put spaces between import curly braces.", + oppositeDescription: "Disable spaces between import curly braces.", + }, + objectCurlySpacing: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: true, + description: + "Put spaces between object curly braces (similar to the corresponding eslint option).", + oppositeDescription: "Disable spaces between object curly braces.", + }, + typeCurlySpacing: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: true, + description: "Put spaces between type curly braces.", + oppositeDescription: "Disable spaces between type curly braces.", + }, jsxBracketSameLine: { since: "0.17.0", category: CATEGORY_JAVASCRIPT, @@ -43,6 +146,54 @@ module.exports = { oppositeDescription: "Do not print semicolons, except at the beginning of lines which may need them.", }, + // [prettierx ...] + alignObjectProperties: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: "Align colons in multiline object literals.", + }, + offsetTernaryExpressions: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: + 'Indent and align ternary expression branches more consistently with "Standard JS" (similar to the corresponding eslint option).', + }, + generatorStarSpacing: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: + "Put spaces around the star (`*`) in generator functions (before and after - similar to the corresponding eslint option). (Default is after only.)", + }, + yieldStarSpacing: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: + "Put spaces around the star (`*`) in `yield*` expressions (before and after - similar to the corresponding eslint option). (Default is after only.)", + }, + spaceBeforeFunctionParen: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: + "Put a space before function parenthesis in all declarations (similar to the corresponding eslint option). (Default is to put a space before function parenthesis for untyped anonymous functions only.)", + }, + breakBeforeElse: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: "Always add a line break before else.", + }, + breakLongMethodChains: { + category: CATEGORY_JAVASCRIPT, + type: "boolean", + default: false, + description: + "Break method chains with more than 3 method calls, like Prettier 1.x.", + }, singleQuote: commonOptions.singleQuote, jsxSingleQuote: { since: "1.15.0", diff --git a/src/language-js/parse-postprocess.js b/src/language-js/parse-postprocess.js index fd97535a7b..5252dbbb20 100644 --- a/src/language-js/parse-postprocess.js +++ b/src/language-js/parse-postprocess.js @@ -152,6 +152,10 @@ function postprocess(ast, options) { node.optional = true; } break; + case "IfStatement": // [prettierx] quick workaround breakBeforeElse & AST compare test + if (node.consequent.innerComments) { + delete node.consequent.innerComments; + } } }); diff --git a/src/language-js/print/array.js b/src/language-js/print/array.js index 5d07163b51..2f81e0eb4f 100644 --- a/src/language-js/print/array.js +++ b/src/language-js/print/array.js @@ -92,12 +92,16 @@ function printArray(path, options, print) { ? ifBreak(",", "", { groupId }) : ifBreak(","); + // [prettierx] arrayBracketSpacing option support (...) parts.push( group( + // [prettierx] arrayBracketSpacing option support (...) [ openBracket, + // [prettierx] arrayBracketSpacing option support (...) indent([ - softline, + // [prettierx] arrayBracketSpacing option support (...) + options.arrayBracketSpacing ? line : softline, shouldUseConciseFormatting ? printArrayItemsConcisely(path, options, print, trailingComma) : [ @@ -106,7 +110,8 @@ function printArray(path, options, print) { ], printDanglingComments(path, options, /* sameIndent */ true), ]), - softline, + // [prettierx] arrayBracketSpacing option support (...) + options.arrayBracketSpacing ? line : softline, closeBracket, ], { shouldBreak, id: groupId } diff --git a/src/language-js/print/binaryish.js b/src/language-js/print/binaryish.js index 402bf2e6ff..465cda5776 100644 --- a/src/language-js/print/binaryish.js +++ b/src/language-js/print/binaryish.js @@ -41,6 +41,9 @@ function printBinaryishExpression(path, options, print) { parent.type === "SwitchStatement" || parent.type === "DoWhileStatement"); + // [prettierx] spaceInParens option support (...) + const parenLine = options.spaceInParens ? line : softline; + const parts = printBinaryishExpressions( path, print, @@ -63,6 +66,9 @@ function printBinaryishExpression(path, options, print) { return parts; } + // [prettierx] spaceInParens option support + // (...) + // // Break between the parens in // unaries or in a member or specific call expression, i.e. // @@ -76,7 +82,10 @@ function printBinaryishExpression(path, options, print) { parent.type === "UnaryExpression" || (isMemberExpression(parent) && !parent.computed) ) { - return group([indent([softline, ...parts]), softline]); + // [prettierx] spaceInParens option support (...) + return group([indent([parenLine, ...parts]), parenLine], { + addedLine: options.spaceInParens, + }); } // Avoid indenting sub-expressions in some cases where the first sub-expression is already diff --git a/src/language-js/print/call-arguments.js b/src/language-js/print/call-arguments.js index c415e836eb..c7a4e310cd 100644 --- a/src/language-js/print/call-arguments.js +++ b/src/language-js/print/call-arguments.js @@ -4,6 +4,8 @@ const { printDanglingComments } = require("../../main/comments"); const { getLast, getPenultimate } = require("../../common/util"); const { getFunctionParameters, + // [prettierx] --paren-spacing option support (...) + hasAddedLine, hasComment, CommentCheckFlags, isFunctionCompositionArgs, @@ -39,6 +41,10 @@ function printCallArguments(path, options, print) { const node = path.getValue(); const isDynamicImport = node.type === "ImportExpression"; + // [prettierx] for --paren-spacing option support (...) + const parenSpace = options.spaceInParens ? " " : ""; + const parenLine = options.spaceInParens ? line : softline; + const args = getCallArguments(node); if (args.length === 0) { return [ @@ -50,7 +56,16 @@ function printCallArguments(path, options, print) { // useEffect(() => { ... }, [foo, bar, baz]) if (isReactHookCallWithDepsArray(args)) { - return ["(", print(["arguments", 0]), ", ", print(["arguments", 1]), ")"]; + // [prettierx] with spaceInParens option support (...) + return [ + "(", + parenSpace, + print(["arguments", 0]), + ", ", + print(["arguments", 1]), + parenSpace, + ")", + ]; } let anyArgEmptyLine = false; @@ -84,9 +99,18 @@ function printCallArguments(path, options, print) { ? "," : ""; - function allArgsBrokenOut() { + // [prettierx] with lastArgAddedLine arg for --paren-spacing option support + function allArgsBrokenOut(lastArgAddedLine) { return group( - ["(", indent([line, ...printedArguments]), maybeTrailingComma, line, ")"], + [ + "(", + // [prettierx] keep break here, regardless of --paren-spacing option + indent([line, ...printedArguments]), + maybeTrailingComma, + // [prettierx] keep break here, unless lastArgAddedLine is true + lastArgAddedLine ? "" : line, + ")", + ], { shouldBreak: true } ); } @@ -99,6 +123,7 @@ function printCallArguments(path, options, print) { return allArgsBrokenOut(); } + // [prettierx] with --paren-spacing option support below (...) const shouldGroupFirst = shouldGroupFirstArg(args); const shouldGroupLast = shouldGroupLastArg(args, options); if (shouldGroupFirst || shouldGroupLast) { @@ -113,6 +138,9 @@ function printCallArguments(path, options, print) { // We want to print the last argument with a special flag let printedExpanded = []; + // [prettierx] keep for --paren-spacing option support (...) + let lastArgAddedLine = false; + try { path.try(() => { iterateCallArgumentsPath(path, (argPath, i) => { @@ -128,6 +156,14 @@ function printCallArguments(path, options, print) { ]; } if (shouldGroupLast && i === lastArgIndex) { + // [prettierx] with --paren-spacing option support (...) + + // [prettierx] keep for --paren-spacing option support (...) + const printedLastArg = print(argPath, { expandLastArg: true }); + + // [prettierx] with --paren-spacing option support (...) + lastArgAddedLine = hasAddedLine(printedLastArg); + printedExpanded = [ ...printedArguments.slice(0, -1), print([], { expandLastArg: true }), @@ -145,31 +181,51 @@ function printCallArguments(path, options, print) { return [ printedArguments.some(willBreak) ? breakParent : "", + // [prettierx] with --paren-spacing option support (...) conditionalGroup([ - ["(", ...printedExpanded, ")"], + [ + "(", + // [prettierx] spaceInParens option support (...) + parenSpace, + ...printedExpanded, + // [prettierx] spaceInParens option support (...) + lastArgAddedLine ? "" : parenSpace, + ")", + ], shouldGroupFirst ? [ "(", + // [prettierx] spaceInParens option support (...) + parenSpace, group(printedExpanded[0], { shouldBreak: true }), ...printedExpanded.slice(1), + // [prettierx] spaceInParens option support (...) + parenSpace, ")", ] : [ "(", + // [prettierx] spaceInParens option support (...) + parenSpace, ...printedArguments.slice(0, -1), group(getLast(printedExpanded), { shouldBreak: true }), + // [prettierx] spaceInParens option support (...) + lastArgAddedLine ? "" : parenSpace, ")", ], - allArgsBrokenOut(), + allArgsBrokenOut(lastArgAddedLine), ]), ]; } + // [prettierx] with --paren-spacing option support (...) const contents = [ "(", - indent([softline, ...printedArguments]), + // [prettierx] --paren-spacing option support (...) + indent([parenLine, ...printedArguments]), ifBreak(maybeTrailingComma), - softline, + // [prettierx] --paren-spacing option support (...) + parenLine, ")", ]; if (isLongCurriedCallExpression(path)) { diff --git a/src/language-js/print/call-expression.js b/src/language-js/print/call-expression.js index 81962434ee..464fdd028c 100644 --- a/src/language-js/print/call-expression.js +++ b/src/language-js/print/call-expression.js @@ -24,6 +24,9 @@ function printCallExpression(path, options, print) { const isNew = node.type === "NewExpression"; const isDynamicImport = node.type === "ImportExpression"; + // [prettierx] spaceInParens option support (...) + const parenSpace = options.spaceInParens ? " " : ""; + const optional = printOptionalToken(path); const args = getCallArguments(node); if ( @@ -50,7 +53,11 @@ function printCallExpression(path, options, print) { optional, printFunctionTypeParameters(path, options, print), "(", + // [prettierx] spaceInParens option support (...) + parenSpace, join(", ", printed), + // [prettierx] spaceInParens option support (...) + parenSpace, ")", ]; } diff --git a/src/language-js/print/function-parameters.js b/src/language-js/print/function-parameters.js index cd5ad46b92..f7d016eb94 100644 --- a/src/language-js/print/function-parameters.js +++ b/src/language-js/print/function-parameters.js @@ -36,6 +36,10 @@ function printFunctionParameters( ? printFunctionTypeParameters(path, options, print) : ""; + // [prettierx] spaceInParens option support (...) + const parenSpace = options.spaceInParens ? " " : ""; + const parenLine = options.spaceInParens ? line : softline; + if (parameters.length === 0) { return [ typeParams, @@ -93,7 +97,17 @@ function printFunctionParameters( // Removing lines in this case leads to broken or ugly output throw new ArgExpansionBailout(); } - return group([removeLines(typeParams), "(", removeLines(printed), ")"]); + // [prettierx] with --paren-spacing option support (...) + return group([ + removeLines(typeParams), + "(", + // [prettierx] spaceInParens option support (...) + parenSpace, + removeLines(printed), + // [prettierx] spaceInParens option support (...) + parenSpace, + ")", + ]); } // Single object destructuring should hug @@ -105,12 +119,32 @@ function printFunctionParameters( // }) {} const hasNotParameterDecorator = parameters.every((node) => !node.decorators); if (shouldHugParameters && hasNotParameterDecorator) { - return [typeParams, "(", ...printed, ")"]; + // [prettierx] with --paren-spacing option support (...) + return [ + typeParams, + "(", + // [prettierx] spaceInParens option support (...) + parenSpace, + ...printed, + // [prettierx] spaceInParens option support (...) + parenSpace, + ")", + ]; } // don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})` if (isParametersInTestCall) { - return [typeParams, "(", ...printed, ")"]; + // [prettierx] with --paren-spacing option support (...) + return [ + typeParams, + "(", + // [prettierx] spaceInParens option support (...) + parenSpace, + ...printed, + // [prettierx] spaceInParens option support (...) + parenSpace, + ")", + ]; } const isFlowShorthandWithOneArg = @@ -133,21 +167,25 @@ function printFunctionParameters( if (isFlowShorthandWithOneArg) { if (options.arrowParens === "always") { - return ["(", ...printed, ")"]; + // [prettierx] spaceInParens option support (...) + return ["(", parenSpace, ...printed, parenSpace, ")"]; } return printed; } + // [prettierx] with spaceInParens option support (...) return [ typeParams, "(", - indent([softline, ...printed]), + // [prettierx] spaceInParens option support (...) + indent([parenLine, ...printed]), ifBreak( !hasRestParameter(functionNode) && shouldPrintComma(options, "all") ? "," : "" ), - softline, + // [prettierx] spaceInParens option support (...) + parenLine, ")", ]; } diff --git a/src/language-js/print/function.js b/src/language-js/print/function.js index 78109891dd..33969d887e 100644 --- a/src/language-js/print/function.js +++ b/src/language-js/print/function.js @@ -27,6 +27,7 @@ const { const { ArgExpansionBailout } = require("../../common/errors"); const { getFunctionParameters, + hasAddedLine, // [prettierx] for spaceInParens option support hasLeadingOwnLineComment, isFlowAnnotationComment, isJsxNode, @@ -81,7 +82,8 @@ function printFunction(path, print, options, args) { } if (node.generator) { - parts.push("function* "); + // [prettierx] support generatorStarSpacing option (...) + parts.push("function", options.generatorStarSpacing ? " * " : "* "); } else { parts.push("function "); } @@ -105,6 +107,12 @@ function printFunction(path, print, options, args) { parts.push( printFunctionTypeParameters(path, options, print), group([ + // [prettierx] spaceBeforeFunctionParen & generatorStarSpacing + // option support (...) + (node.id || node.typeParameters) && + (options.spaceBeforeFunctionParen || options.generatorStarSpacing) + ? " " + : "", shouldGroupParameters ? group(parametersDoc) : parametersDoc, returnTypeDoc, ]), @@ -135,9 +143,14 @@ function printMethod(path, options, print) { parts.push(kind, " "); } + // [prettierx] with --generator-star-spacing option support (...) // A `getter`/`setter` can't be a generator, but it's recoverable if (value.generator) { parts.push("*"); + // [prettierx] --generator-star-spacing option support (...) + if (options.generatorStarSpacing) { + parts.push(" "); + } } parts.push( @@ -158,6 +171,7 @@ function printMethod(path, options, print) { return parts; } +// [prettierx] with --space-before-function-paren option support (...) function printMethodInternal(path, options, print) { const node = path.getNode(); const parametersDoc = printFunctionParameters(path, print, options); @@ -169,6 +183,8 @@ function printMethodInternal(path, options, print) { const parts = [ printFunctionTypeParameters(path, options, print), group([ + // [prettierx] --space-before-function-paren option support (...) + options.spaceBeforeFunctionParen ? " " : "", shouldGroupParameters ? group(parametersDoc) : parametersDoc, returnTypeDoc, ]), @@ -283,6 +299,10 @@ function printArrowFunction(path, options, print, args) { const body = []; let chainShouldBreak = false; + // [prettierx] spaceInParens option support (...) + const parenSpace = options.spaceInParens ? " " : ""; + const parenLine = options.spaceInParens ? line : softline; + (function rec() { const doc = printArrowFunctionSignature(path, options, print, args); if (signatures.length === 0) { @@ -337,7 +357,10 @@ function printArrowFunction(path, options, print, args) { node.body.type === "ArrowFunctionExpression" || node.body.type === "DoExpression") ) { - return group([...parts, " ", body]); + // [prettierx] with spaceInParens option support (...) + return group([...parts, " ", body], { + addedLine: hasAddedLine(body), // pass the option from a nested => arrow => function + }); } // We handle sequence expressions as the body of arrows specially, @@ -345,15 +368,17 @@ function printArrowFunction(path, options, print, args) { if (node.body.type === "SequenceExpression") { return group([ ...parts, - group([" (", indent([softline, body]), softline, ")"]), + // [prettierx] spaceInParens option support (...) + group([" (", indent([parenLine, body]), parenLine, ")"]), ]); } + // [prettierx] with --paren-spacing option support (...) // if the arrow function is expanded as last argument, we are adding a // level of indentation and need to add a softline to align the closing ) // with the opening (, or if it's inside a JSXExpression (e.g. an attribute) // we should align the expression's closing } with the line with the opening {. - const shouldAddSoftLine = + const shouldAddLine = ((args && args.expandLastArg) || path.getParentNode().type === "JSXExpressionContainer") && !hasComment(node); @@ -368,20 +393,25 @@ function printArrowFunction(path, options, print, args) { node.body.type === "ConditionalExpression" && !startsWithNoLookaheadToken(node.body, /* forbidFunctionAndClass */ false); - return group([ - ...parts, - group([ - indent([ - line, - shouldAddParens ? ifBreak("", "(") : "", - body, - shouldAddParens ? ifBreak("", ")") : "", + // [prettierx] with --paren-spacing option support (...) + return group( + [ + ...parts, + group([ + indent([ + line, + shouldAddParens ? ifBreak("", ["(", parenSpace]) : "", + body, + shouldAddParens ? ifBreak("", [parenSpace, ")"]) : "", + ]), + shouldAddLine + ? [ifBreak(printTrailingComma ? "," : ""), parenLine] + : "", ]), - shouldAddSoftLine - ? [ifBreak(printTrailingComma ? "," : ""), softline] - : "", - ]), - ]); + ], + // [prettierx] --paren-spacing option support (...) + { addedLine: shouldAddLine && options.spaceInParens } + ); } function canPrintParamsWithoutParens(node) { diff --git a/src/language-js/print/jsx.js b/src/language-js/print/jsx.js index 3b1f6ae386..cd3b48d4b3 100644 --- a/src/language-js/print/jsx.js +++ b/src/language-js/print/jsx.js @@ -25,6 +25,7 @@ const { isCallExpression, isStringLiteral, isBinaryish, + hasAddedLine, // [prettierx] for templateCurlySpacing option support (...) hasComment, CommentCheckFlags, hasNodeIgnoreComment, @@ -498,6 +499,10 @@ function printJsxExpressionContainer(path, options, print) { const node = path.getValue(); const parent = path.getParentNode(0); + // [prettierx] templateCurlySpacing option support (...) + const templateCurlySpace = options.templateCurlySpacing ? " " : ""; + const templateCurlyLine = options.templateCurlySpacing ? line : softline; + const shouldInline = node.expression.type === "JSXEmptyExpression" || (!hasComment(node.expression) && @@ -514,13 +519,27 @@ function printJsxExpressionContainer(path, options, print) { isBinaryish(node.expression))))); if (shouldInline) { - return group(["{", print("expression"), lineSuffixBoundary, "}"]); + // [prettierx] templateCurlySpacing option support (...) + const printed = print("expression"); + + return group([ + "{", + // [prettierx] templateCurlySpacing option support (...) + templateCurlySpace, + // [prettierx] templateCurlySpacing option support (...) + printed, + lineSuffixBoundary, + // [prettierx] templateCurlySpacing option support (...) + hasAddedLine(printed) ? "" : templateCurlySpace, + "}", + ]); } return group([ "{", - indent([softline, print("expression")]), - softline, + // [prettierx] templateCurlySpacing option support (...) + indent([templateCurlyLine, print("expression")]), + templateCurlyLine, lineSuffixBoundary, "}", ]); @@ -676,6 +695,11 @@ function printJsxEmptyExpression(path, options /*, print*/) { // `JSXSpreadAttribute` and `JSXSpreadChild` function printJsxSpreadAttribute(path, options, print) { const node = path.getValue(); + + // [prettierx] templateCurlySpacing option support (...) + const templateCurlySpace = options.templateCurlySpacing ? " " : ""; + const templateCurlyLine = options.templateCurlySpacing ? line : softline; + return [ "{", path.call( @@ -683,11 +707,14 @@ function printJsxSpreadAttribute(path, options, print) { const printed = ["...", print()]; const node = p.getValue(); if (!hasComment(node) || !willPrintOwnComments(p)) { - return printed; + // [prettierx] templateCurlySpacing option support (...) + return [templateCurlySpace, ...printed, templateCurlySpace]; } + // [prettierx] with templateCurlySpacing option support (...) return [ - indent([softline, printComments(p, printed, options)]), - softline, + // [prettierx] with templateCurlySpacing option support (...) + indent([templateCurlyLine, printComments(p, printed, options)]), + templateCurlyLine, ]; }, node.type === "JSXSpreadAttribute" ? "argument" : "expression" diff --git a/src/language-js/print/member-chain.js b/src/language-js/print/member-chain.js index fefca1fdd5..22b555a041 100644 --- a/src/language-js/print/member-chain.js +++ b/src/language-js/print/member-chain.js @@ -318,7 +318,9 @@ function printMemberChain(path, options, print) { if (groups.length === 0) { return ""; } - return indent(group([hardline, join(hardline, groups.map(printGroup))])); + // [prettierx]: --no-indent-chains option support + const printed = group([hardline, join(hardline, groups.map(printGroup))]); + return options.indentChains ? indent(printed) : printed; } const printedGroups = groups.map(printGroup); @@ -380,12 +382,16 @@ function printMemberChain(path, options, print) { // We don't want to print in one line if at least one of these conditions occurs: // * the chain has comments, + // * [prettierx] --break-long-method-chains option if enabled: + // the chain has at least 3 chained method calls, // * the chain is an expression statement and all the arguments are literal-like ("fluent configuration" pattern), // * the chain is longer than 2 calls and has non-trivial arguments or more than 2 arguments in any call but the first one, // * any group but the last one has a hard line, // * the last call's arguments have a hard line and other calls have non-trivial arguments. if ( nodeHasComment || + // [prettierx] breakLongMethodChains option support + (options.breakLongMethodChains && callExpressions.length >= 3) || (callExpressions.length > 2 && callExpressions.some( (expr) => !expr.arguments.every((arg) => isSimpleCallArgument(arg, 0)) diff --git a/src/language-js/print/member.js b/src/language-js/print/member.js index af0a620ddd..bb3b096010 100644 --- a/src/language-js/print/member.js +++ b/src/language-js/print/member.js @@ -1,7 +1,8 @@ "use strict"; const { - builders: { softline, group, indent, label }, + // [prettierx] computedPropertySpacing option support + builders: { softline, line, group, indent, label }, } = require("../../document"); const { isNumericLiteral, @@ -57,15 +58,37 @@ function printMemberLookup(path, options, print) { const node = path.getValue(); const optional = printOptionalToken(path); + // [prettierx] computedPropertySpacing option support + const computedPropertySpace = options.computedPropertySpacing ? " " : ""; + const computedPropertyLine = options.computedPropertySpacing + ? line + : softline; + if (!node.computed) { return [optional, ".", property]; } if (!node.property || isNumericLiteral(node.property)) { - return [optional, "[", property, "]"]; + // [prettierx] computedPropertySpacing option support + return [ + optional, + "[", + computedPropertySpace, + property, + computedPropertySpace, + "]", + ]; } - return group([optional, "[", indent([softline, property]), softline, "]"]); + // [prettierx] computedPropertySpacing option support + return group([ + optional, + "[", + // [prettierx] computedPropertySpacing option support + indent([computedPropertyLine, property]), + computedPropertyLine, + "]", + ]); } module.exports = { printMemberExpression, printMemberLookup }; diff --git a/src/language-js/print/module.js b/src/language-js/print/module.js index a32b495edc..cd6e392a8e 100644 --- a/src/language-js/print/module.js +++ b/src/language-js/print/module.js @@ -4,6 +4,7 @@ const { isNonEmptyArray } = require("../../common/util"); const { builders: { softline, group, indent, join, line, ifBreak, hardline }, } = require("../../document"); +const { removeLines } = require("../../document/doc-utils"); const { printDanglingComments } = require("../../main/comments"); const { @@ -182,19 +183,33 @@ function printModuleSpecifiers(path, options, print) { const standaloneSpecifiers = []; const groupedSpecifiers = []; + // [prettierx] for exportCurlySpacing, import CurlySpacing option support + let isExport = false; + + // [prettierx] with exportCurlySpacing, import CurlySpacing option support path.each(() => { const specifierType = path.getValue().type; if ( specifierType === "ExportNamespaceSpecifier" || - specifierType === "ExportDefaultSpecifier" || - specifierType === "ImportNamespaceSpecifier" || - specifierType === "ImportDefaultSpecifier" + specifierType === "ExportDefaultSpecifier" ) { + // [prettierx] exportCurlySpacing option + isExport = true; standaloneSpecifiers.push(print()); } else if ( - specifierType === "ExportSpecifier" || - specifierType === "ImportSpecifier" + specifierType === "ImportNamespaceSpecifier" || + specifierType === "ImportDefaultSpecifier" ) { + // [prettierx] importCurlySpacing option + isExport = false; + standaloneSpecifiers.push(print()); + } else if (specifierType === "ExportSpecifier") { + // [prettierx] exportCurlySpacing option + isExport = true; + groupedSpecifiers.push(print()); + } else if (specifierType === "ImportSpecifier") { + // [prettierx] importCurlySpacing option + isExport = false; groupedSpecifiers.push(print()); } else { /* istanbul ignore next */ @@ -203,40 +218,53 @@ function printModuleSpecifiers(path, options, print) { ); } }, "specifiers"); - parts.push(join(", ", standaloneSpecifiers)); + // [prettierx] for exportCurlySpacing, import CurlySpacing option support + const curlySpacing = isExport + ? options.exportCurlySpacing + : options.importCurlySpacing; + const curlyLine = curlySpacing ? line : softline; + if (groupedSpecifiers.length > 0) { if (standaloneSpecifiers.length > 0) { parts.push(", "); } const canBreak = - groupedSpecifiers.length > 1 || - standaloneSpecifiers.length > 0 || - node.specifiers.some((node) => hasComment(node)); + // prettierx: importFormatting + options.importFormatting !== "oneline" && + (groupedSpecifiers.length > 1 || + standaloneSpecifiers.length > 0 || + node.specifiers.some((node) => hasComment(node))); if (canBreak) { parts.push( group([ "{", indent([ - options.bracketSpacing ? line : softline, + // [prettierx] importCurlySpacing, exportCurlySpacing options + curlyLine, join([",", line], groupedSpecifiers), ]), ifBreak(shouldPrintComma(options) ? "," : ""), - options.bracketSpacing ? line : softline, + // [prettierx] importCurlySpacing, exportCurlySpacing options + curlyLine, "}", ]) ); } else { - parts.push([ - "{", - options.bracketSpacing ? " " : "", - ...groupedSpecifiers, - options.bracketSpacing ? " " : "", - "}", - ]); + parts.push( + removeLines([ + "{", + // [prettierx] importCurlySpacing, exportCurlySpacing options + curlyLine, + join([",", line], groupedSpecifiers), + // [prettierx] importCurlySpacing, exportCurlySpacing options + curlyLine, + "}", + ]) + ); } } } else { @@ -267,9 +295,11 @@ function printImportAssertions(path, options, print) { if (isNonEmptyArray(node.assertions)) { return [ " assert {", - options.bracketSpacing ? " " : "", + // [prettierx] importCurlySpacing option + options.importCurlySpacing ? " " : "", join(", ", path.map(print, "assertions")), - options.bracketSpacing ? " " : "", + // [prettierx] importCurlySpacing option + options.importCurlySpacing ? " " : "", "}", ]; } diff --git a/src/language-js/print/object.js b/src/language-js/print/object.js index 00afcfc6e0..2d7afaea85 100644 --- a/src/language-js/print/object.js +++ b/src/language-js/print/object.js @@ -26,21 +26,36 @@ const { printHardlineAfterHeritage } = require("./class"); /** @typedef {import("../../document").Doc} Doc */ +// [prettierx]: objectCurlySpacing, typeCurlySpacing option support +/** + * Returns the properties field and spacing option for the given node. + * @param {{type: string}} node + * @param {{typeCurlySpacing?: boolean, objectCurlySpacing?: boolean}} options + * @returns {[field: "members" | "body" | "properties", spacing: boolean]} + */ +function getFieldAndSpacing(node, options) { + switch (node.type) { + case "TSTypeLiteral": + return ["members", options.typeCurlySpacing]; + case "TSInterfaceBody": + return ["body", options.typeCurlySpacing]; + // [prettierx]: typeCurlySpacing option support + case "ObjectTypeAnnotation": + return ["properties", options.typeCurlySpacing]; + default: + return ["properties", options.objectCurlySpacing]; + } +} + function printObject(path, options, print) { const semi = options.semi ? ";" : ""; const node = path.getValue(); - let propertiesField; - - if (node.type === "TSTypeLiteral") { - propertiesField = "members"; - } else if (node.type === "TSInterfaceBody") { - propertiesField = "body"; - } else { - propertiesField = "properties"; - } + // [prettierx]: objectCurlySpacing, typeCurlySpacing option support + const [propertiesField, curlySpacing] = getFieldAndSpacing(node, options); const isTypeAnnotation = node.type === "ObjectTypeAnnotation"; + /** @type {string[]} */ const fields = [propertiesField]; if (isTypeAnnotation) { fields.push("indexers", "callProperties", "internalSlots"); @@ -187,14 +202,16 @@ function printObject(path, options, print) { ? printHardlineAfterHeritage(parent) : "", leftBrace, - indent([options.bracketSpacing ? line : softline, ...props]), + // [prettierx]: objectCurlySpacing, typeCurlySpacing option support + indent([curlySpacing ? line : softline, ...props]), ifBreak( canHaveTrailingSeparator && (separator !== "," || shouldPrintComma(options)) ? separator : "" ), - options.bracketSpacing ? line : softline, + // [prettierx]: objectCurlySpacing, typeCurlySpacing option support + curlySpacing ? line : softline, rightBrace, printOptionalToken(path), printTypeAnnotation(path, options, print), diff --git a/src/language-js/print/property.js b/src/language-js/print/property.js index b598c2c930..a9bc1af4a7 100644 --- a/src/language-js/print/property.js +++ b/src/language-js/print/property.js @@ -17,7 +17,17 @@ function printPropertyKey(path, options, print) { const node = path.getNode(); if (node.computed) { - return ["[", print("key"), "]"]; + // [prettierx] computedPropertySpacing option support (...) + const computedPropertySpace = options.computedPropertySpacing ? " " : ""; + + // [prettierx] computedPropertySpacing option support (...) + return [ + "[", + computedPropertySpace, + print("key"), + computedPropertySpace, + "]", + ]; } const parent = path.getParentNode(); @@ -89,17 +99,125 @@ function printPropertyKey(path, options, print) { return print("key"); } +// [prettierx] for alignObjectProperties option +// with computedPropertySpacing option support +function getPropertyPadding(options, path) { + if (!options.alignObjectProperties) { + return ""; + } + + if (/json/.test(options.parser)) { + return ""; + } + + const node = path.getValue(); + const { type } = node; + + // grandparent node: + const parentObject = path.getParentNode(1); + + const { locStart, locEnd } = options; + + // THIS IS A HACK: + const shouldBreak = options.originalText + .slice(locStart(parentObject), locEnd(parentObject)) + .match(/{\s*(\/.*)?\n/); + + if (!shouldBreak) { + return ""; + } + + const nameLength = + type === "Identifier" + ? node.name.length + : node.raw + ? node.raw.length + : node.extra.raw + ? node.extra.raw.length + : undefined; + + // [prettierx] computedPropertySpacing option support + const computedPropertyOverhead = options.computedPropertySpacing ? 4 : 2; + + // FUTURE TBD from arijs/prettier-miscellaneous#10 + // (does not seem to be needed to pass the tests): + // if (nameLength === undefined) { + // return ""; + // } + + const { properties } = parentObject; + const lengths = properties.map((property) => { + if (!property.key) { + return 0; + } + return ( + property.key.loc.end.column - + property.key.loc.start.column + + (property.computed ? computedPropertyOverhead : 0) + ); + }); + + const maxLength = Math.max.apply(null, lengths); + const padLength = maxLength - nameLength + 1; + + const padding = " ".repeat(padLength); + + return padding; +} + function printProperty(path, options, print) { const node = path.getValue(); if (node.shorthand) { return print("value"); } + // [prettierx] calculate property padding + // for alignObjectProperties option + const propertyPadding = path.call( + getPropertyPadding.bind(null, options), + "key" + ); + + // [prettierx] FUTURE TBD: it should be possible to refactor the code + // to use the same printPropertyKey call for both + // computed & non-computed properties + + // [prettierx] computedPropertySpacing option support + const computedPropertySpace = options.computedPropertySpacing ? " " : ""; + + // [prettierx] calculate this overhead in case it is needed, + // with computedPropertySpacing option support: + const computedPropertyOverhead = options.computedPropertySpacing ? 4 : 2; + + // [prettierx] compose left part, + // for alignObjectProperties option + const propertyLeftPart = node.computed + ? [ + // [prettierx] computed property key, + // with padding as needed for alignment + "[", + // [prettierx] computedPropertySpacing option support (...) + computedPropertySpace, + print("key"), + // [prettierx] computedPropertySpacing option support (...) + computedPropertySpace, + "]", + propertyPadding.slice(computedPropertyOverhead), + ] + : [ + // [prettierx] normal property key, + // for alignObjectProperties option + printPropertyKey(path, options, print), + propertyPadding, + ]; + return printAssignment( path, options, print, - printPropertyKey(path, options, print), + // [prettierx] with optional property alignment + // for alignObjectProperties option + propertyLeftPart, ":", "value" ); diff --git a/src/language-js/print/statement.js b/src/language-js/print/statement.js index 76365ec21d..b1e9be0249 100644 --- a/src/language-js/print/statement.js +++ b/src/language-js/print/statement.js @@ -135,6 +135,17 @@ function expressionNeedsASIProtection(path, options) { } break; } + // [prettierx] spaceInParens option support (...) + // needsParens is false for binaryish expr inside memberexpr, but is parenthesized nevertheless + case "MemberExpression": + if ( + !node.computed && + (node.object.type === "LogicalExpression" || + node.object.type === "BinaryExpression") + ) { + return true; + } + break; default: { if (isJsxNode(node)) { return true; diff --git a/src/language-js/print/template-literal.js b/src/language-js/print/template-literal.js index cfa61da53e..24bc7fca5d 100644 --- a/src/language-js/print/template-literal.js +++ b/src/language-js/print/template-literal.js @@ -7,6 +7,8 @@ const { join, hardline, softline, + // [prettierx] templateCurlySpacing option support (...) + line, group, indent, align, @@ -28,6 +30,10 @@ function printTemplateLiteral(path, print, options) { const node = path.getValue(); const isTemplateLiteral = node.type === "TemplateLiteral"; + // [prettierx] templateCurlySpacing option support (...) + const templateCurlySpace = options.templateCurlySpacing ? " " : ""; + const templateCurlyLine = options.templateCurlySpacing ? line : softline; + if ( isTemplateLiteral && isJestEachTemplateLiteral(node, path.getParentNode()) @@ -93,7 +99,11 @@ function printTemplateLiteral(path, print, options) { expression.type === "TSAsExpression" || isBinaryish(expression) ) { - printed = [indent([softline, printed]), softline]; + // [prettierx] templateCurlySpacing option support (...) + printed = [indent([templateCurlyLine, printed]), templateCurlyLine]; + } else { + // [prettierx] templateCurlySpacing option support (...) + printed = [templateCurlySpace, printed, templateCurlySpace]; } } @@ -128,14 +138,21 @@ function printJestEachTemplateLiteral(path, options, print) { const expressions = path.map(print, "expressions"); options.__inJestEach = false; const parts = []; + + // [prettierx] templateCurlySpacing option support (...) + const templateCurlySpace = options.templateCurlySpacing ? " " : ""; + const stringifiedExpressions = expressions.map( (doc) => + // [prettierx] templateCurlySpacing option support (...) "${" + + templateCurlySpace + printDocToString(doc, { ...options, printWidth: Number.POSITIVE_INFINITY, endOfLine: "lf", }).formatted + + templateCurlySpace + "}" ); @@ -200,18 +217,33 @@ function printJestEachTemplateLiteral(path, options, print) { } } -function printTemplateExpression(path, print) { +// [prettierx] templateCurlySpacing option support (...) +function printTemplateExpression(path, print, options) { const node = path.getValue(); let printed = print(); if (hasComment(node)) { printed = group([indent([softline, printed]), softline]); } - return ["${", printed, lineSuffixBoundary, "}"]; + + // [prettierx] templateCurlySpacing option support (...) + const templateCurlySpace = options.templateCurlySpacing ? " " : ""; + + // [prettierx] templateCurlySpacing option support (...) + return [ + "${", + templateCurlySpace, + printed, + lineSuffixBoundary, + templateCurlySpace, + "}", + ]; } -function printTemplateExpressions(path, print) { +// [prettierx] templateCurlySpacing option support (...) +function printTemplateExpressions(path, print, options) { return path.map( - (path) => printTemplateExpression(path, print), + // [prettierx] templateCurlySpacing option support (...) + (path) => printTemplateExpression(path, print, options), "expressions" ); } diff --git a/src/language-js/print/ternary.js b/src/language-js/print/ternary.js index 9f1c8aa2dd..0e1b2f614d 100644 --- a/src/language-js/print/ternary.js +++ b/src/language-js/print/ternary.js @@ -207,6 +207,10 @@ function printTernary(path, options, print) { const alternateNode = node[alternateNodePropertyName]; const parts = []; + // [prettierx] spaceInParens option support (...) + const parenSpace = options.spaceInParens ? " " : ""; + const parenLine = options.spaceInParens ? line : softline; + // We print a ConditionalExpression in either "JSX mode" or "normal mode". // See tests/jsx/conditional-expression.js for more info. let jsxMode = false; @@ -280,24 +284,42 @@ function printTernary(path, options, print) { const part = [ line, "? ", - consequentNode.type === node.type ? ifBreak("", "(") : "", - align(2, print(consequentNodePropertyName)), - consequentNode.type === node.type ? ifBreak("", ")") : "", + // [prettierx] spaceInParens option support (...) + ...(consequentNode.type === node.type + ? [ifBreak("", ["(", parenSpace])] + : [""]), + // [prettierx] offsetTernaryExpressions option support: + !options.offsetTernaryExpressions + ? align(2, print(consequentNodePropertyName)) + : print(consequentNodePropertyName), + // [prettierx] spaceInParens option support (...) + ...(consequentNode.type === node.type + ? [parenSpace, ifBreak("", ")")] + : [""]), line, ": ", - alternateNode.type === node.type + // [prettierx] offsetTernaryExpressions option support: + options.offsetTernaryExpressions || alternateNode.type === node.type ? print(alternateNodePropertyName) : align(2, print(alternateNodePropertyName)), ]; parts.push( + // [prettierx] with offsetTernaryExpressions option support below: parent.type !== node.type || parent[alternateNodePropertyName] === node || isParentTest ? part - : options.useTabs + : options.useTabs || options.offsetTernaryExpressions // [prettierx] offsetTernaryExpressions option support (...) ? dedent(indent(part)) : align(Math.max(0, options.tabWidth - 2), part) ); + + // [prettierx] offsetTernaryExpressions option support: + // Indent the whole ternary if offsetTernaryExpressions is enabled + // (like ESLint). + if (options.offsetTernaryExpressions) { + forceNoIndent = false; + } } // We want a whole chain of ConditionalExpressions to all @@ -319,12 +341,9 @@ function printTernary(path, options, print) { locEnd(comment) ) ); - const maybeGroup = (doc) => - parent === firstNonConditionalParent - ? group(doc, { shouldBreak }) - : shouldBreak - ? [doc, breakParent] - : doc; + // [prettierx] moved & updated for --space-in-parens option support (...) + // const maybeGroup = (doc) => + // ... // Break the closing paren to keep the chain right after it: // (a @@ -337,13 +356,22 @@ function printTernary(path, options, print) { (parent.type === "NGPipeExpression" && parent.left === node)) && !parent.computed; + // prettierx: with options for parenSpace support in ternaries (...) + const maybeGroup = (doc) => + parent === firstNonConditionalParent + ? group(doc, { breakParent, addedLine: breakClosingParen }) + : shouldBreak + ? [doc, breakParent] + : doc; + const shouldExtraIndent = shouldExtraIndentForConditionalExpression(path); const result = maybeGroup([ printTernaryTest(path, options, print), forceNoIndent ? parts : indent(parts), + // [prettierx]: spaceInParens option (...) isConditionalExpression && breakClosingParen && !shouldExtraIndent - ? softline + ? parenLine : "", ]); diff --git a/src/language-js/print/type-annotation.js b/src/language-js/print/type-annotation.js index f37f518bad..47b4167c6f 100644 --- a/src/language-js/print/type-annotation.js +++ b/src/language-js/print/type-annotation.js @@ -238,8 +238,12 @@ function printFunctionType(path, options, print) { needsColon = true; } + // [prettierx] spaceInParens option support (...) + const parenSpace = options.spaceInParens ? " " : ""; + if (needsParens) { - parts.push("("); + // [prettierx] spaceInParens option support (...) + parts.push("(", parenSpace); } const parametersDoc = printFunctionParameters( @@ -274,7 +278,8 @@ function printFunctionType(path, options, print) { } if (needsParens) { - parts.push(")"); + // [prettierx] spaceInParens option support (...) + parts.push(parenSpace, ")"); } return group(parts); @@ -302,7 +307,16 @@ function printIndexedAccessType(path, options, print) { const node = path.getValue(); const leftDelimiter = node.type === "OptionalIndexedAccessType" && node.optional ? "?.[" : "["; - return [print("objectType"), leftDelimiter, print("indexType"), "]"]; + return [ + print("objectType"), + leftDelimiter, + // [prettierx] typeBracketSpacing option support (...) + options.typeBracketSpacing ? " " : "", + print("indexType"), + // [prettierx] typeBracketSpacing option support (...) + options.typeBracketSpacing ? " " : "", + "]", + ]; } module.exports = { diff --git a/src/language-js/print/type-parameters.js b/src/language-js/print/type-parameters.js index f9aeaa3341..7228e895c2 100644 --- a/src/language-js/print/type-parameters.js +++ b/src/language-js/print/type-parameters.js @@ -20,6 +20,12 @@ const getTypeParametersGroupId = createGroupIdMapper("typeParameters"); function printTypeParameters(path, options, print, paramsKey) { const node = path.getValue(); + // [prettierx] typeAngleBracketSpacing option support (...) + const typeAngleBracketSpace = options.typeAngleBracketSpacing ? " " : ""; + const typeAngleBracketLine = options.typeAngleBracketSpacing + ? line + : softline; + if (!node[paramsKey]) { return ""; } @@ -40,9 +46,14 @@ function printTypeParameters(path, options, print, paramsKey) { node[paramsKey][0].type === "NullableTypeAnnotation")); if (shouldInline) { + // [prettierx] typeAngleBracketSpacing option support (...) return [ "<", + // [prettierx] typeAngleBracketSpacing option support (...) + typeAngleBracketSpace, join(", ", path.map(print, paramsKey)), + // [prettierx] typeAngleBracketSpacing option support (...) + typeAngleBracketSpace, printDanglingCommentsForInline(path, options), ">", ]; @@ -64,11 +75,20 @@ function printTypeParameters(path, options, print, paramsKey) { : ""; return group( + // [prettierx] typeAngleBracketSpacing option support (...) [ "<", - indent([softline, join([",", line], path.map(print, paramsKey))]), + // [prettierx] typeAngleBracketSpacing option support (...) + indent([ + // [prettierx] typeAngleBracketSpacing option support (...) + typeAngleBracketLine, + // [prettierx] keep break after comma here, + // regardless of typeAngleBracketSpacing option (...) + join([",", line], path.map(print, paramsKey)), + ]), trailingComma, - softline, + // [prettierx] typeAngleBracketSpacing option support (...) + typeAngleBracketLine, ">", ], { id: getTypeParametersGroupId(node) } @@ -97,7 +117,11 @@ function printTypeParameter(path, options, print) { const parts = []; const parent = path.getParentNode(); if (parent.type === "TSMappedType") { - parts.push("[", print("name")); + // [prettierx] typeBracketSpacing option support (...) + const typeBracketSpace = options.typeBracketSpacing ? " " : ""; + + // [prettierx] typeBracketSpacing option support (...) + parts.push("[", typeBracketSpace, print("name")); if (node.constraint) { parts.push(" in ", print("constraint")); } @@ -107,7 +131,8 @@ function printTypeParameter(path, options, print) { path.callParent(() => print("nameType")) ); } - parts.push("]"); + // [prettierx] typeBracketSpacing option support (...) + parts.push(typeBracketSpace, "]"); return parts; } diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index 3e7f1b88eb..eb5e283a8a 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -301,7 +301,8 @@ function printTypescript(path, options, print) { [ "{", indent([ - options.bracketSpacing ? line : softline, + // [prettierx] typeCurlySpacing option support: + options.typeCurlySpacing ? line : softline, node.readonly ? [ getTypeScriptMappedTypeModifier(node.readonly, "readonly"), @@ -318,7 +319,8 @@ function printTypescript(path, options, print) { ifBreak(semi), ]), printDanglingComments(path, options, /* sameIndent */ true), - options.bracketSpacing ? line : softline, + // [prettierx] typeCurlySpacing option support: + options.typeCurlySpacing ? line : softline, "}", ], { shouldBreak } diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 75f881a87a..c84085f7af 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -18,6 +18,8 @@ const preprocess = require("./print-preprocess"); const { hasFlowShorthandAnnotationComment, hasComment, + // [prettierx]: for --paren-spacing option support + hasAddedLine, CommentCheckFlags, isTheOnlyJsxElementInMarkdown, isBlockComment, @@ -28,6 +30,8 @@ const { hasIgnoreComment, isCallExpression, isMemberExpression, + // [prettierx]: for --paren-spacing option support + startsWithSpace, } = require("./utils"); const { locStart, locEnd } = require("./loc"); @@ -117,7 +121,17 @@ function genericPrint(path, options, print, args) { return args && args.needsSemi ? [";", printed] : printed; } - const parts = [args && args.needsSemi ? ";(" : "(", printed]; + // [prettierx] spaceInParens option support (...) + const parenSpace = options.spaceInParens ? " " : ""; + + const addLeadingSpace = !startsWithSpace(printed); + const addTrailingSpace = !hasAddedLine(printed); + + const parts = [ + args && args.needsSemi ? ";(" : "(", + addLeadingSpace ? parenSpace : "", + printed, + ]; if (hasFlowShorthandAnnotationComment(node)) { const [comment] = node.trailingComments; @@ -125,7 +139,8 @@ function genericPrint(path, options, print, args) { comment.printed = true; } - parts.push(")"); + // [prettierx] spaceInParens option support (...) + parts.push(addTrailingSpace ? parenSpace : "", ")"); return parts; } @@ -134,6 +149,10 @@ function printPathNoParens(path, options, print, args) { const node = path.getValue(); const semi = options.semi ? ";" : ""; + // [prettierx] spaceInParens option support (...) + const parenSpace = options.spaceInParens ? " " : ""; + const parenLine = options.spaceInParens ? line : softline; + if (!node) { return ""; } @@ -205,19 +224,22 @@ function printPathNoParens(path, options, print, args) { print("expression"), isTheOnlyJsxElementInMarkdown(options, path) ? "" : semi, ]; + // prettierx: spaceInParens option support (...) // Babel non-standard node. Used for Closure-style type casts. See postprocess.js. case "ParenthesizedExpression": { const shouldHug = !hasComment(node.expression) && (node.expression.type === "ObjectExpression" || node.expression.type === "ArrayExpression"); + // [prettierx] spaceInParens option support (...) if (shouldHug) { - return ["(", print("expression"), ")"]; + return ["(", parenSpace, print("expression"), parenSpace, ")"]; } return group([ "(", - indent([softline, print("expression")]), - softline, + // [prettierx] spaceInParens option support (...) + indent([parenLine, print("expression")]), + parenLine, ")", ]); } @@ -272,6 +294,10 @@ function printPathNoParens(path, options, print, args) { parts.push("yield"); if (node.delegate) { + // [prettierx] --yield-star-spacing option support (...) + if (options.yieldStarSpacing) { + parts.push(" "); + } parts.push("*"); } if (node.argument) { @@ -386,7 +412,18 @@ function printPathNoParens(path, options, print, args) { case "UnaryExpression": parts.push(node.operator); - if (/[a-z]$/.test(node.operator)) { + // [prettierx] spaceUnaryOps option support (...) + if ( + /[a-z]$/.test(node.operator) || + (options.spaceUnaryOps && + // [prettierx] no space between `!!` + !( + node.operator === "!" && + node.argument && + node.argument.type === "UnaryExpression" && + node.argument.operator === "!" + )) + ) { parts.push(" "); } @@ -453,9 +490,14 @@ function printPathNoParens(path, options, print, args) { return group(parts); } case "WithStatement": + // [prettierx] spaceInParens option support (...) return group([ "with (", + // [prettierx] spaceInParens option support (...) + parenSpace, print("object"), + // [prettierx] spaceInParens option support (...) + parenSpace, ")", adjustClause(node.body, print("body")), ]); @@ -463,7 +505,8 @@ function printPathNoParens(path, options, print, args) { const con = adjustClause(node.consequent, print("consequent")); const opening = group([ "if (", - group([indent([softline, print("test")]), softline]), + // [prettierx] spaceInParens option support (...) + group([indent([parenLine, print("test")]), parenLine]), ")", con, ]); @@ -471,19 +514,25 @@ function printPathNoParens(path, options, print, args) { parts.push(opening); if (node.alternate) { + // [prettierx] --break-before-else option support (...) const commentOnOwnLine = hasComment( node.consequent, - CommentCheckFlags.Trailing | CommentCheckFlags.Line + options.breakBeforeElse + ? CommentCheckFlags.Trailing + : CommentCheckFlags.Trailing | CommentCheckFlags.Line ) || needsHardlineAfterDanglingComment(node); + // [prettierx] --break-before-else option support (...) const elseOnSameLine = - node.consequent.type === "BlockStatement" && !commentOnOwnLine; + node.consequent.type === "BlockStatement" && + !commentOnOwnLine && + !options.breakBeforeElse; parts.push(elseOnSameLine ? " " : hardline); if (hasComment(node, CommentCheckFlags.Dangling)) { parts.push( printDanglingComments(path, options, true), - commentOnOwnLine ? hardline : " " + commentOnOwnLine || options.breakBeforeElse ? hardline : " " ); } @@ -521,10 +570,12 @@ function printPathNoParens(path, options, print, args) { return [ printedComments, group([ + // [prettierx] with --paren-spacing option support (...) "for (", group([ indent([ - softline, + // [prettierx] --paren-spacing option support (...) + parenLine, print("init"), ";", line, @@ -533,7 +584,8 @@ function printPathNoParens(path, options, print, args) { line, print("update"), ]), - softline, + // [prettierx] --paren-spacing option support (...) + parenLine, ]), ")", body, @@ -543,28 +595,39 @@ function printPathNoParens(path, options, print, args) { case "WhileStatement": return group([ "while (", - group([indent([softline, print("test")]), softline]), + // [prettierx] --paren-spacing option support (...) + group([indent([parenLine, print("test")]), parenLine]), ")", adjustClause(node.body, print("body")), ]); case "ForInStatement": + // [prettierx] spaceInParens option support (...) return group([ "for (", + // [prettierx] spaceInParens option support (...) + parenSpace, print("left"), " in ", print("right"), + // [prettierx] spaceInParens option support (...) + parenSpace, ")", adjustClause(node.body, print("body")), ]); case "ForOfStatement": + // [prettierx] spaceInParens option support (...) return group([ "for", node.await ? " await" : "", " (", + // [prettierx] spaceInParens option support (...) + parenSpace, print("left"), " of ", print("right"), + // [prettierx] spaceInParens option support (...) + parenSpace, ")", adjustClause(node.body, print("body")), ]); @@ -581,7 +644,8 @@ function printPathNoParens(path, options, print, args) { } parts.push( "while (", - group([indent([softline, print("test")]), softline]), + // [prettierx] spaceInParens option support (...) + group([indent([parenLine, print("test")]), parenLine]), ")", semi ); @@ -640,9 +704,10 @@ function printPathNoParens(path, options, print, args) { return [ "catch ", + // [prettierx] spaceInParens option support (...) parameterHasComments - ? ["(", indent([softline, param]), softline, ") "] - : ["(", param, ") "], + ? ["(", indent([parenLine, param]), parenLine, ") "] + : ["(", parenSpace, param, parenSpace, ") "], print("body"), ]; } @@ -651,10 +716,12 @@ function printPathNoParens(path, options, print, args) { // Note: ignoring n.lexical because it has no printing consequences. case "SwitchStatement": return [ + // [prettierx] spaceInParens option support (...) group([ "switch (", - indent([softline, print("discriminant")]), - softline, + // [prettierx] spaceInParens option support (...) + indent([parenLine, print("discriminant")]), + parenLine, ")", ]), " {", diff --git a/src/language-js/utils.js b/src/language-js/utils.js index 9aefc897b4..7d36916a51 100644 --- a/src/language-js/utils.js +++ b/src/language-js/utils.js @@ -668,6 +668,57 @@ function hasLeadingOwnLineComment(text, node) { ); } +// [prettierx] for --paren-spacing option support (...) +function startsWithSpace(arg) { + const getFirstItem = (item) => { + if (!item) { + return; + } + + if (Array.isArray(item)) { + if (item.length > 0) { + return getFirstItem(item[0]); + } + return; + } + + if (item.type === "group" || item.type === "indent") { + return getFirstItem(item.contents); + } + + return item; + }; + + const firstItem = getFirstItem(arg); + + return ( + firstItem && + (firstItem === " " || (firstItem.type === "line" && !firstItem.soft)) + ); +} + +// [prettierx] for --paren-spacing option support (...) +function hasAddedLine(arg) { + if (Array.isArray(arg)) { + if (arg.length > 0) { + return hasAddedLine(arg[0]); + } + return false; + } + + switch (arg.type) { + case "concat": + if (arg.parts.length > 0) { + return hasAddedLine(getLast(arg.parts)); + } + return false; + case "group": + return arg.addedLine; + default: + return false; + } +} + // Note: Quoting/unquoting numbers in TypeScript is not safe. // // let a = { 1: 1, 2: 2 } @@ -1315,6 +1366,8 @@ module.exports = { getLeftSidePathName, getParentExportDeclaration, getTypeScriptMappedTypeModifier, + // [prettierx]: for --paren-spacing support + hasAddedLine, hasFlowAnnotationComment, hasFlowShorthandAnnotationComment, hasLeadingOwnLineComment, @@ -1364,6 +1417,8 @@ module.exports = { isBitwiseOperator, shouldFlatten, startsWithNoLookaheadToken, + // [prettierx]: for --paren-spacing support + startsWithSpace, getPrecedence, hasComment, getComments, diff --git a/tests/format/angular/angular/__snapshots__/jsfmt.spec.js.snap b/tests/format/angular/angular/__snapshots__/jsfmt.spec.js.snap index 0f0b5368a5..36bf266453 100644 --- a/tests/format/angular/angular/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/angular/angular/__snapshots__/jsfmt.spec.js.snap @@ -1,8 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`angularjs.html - {"bracketSpacing":false} format 1`] = ` +exports[`angularjs.html - {"bogus":null,"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +bogus: null +objectCurlySpacing: false parsers: ["angular"] printWidth: 80 | printWidth @@ -236,9 +237,10 @@ printWidth: 80 ================================================================================ `; -exports[`attr-name.component.html - {"bracketSpacing":false} format 1`] = ` +exports[`attr-name.component.html - {"bogus":null,"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +bogus: null +objectCurlySpacing: false parsers: ["angular"] printWidth: 80 | printWidth @@ -312,9 +314,10 @@ printWidth: 80 ================================================================================ `; -exports[`attributes.component.html - {"bracketSpacing":false} format 1`] = ` +exports[`attributes.component.html - {"bogus":null,"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +bogus: null +objectCurlySpacing: false parsers: ["angular"] printWidth: 80 | printWidth @@ -1995,9 +1998,10 @@ printWidth: 80 ================================================================================ `; -exports[`first-lf.component.html - {"bracketSpacing":false} format 1`] = ` +exports[`first-lf.component.html - {"bogus":null,"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +bogus: null +objectCurlySpacing: false parsers: ["angular"] printWidth: 80 | printWidth @@ -2538,9 +2542,10 @@ printWidth: 80 ================================================================================ `; -exports[`ignore-attribute.component.html - {"bracketSpacing":false} format 1`] = ` +exports[`ignore-attribute.component.html - {"bogus":null,"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +bogus: null +objectCurlySpacing: false parsers: ["angular"] printWidth: 80 | printWidth @@ -2855,9 +2860,10 @@ printWidth: 80 ================================================================================ `; -exports[`interpolation.component.html - {"bracketSpacing":false} format 1`] = ` +exports[`interpolation.component.html - {"bogus":null,"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +bogus: null +objectCurlySpacing: false parsers: ["angular"] printWidth: 80 | printWidth @@ -3908,9 +3914,10 @@ printWidth: 80 ================================================================================ `; -exports[`real-world.component.html - {"bracketSpacing":false} format 1`] = ` +exports[`real-world.component.html - {"bogus":null,"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +bogus: null +objectCurlySpacing: false parsers: ["angular"] printWidth: 80 | printWidth @@ -13688,9 +13695,10 @@ can be found in the LICENSE file at http://angular.io/license ================================================================================ `; -exports[`tag-name.component.html - {"bracketSpacing":false} format 1`] = ` +exports[`tag-name.component.html - {"bogus":null,"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +bogus: null +objectCurlySpacing: false parsers: ["angular"] printWidth: 80 | printWidth diff --git a/tests/format/angular/angular/jsfmt.spec.js b/tests/format/angular/angular/jsfmt.spec.js index 1c52f201d7..6c725a1d9a 100644 --- a/tests/format/angular/angular/jsfmt.spec.js +++ b/tests/format/angular/angular/jsfmt.spec.js @@ -2,4 +2,9 @@ run_spec(__dirname, ["angular"], { trailingComma: "none" }); run_spec(__dirname, ["angular"]); run_spec(__dirname, ["angular"], { printWidth: 1 }); run_spec(__dirname, ["angular"], { htmlWhitespaceSensitivity: "ignore" }); -run_spec(__dirname, ["angular"], { bracketSpacing: false }); +run_spec(__dirname, ["angular"], { + // [prettierx] bogus option to keep snapshot more consistent with Prettier 2.3.1 + bogus: null, + // [prettierx] updated option: + objectCurlySpacing: false, +}); diff --git a/tests/format/js/bracket-spacing/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/bracket-spacing/__snapshots__/jsfmt.spec.js.snap index 755f8f7c3f..204d1abfd9 100644 --- a/tests/format/js/bracket-spacing/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/bracket-spacing/__snapshots__/jsfmt.spec.js.snap @@ -1,8 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`array.js - {"bracketSpacing":false} format 1`] = ` +exports[`array.js - {"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +objectCurlySpacing: false parsers: ["babel", "flow", "typescript"] printWidth: 80 | printWidth @@ -33,9 +33,9 @@ const arr2 = [1, 2, 3, 4]; ================================================================================ `; -exports[`object.js - {"bracketSpacing":false} format 1`] = ` +exports[`object.js - {"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +objectCurlySpacing: false parsers: ["babel", "flow", "typescript"] printWidth: 80 | printWidth diff --git a/tests/format/js/bracket-spacing/jsfmt.spec.js b/tests/format/js/bracket-spacing/jsfmt.spec.js index df3db0cc4b..94efa7bdae 100644 --- a/tests/format/js/bracket-spacing/jsfmt.spec.js +++ b/tests/format/js/bracket-spacing/jsfmt.spec.js @@ -1,2 +1,5 @@ run_spec(__dirname, ["babel", "flow", "typescript"]); -run_spec(__dirname, ["babel", "flow", "typescript"], { bracketSpacing: false }); +// [prettierx]: broken-out bracket spacing options +run_spec(__dirname, ["babel", "flow", "typescript"], { + objectCurlySpacing: false, +}); diff --git a/tests/format/js/export/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/export/__snapshots__/jsfmt.spec.js.snap index f34ad6b8c1..11068e90cc 100644 --- a/tests/format/js/export/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/export/__snapshots__/jsfmt.spec.js.snap @@ -1,8 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`bracket.js - {"bracketSpacing":false} format 1`] = ` +exports[`bracket.js - {"exportCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +exportCurlySpacing: false parsers: ["babel", "flow", "typescript"] printWidth: 80 | printWidth @@ -109,9 +109,9 @@ export { fitsIn, oneLine }; ================================================================================ `; -exports[`empty.js - {"bracketSpacing":false} format 1`] = ` +exports[`empty.js - {"exportCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +exportCurlySpacing: false parsers: ["babel", "flow", "typescript"] printWidth: 80 | printWidth @@ -142,9 +142,9 @@ export {} from "."; ================================================================================ `; -exports[`same-local-and-exported.js - {"bracketSpacing":false} format 1`] = ` +exports[`same-local-and-exported.js - {"exportCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +exportCurlySpacing: false parsers: ["babel", "flow", "typescript"] printWidth: 80 | printWidth diff --git a/tests/format/js/export/jsfmt.spec.js b/tests/format/js/export/jsfmt.spec.js index df3db0cc4b..c5a04e8575 100644 --- a/tests/format/js/export/jsfmt.spec.js +++ b/tests/format/js/export/jsfmt.spec.js @@ -1,2 +1,5 @@ run_spec(__dirname, ["babel", "flow", "typescript"]); -run_spec(__dirname, ["babel", "flow", "typescript"], { bracketSpacing: false }); +run_spec(__dirname, ["babel", "flow", "typescript"], { + // [prettierx]: broken-out bracket spacing options + exportCurlySpacing: false, +}); diff --git a/tests/format/js/import-assertions/bracket-spacing/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/import-assertions/bracket-spacing/__snapshots__/jsfmt.spec.js.snap index 96bf68213b..3ea05b6cff 100644 --- a/tests/format/js/import-assertions/bracket-spacing/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/import-assertions/bracket-spacing/__snapshots__/jsfmt.spec.js.snap @@ -1,22 +1,24 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`dynamic-import.js - {"bracketSpacing":false} [espree] format 1`] = ` +exports[`dynamic-import.js - {"exportCurlySpacing":false,"importCurlySpacing":false,"objectCurlySpacing":false} [espree] format 1`] = ` "Unexpected token , (1:20) > 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } }); | ^ 2 |" `; -exports[`dynamic-import.js - {"bracketSpacing":false} [meriyah] format 1`] = ` +exports[`dynamic-import.js - {"exportCurlySpacing":false,"importCurlySpacing":false,"objectCurlySpacing":false} [meriyah] format 1`] = ` "[1:20]: Expected ')' (1:20) > 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } }); | ^ 2 |" `; -exports[`dynamic-import.js - {"bracketSpacing":false} format 1`] = ` +exports[`dynamic-import.js - {"exportCurlySpacing":false,"importCurlySpacing":false,"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +exportCurlySpacing: false +importCurlySpacing: false +objectCurlySpacing: false parsers: ["babel"] printWidth: 80 | printWidth @@ -29,21 +31,23 @@ import("./foo.json", {assert: {type: "json"}}); ================================================================================ `; -exports[`empty.js - {"bracketSpacing":false} [espree] format 1`] = ` +exports[`empty.js - {"exportCurlySpacing":false,"importCurlySpacing":false,"objectCurlySpacing":false} [espree] format 1`] = ` "Unexpected token assert (1:33) > 1 | export * as bar from \\"bar.json\\" assert { } | ^" `; -exports[`empty.js - {"bracketSpacing":false} [meriyah] format 1`] = ` +exports[`empty.js - {"exportCurlySpacing":false,"importCurlySpacing":false,"objectCurlySpacing":false} [meriyah] format 1`] = ` "[1:38]: Unexpected token: 'identifier' (1:38) > 1 | export * as bar from \\"bar.json\\" assert { } | ^" `; -exports[`empty.js - {"bracketSpacing":false} format 1`] = ` +exports[`empty.js - {"exportCurlySpacing":false,"importCurlySpacing":false,"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +exportCurlySpacing: false +importCurlySpacing: false +objectCurlySpacing: false parsers: ["babel"] printWidth: 80 | printWidth @@ -55,23 +59,25 @@ export * as bar from "bar.json"; ================================================================================ `; -exports[`re-export.js - {"bracketSpacing":false} [espree] format 1`] = ` +exports[`re-export.js - {"exportCurlySpacing":false,"importCurlySpacing":false,"objectCurlySpacing":false} [espree] format 1`] = ` "Unexpected token assert (1:33) > 1 | export { foo2 } from \\"foo.json\\" assert { type: \\"json\\" }; | ^ 2 |" `; -exports[`re-export.js - {"bracketSpacing":false} [meriyah] format 1`] = ` +exports[`re-export.js - {"exportCurlySpacing":false,"importCurlySpacing":false,"objectCurlySpacing":false} [meriyah] format 1`] = ` "[1:38]: Unexpected token: 'identifier' (1:38) > 1 | export { foo2 } from \\"foo.json\\" assert { type: \\"json\\" }; | ^ 2 |" `; -exports[`re-export.js - {"bracketSpacing":false} format 1`] = ` +exports[`re-export.js - {"exportCurlySpacing":false,"importCurlySpacing":false,"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +exportCurlySpacing: false +importCurlySpacing: false +objectCurlySpacing: false parsers: ["babel"] printWidth: 80 | printWidth @@ -84,23 +90,25 @@ export {foo2} from "foo.json" assert {type: "json"}; ================================================================================ `; -exports[`static-import.js - {"bracketSpacing":false} [espree] format 1`] = ` +exports[`static-import.js - {"exportCurlySpacing":false,"importCurlySpacing":false,"objectCurlySpacing":false} [espree] format 1`] = ` "Unexpected token assert (1:31) > 1 | import json from \\"./foo.json\\" assert { type: \\"json\\" }; | ^ 2 |" `; -exports[`static-import.js - {"bracketSpacing":false} [meriyah] format 1`] = ` +exports[`static-import.js - {"exportCurlySpacing":false,"importCurlySpacing":false,"objectCurlySpacing":false} [meriyah] format 1`] = ` "[1:36]: Unexpected token: 'identifier' (1:36) > 1 | import json from \\"./foo.json\\" assert { type: \\"json\\" }; | ^ 2 |" `; -exports[`static-import.js - {"bracketSpacing":false} format 1`] = ` +exports[`static-import.js - {"exportCurlySpacing":false,"importCurlySpacing":false,"objectCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +exportCurlySpacing: false +importCurlySpacing: false +objectCurlySpacing: false parsers: ["babel"] printWidth: 80 | printWidth diff --git a/tests/format/js/import-assertions/bracket-spacing/jsfmt.spec.js b/tests/format/js/import-assertions/bracket-spacing/jsfmt.spec.js index 141e96b4f2..f20e69a5f4 100644 --- a/tests/format/js/import-assertions/bracket-spacing/jsfmt.spec.js +++ b/tests/format/js/import-assertions/bracket-spacing/jsfmt.spec.js @@ -1,5 +1,8 @@ run_spec(__dirname, ["babel"], { - bracketSpacing: false, + // [prettierx]: broken-out bracket spacing options + exportCurlySpacing: false, + importCurlySpacing: false, + objectCurlySpacing: false, errors: { espree: [ "dynamic-import.js", diff --git a/tests/format/js/import/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/import/__snapshots__/jsfmt.spec.js.snap index c61aafb154..23678bb09e 100644 --- a/tests/format/js/import/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/import/__snapshots__/jsfmt.spec.js.snap @@ -1,8 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`brackets.js - {"bracketSpacing":false} format 1`] = ` +exports[`brackets.js - {"importCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +importCurlySpacing: false parsers: ["babel", "flow", "typescript"] printWidth: 80 | printWidth @@ -69,9 +69,9 @@ import { fitsIn, oneLine } from "."; ================================================================================ `; -exports[`comments.js - {"bracketSpacing":false} format 1`] = ` +exports[`comments.js - {"importCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +importCurlySpacing: false parsers: ["babel", "flow", "typescript"] printWidth: 80 | printWidth @@ -278,9 +278,9 @@ import x, { ================================================================================ `; -exports[`empty-import.js - {"bracketSpacing":false} format 1`] = ` +exports[`empty-import.js - {"importCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +importCurlySpacing: false parsers: ["babel", "flow", "typescript"] printWidth: 80 | printWidth @@ -307,9 +307,9 @@ import {} from "@types/googlemaps"; ================================================================================ `; -exports[`inline.js - {"bracketSpacing":false} format 1`] = ` +exports[`inline.js - {"importCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +importCurlySpacing: false parsers: ["babel", "flow", "typescript"] printWidth: 80 | printWidth @@ -358,9 +358,9 @@ import { ================================================================================ `; -exports[`long-line.js - {"bracketSpacing":false} format 1`] = ` +exports[`long-line.js - {"importCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +importCurlySpacing: false parsers: ["babel", "flow", "typescript"] printWidth: 80 | printWidth @@ -387,9 +387,9 @@ import someCoolUtilWithARatherLongName from "../../../../utils/someCoolUtilWithA ================================================================================ `; -exports[`multiple_standalones.js - {"bracketSpacing":false} format 1`] = ` +exports[`multiple_standalones.js - {"importCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +importCurlySpacing: false parsers: ["babel", "flow", "typescript"] printWidth: 80 | printWidth @@ -416,9 +416,9 @@ import a, * as b from "a"; ================================================================================ `; -exports[`same-local-and-imported.js - {"bracketSpacing":false} format 1`] = ` +exports[`same-local-and-imported.js - {"importCurlySpacing":false} format 1`] = ` ====================================options===================================== -bracketSpacing: false +importCurlySpacing: false parsers: ["babel", "flow", "typescript"] printWidth: 80 | printWidth diff --git a/tests/format/js/import/jsfmt.spec.js b/tests/format/js/import/jsfmt.spec.js index df3db0cc4b..473d86547c 100644 --- a/tests/format/js/import/jsfmt.spec.js +++ b/tests/format/js/import/jsfmt.spec.js @@ -1,2 +1,5 @@ run_spec(__dirname, ["babel", "flow", "typescript"]); -run_spec(__dirname, ["babel", "flow", "typescript"], { bracketSpacing: false }); +run_spec(__dirname, ["babel", "flow", "typescript"], { + // [prettierx]: broken-out bracket spacing options + importCurlySpacing: false, +}); diff --git a/tests/integration/__tests__/__snapshots__/early-exit.js.snap b/tests/integration/__tests__/__snapshots__/early-exit.js.snap index aa40cd9523..7828f4882c 100644 --- a/tests/integration/__tests__/__snapshots__/early-exit.js.snap +++ b/tests/integration/__tests__/__snapshots__/early-exit.js.snap @@ -58,23 +58,51 @@ Output options: Format options: + --align-object-properties + Align colons in multiline object literals. + Defaults to false. + --array-bracket-spacing Put spaces between array brackets (similar to the corresponding eslint option). Status: experimental, with limited testing. + Defaults to false. --arrow-parens Include parentheses around a sole arrow function parameter. Defaults to always. --no-bracket-spacing Do not print spaces between brackets. + --break-before-else Always add a line break before else. + Defaults to false. + --break-long-method-chains + Break method chains with more than 3 method calls, like Prettier 1.x. + Defaults to false. + --computed-property-spacing + Put spaces between computed property brackets (similar to the corresponding eslint option). Status: experimental, with limited testing. + Defaults to false. --embedded-language-formatting Control how Prettier formats quoted code embedded in the file. Defaults to auto. --end-of-line Which end of line characters to apply. Defaults to lf. + --no-export-curly-spacing + Disable spaces between export curly braces. + --generator-star-spacing Put spaces around the star (\`*\`) in generator functions (before and after - similar to the corresponding eslint option). (Default is after only.) + Defaults to false. --html-whitespace-sensitivity How to handle whitespaces in HTML. Defaults to css. + --no-import-curly-spacing + Disable spaces between import curly braces. + --import-formatting + Formatting of import statements, may be \`oneline\` to avoid conflict with VSCode \\"Organize Imports\\" feature. + Defaults to auto. + --no-indent-chains Disable indents at the start of chained calls. --jsx-bracket-same-line Put > on the last line instead of at a new line. Defaults to false. --jsx-single-quote Use single quotes in JSX. Defaults to false. + --no-object-curly-spacing + Disable spaces between object curly braces. + --offset-ternary-expressions + Indent and align ternary expression branches more consistently with \\"Standard JS\\" (similar to the corresponding eslint option). + Defaults to false. --parser Which parser to use. --print-width The line length where Prettier will try wrap. @@ -88,16 +116,33 @@ Format options: --no-semi Do not print semicolons, except at the beginning of lines which may need them. --single-quote Use single quotes instead of double quotes. Defaults to false. + --space-before-function-paren + Put a space before function parenthesis in all declarations (similar to the corresponding eslint option). (Default is to put a space before function parenthesis for untyped anonymous functions only.) + Defaults to false. + --space-in-parens Print spaces in between parens, WordPress style (similar to the corresponding eslint option). Not recommended in combination with the default \`arrowParens: \\"always\\"\` option. Status: experimental, with limited testing. + Defaults to false. + --space-unary-ops Put spaces after unary operator symbols, except in the middle of \`!!\` (similar to the corresponding eslint option). Status: experimental, with limited testing. + Defaults to false. --tab-width Number of spaces per indentation level. Defaults to 2. + --template-curly-spacing Put spaces between template curly brackets (similar to the corresponding eslint option). Status: experimental, with limited testing. + Defaults to false. --trailing-comma Print trailing commas wherever possible when multi-line. Defaults to es5. + --type-angle-bracket-spacing + Put spaces between type angle brackets. Status: experimental, with limited testing. + Defaults to false. + --type-bracket-spacing Print spaces between type brackets. Status: experimental, with limited testing. + Defaults to false. + --no-type-curly-spacing Disable spaces between type curly braces. --use-tabs Indent with tabs instead of spaces. Defaults to false. --vue-indent-script-and-style Indent script and style tags in Vue files. Defaults to false. + --yield-star-spacing Put spaces around the star (\`*\`) in \`yield*\` expressions (before and after - similar to the corresponding eslint option). (Default is after only.) + Defaults to false. Config options: @@ -223,23 +268,51 @@ Output options: Format options: + --align-object-properties + Align colons in multiline object literals. + Defaults to false. + --array-bracket-spacing Put spaces between array brackets (similar to the corresponding eslint option). Status: experimental, with limited testing. + Defaults to false. --arrow-parens Include parentheses around a sole arrow function parameter. Defaults to always. --no-bracket-spacing Do not print spaces between brackets. + --break-before-else Always add a line break before else. + Defaults to false. + --break-long-method-chains + Break method chains with more than 3 method calls, like Prettier 1.x. + Defaults to false. + --computed-property-spacing + Put spaces between computed property brackets (similar to the corresponding eslint option). Status: experimental, with limited testing. + Defaults to false. --embedded-language-formatting Control how Prettier formats quoted code embedded in the file. Defaults to auto. --end-of-line Which end of line characters to apply. Defaults to lf. + --no-export-curly-spacing + Disable spaces between export curly braces. + --generator-star-spacing Put spaces around the star (\`*\`) in generator functions (before and after - similar to the corresponding eslint option). (Default is after only.) + Defaults to false. --html-whitespace-sensitivity How to handle whitespaces in HTML. Defaults to css. + --no-import-curly-spacing + Disable spaces between import curly braces. + --import-formatting + Formatting of import statements, may be \`oneline\` to avoid conflict with VSCode \\"Organize Imports\\" feature. + Defaults to auto. + --no-indent-chains Disable indents at the start of chained calls. --jsx-bracket-same-line Put > on the last line instead of at a new line. Defaults to false. --jsx-single-quote Use single quotes in JSX. Defaults to false. + --no-object-curly-spacing + Disable spaces between object curly braces. + --offset-ternary-expressions + Indent and align ternary expression branches more consistently with \\"Standard JS\\" (similar to the corresponding eslint option). + Defaults to false. --parser Which parser to use. --print-width The line length where Prettier will try wrap. @@ -253,16 +326,33 @@ Format options: --no-semi Do not print semicolons, except at the beginning of lines which may need them. --single-quote Use single quotes instead of double quotes. Defaults to false. + --space-before-function-paren + Put a space before function parenthesis in all declarations (similar to the corresponding eslint option). (Default is to put a space before function parenthesis for untyped anonymous functions only.) + Defaults to false. + --space-in-parens Print spaces in between parens, WordPress style (similar to the corresponding eslint option). Not recommended in combination with the default \`arrowParens: \\"always\\"\` option. Status: experimental, with limited testing. + Defaults to false. + --space-unary-ops Put spaces after unary operator symbols, except in the middle of \`!!\` (similar to the corresponding eslint option). Status: experimental, with limited testing. + Defaults to false. --tab-width Number of spaces per indentation level. Defaults to 2. + --template-curly-spacing Put spaces between template curly brackets (similar to the corresponding eslint option). Status: experimental, with limited testing. + Defaults to false. --trailing-comma Print trailing commas wherever possible when multi-line. Defaults to es5. + --type-angle-bracket-spacing + Put spaces between type angle brackets. Status: experimental, with limited testing. + Defaults to false. + --type-bracket-spacing Print spaces between type brackets. Status: experimental, with limited testing. + Defaults to false. + --no-type-curly-spacing Disable spaces between type curly braces. --use-tabs Indent with tabs instead of spaces. Defaults to false. --vue-indent-script-and-style Indent script and style tags in Vue files. Defaults to false. + --yield-star-spacing Put spaces around the star (\`*\`) in \`yield*\` expressions (before and after - similar to the corresponding eslint option). (Default is after only.) + Defaults to false. Config options: diff --git a/tests/integration/__tests__/__snapshots__/help-options.js.snap b/tests/integration/__tests__/__snapshots__/help-options.js.snap index 0d8680b47c..c59c1fb5a7 100644 --- a/tests/integration/__tests__/__snapshots__/help-options.js.snap +++ b/tests/integration/__tests__/__snapshots__/help-options.js.snap @@ -1,5 +1,31 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`show detailed usage with --help align-object-properties (stderr) 1`] = `""`; + +exports[`show detailed usage with --help align-object-properties (stdout) 1`] = ` +"--align-object-properties + + Align colons in multiline object literals. + +Default: false +" +`; + +exports[`show detailed usage with --help align-object-properties (write) 1`] = `Array []`; + +exports[`show detailed usage with --help array-bracket-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help array-bracket-spacing (stdout) 1`] = ` +"--array-bracket-spacing + + Put spaces between array brackets (similar to the corresponding eslint option). Status: experimental, with limited testing. + +Default: false +" +`; + +exports[`show detailed usage with --help array-bracket-spacing (write) 1`] = `Array []`; + exports[`show detailed usage with --help arrow-parens (stderr) 1`] = `""`; exports[`show detailed usage with --help arrow-parens (stdout) 1`] = ` @@ -31,6 +57,32 @@ Default: true exports[`show detailed usage with --help bracket-spacing (write) 1`] = `Array []`; +exports[`show detailed usage with --help break-before-else (stderr) 1`] = `""`; + +exports[`show detailed usage with --help break-before-else (stdout) 1`] = ` +"--break-before-else + + Always add a line break before else. + +Default: false +" +`; + +exports[`show detailed usage with --help break-before-else (write) 1`] = `Array []`; + +exports[`show detailed usage with --help break-long-method-chains (stderr) 1`] = `""`; + +exports[`show detailed usage with --help break-long-method-chains (stdout) 1`] = ` +"--break-long-method-chains + + Break method chains with more than 3 method calls, like Prettier 1.x. + +Default: false +" +`; + +exports[`show detailed usage with --help break-long-method-chains (write) 1`] = `Array []`; + exports[`show detailed usage with --help check (stderr) 1`] = `""`; exports[`show detailed usage with --help check (stdout) 1`] = ` @@ -56,6 +108,19 @@ Default: true exports[`show detailed usage with --help color (write) 1`] = `Array []`; +exports[`show detailed usage with --help computed-property-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help computed-property-spacing (stdout) 1`] = ` +"--computed-property-spacing + + Put spaces between computed property brackets (similar to the corresponding eslint option). Status: experimental, with limited testing. + +Default: false +" +`; + +exports[`show detailed usage with --help computed-property-spacing (write) 1`] = `Array []`; + exports[`show detailed usage with --help config (stderr) 1`] = `""`; exports[`show detailed usage with --help config (stdout) 1`] = ` @@ -153,6 +218,19 @@ Default: lf exports[`show detailed usage with --help end-of-line (write) 1`] = `Array []`; +exports[`show detailed usage with --help export-curly-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help export-curly-spacing (stdout) 1`] = ` +"--export-curly-spacing + + Put spaces between export curly braces. + +Default: true +" +`; + +exports[`show detailed usage with --help export-curly-spacing (write) 1`] = `Array []`; + exports[`show detailed usage with --help file-info (stderr) 1`] = `""`; exports[`show detailed usage with --help file-info (stdout) 1`] = ` @@ -177,6 +255,19 @@ exports[`show detailed usage with --help find-config-path (stdout) 1`] = ` exports[`show detailed usage with --help find-config-path (write) 1`] = `Array []`; +exports[`show detailed usage with --help generator-star-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help generator-star-spacing (stdout) 1`] = ` +"--generator-star-spacing + + Put spaces around the star (\`*\`) in generator functions (before and after - similar to the corresponding eslint option). (Default is after only.) + +Default: false +" +`; + +exports[`show detailed usage with --help generator-star-spacing (write) 1`] = `Array []`; + exports[`show detailed usage with --help help (stderr) 1`] = `""`; exports[`show detailed usage with --help help (stdout) 1`] = ` @@ -232,6 +323,50 @@ exports[`show detailed usage with --help ignore-unknown (stdout) 1`] = ` exports[`show detailed usage with --help ignore-unknown (write) 1`] = `Array []`; +exports[`show detailed usage with --help import-curly-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help import-curly-spacing (stdout) 1`] = ` +"--import-curly-spacing + + Put spaces between import curly braces. + +Default: true +" +`; + +exports[`show detailed usage with --help import-curly-spacing (write) 1`] = `Array []`; + +exports[`show detailed usage with --help import-formatting (stderr) 1`] = `""`; + +exports[`show detailed usage with --help import-formatting (stdout) 1`] = ` +"--import-formatting + + Formatting of import statements, may be \`oneline\` to avoid conflict with VSCode \\"Organize Imports\\" feature. + +Valid options: + + auto automatic formatting, like Prettier + oneline keep import statements on one line + +Default: auto +" +`; + +exports[`show detailed usage with --help import-formatting (write) 1`] = `Array []`; + +exports[`show detailed usage with --help indent-chains (stderr) 1`] = `""`; + +exports[`show detailed usage with --help indent-chains (stdout) 1`] = ` +"--indent-chains + + Put indents at the start of chained calls. + +Default: true +" +`; + +exports[`show detailed usage with --help indent-chains (write) 1`] = `Array []`; + exports[`show detailed usage with --help insert-pragma (stderr) 1`] = `""`; exports[`show detailed usage with --help insert-pragma (stdout) 1`] = ` @@ -358,6 +493,50 @@ exports[`show detailed usage with --help no-error-on-unmatched-pattern (stdout) exports[`show detailed usage with --help no-error-on-unmatched-pattern (write) 1`] = `Array []`; +exports[`show detailed usage with --help no-export-curly-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help no-export-curly-spacing (stdout) 1`] = ` +"--no-export-curly-spacing + + Disable spaces between export curly braces. +" +`; + +exports[`show detailed usage with --help no-export-curly-spacing (write) 1`] = `Array []`; + +exports[`show detailed usage with --help no-import-curly-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help no-import-curly-spacing (stdout) 1`] = ` +"--no-import-curly-spacing + + Disable spaces between import curly braces. +" +`; + +exports[`show detailed usage with --help no-import-curly-spacing (write) 1`] = `Array []`; + +exports[`show detailed usage with --help no-indent-chains (stderr) 1`] = `""`; + +exports[`show detailed usage with --help no-indent-chains (stdout) 1`] = ` +"--no-indent-chains + + Disable indents at the start of chained calls. +" +`; + +exports[`show detailed usage with --help no-indent-chains (write) 1`] = `Array []`; + +exports[`show detailed usage with --help no-object-curly-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help no-object-curly-spacing (stdout) 1`] = ` +"--no-object-curly-spacing + + Disable spaces between object curly braces. +" +`; + +exports[`show detailed usage with --help no-object-curly-spacing (write) 1`] = `Array []`; + exports[`show detailed usage with --help no-semi (stderr) 1`] = `""`; exports[`show detailed usage with --help no-semi (stdout) 1`] = ` @@ -369,6 +548,43 @@ exports[`show detailed usage with --help no-semi (stdout) 1`] = ` exports[`show detailed usage with --help no-semi (write) 1`] = `Array []`; +exports[`show detailed usage with --help no-type-curly-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help no-type-curly-spacing (stdout) 1`] = ` +"--no-type-curly-spacing + + Disable spaces between type curly braces. +" +`; + +exports[`show detailed usage with --help no-type-curly-spacing (write) 1`] = `Array []`; + +exports[`show detailed usage with --help object-curly-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help object-curly-spacing (stdout) 1`] = ` +"--object-curly-spacing + + Put spaces between object curly braces (similar to the corresponding eslint option). + +Default: true +" +`; + +exports[`show detailed usage with --help object-curly-spacing (write) 1`] = `Array []`; + +exports[`show detailed usage with --help offset-ternary-expressions (stderr) 1`] = `""`; + +exports[`show detailed usage with --help offset-ternary-expressions (stdout) 1`] = ` +"--offset-ternary-expressions + + Indent and align ternary expression branches more consistently with \\"Standard JS\\" (similar to the corresponding eslint option). + +Default: false +" +`; + +exports[`show detailed usage with --help offset-ternary-expressions (write) 1`] = `Array []`; + exports[`show detailed usage with --help parser (stderr) 1`] = `""`; exports[`show detailed usage with --help parser (stdout) 1`] = ` @@ -554,6 +770,45 @@ Default: false exports[`show detailed usage with --help single-quote (write) 1`] = `Array []`; +exports[`show detailed usage with --help space-before-function-paren (stderr) 1`] = `""`; + +exports[`show detailed usage with --help space-before-function-paren (stdout) 1`] = ` +"--space-before-function-paren + + Put a space before function parenthesis in all declarations (similar to the corresponding eslint option). (Default is to put a space before function parenthesis for untyped anonymous functions only.) + +Default: false +" +`; + +exports[`show detailed usage with --help space-before-function-paren (write) 1`] = `Array []`; + +exports[`show detailed usage with --help space-in-parens (stderr) 1`] = `""`; + +exports[`show detailed usage with --help space-in-parens (stdout) 1`] = ` +"--space-in-parens + + Print spaces in between parens, WordPress style (similar to the corresponding eslint option). Not recommended in combination with the default \`arrowParens: \\"always\\"\` option. Status: experimental, with limited testing. + +Default: false +" +`; + +exports[`show detailed usage with --help space-in-parens (write) 1`] = `Array []`; + +exports[`show detailed usage with --help space-unary-ops (stderr) 1`] = `""`; + +exports[`show detailed usage with --help space-unary-ops (stdout) 1`] = ` +"--space-unary-ops + + Put spaces after unary operator symbols, except in the middle of \`!!\` (similar to the corresponding eslint option). Status: experimental, with limited testing. + +Default: false +" +`; + +exports[`show detailed usage with --help space-unary-ops (write) 1`] = `Array []`; + exports[`show detailed usage with --help stdin-filepath (stderr) 1`] = `""`; exports[`show detailed usage with --help stdin-filepath (stdout) 1`] = ` @@ -589,6 +844,19 @@ Default: 2 exports[`show detailed usage with --help tab-width (write) 1`] = `Array []`; +exports[`show detailed usage with --help template-curly-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help template-curly-spacing (stdout) 1`] = ` +"--template-curly-spacing + + Put spaces between template curly brackets (similar to the corresponding eslint option). Status: experimental, with limited testing. + +Default: false +" +`; + +exports[`show detailed usage with --help template-curly-spacing (write) 1`] = `Array []`; + exports[`show detailed usage with --help trailing-comma (stderr) 1`] = `""`; exports[`show detailed usage with --help trailing-comma (stdout) 1`] = ` @@ -608,6 +876,45 @@ Default: es5 exports[`show detailed usage with --help trailing-comma (write) 1`] = `Array []`; +exports[`show detailed usage with --help type-angle-bracket-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help type-angle-bracket-spacing (stdout) 1`] = ` +"--type-angle-bracket-spacing + + Put spaces between type angle brackets. Status: experimental, with limited testing. + +Default: false +" +`; + +exports[`show detailed usage with --help type-angle-bracket-spacing (write) 1`] = `Array []`; + +exports[`show detailed usage with --help type-bracket-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help type-bracket-spacing (stdout) 1`] = ` +"--type-bracket-spacing + + Print spaces between type brackets. Status: experimental, with limited testing. + +Default: false +" +`; + +exports[`show detailed usage with --help type-bracket-spacing (write) 1`] = `Array []`; + +exports[`show detailed usage with --help type-curly-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help type-curly-spacing (stdout) 1`] = ` +"--type-curly-spacing + + Put spaces between type curly braces. + +Default: true +" +`; + +exports[`show detailed usage with --help type-curly-spacing (write) 1`] = `Array []`; + exports[`show detailed usage with --help use-tabs (stderr) 1`] = `""`; exports[`show detailed usage with --help use-tabs (stdout) 1`] = ` @@ -666,3 +973,16 @@ exports[`show detailed usage with --help write (stdout) 1`] = ` `; exports[`show detailed usage with --help write (write) 1`] = `Array []`; + +exports[`show detailed usage with --help yield-star-spacing (stderr) 1`] = `""`; + +exports[`show detailed usage with --help yield-star-spacing (stdout) 1`] = ` +"--yield-star-spacing + + Put spaces around the star (\`*\`) in \`yield*\` expressions (before and after - similar to the corresponding eslint option). (Default is after only.) + +Default: false +" +`; + +exports[`show detailed usage with --help yield-star-spacing (write) 1`] = `Array []`; diff --git a/tests/integration/__tests__/__snapshots__/plugin-options-string.js.snap b/tests/integration/__tests__/__snapshots__/plugin-options-string.js.snap index 2ed7ae8b69..1a9a5963d5 100644 --- a/tests/integration/__tests__/__snapshots__/plugin-options-string.js.snap +++ b/tests/integration/__tests__/__snapshots__/plugin-options-string.js.snap @@ -18,20 +18,24 @@ exports[`show external options with \`--help\` 1`] = ` - First value + Second value -@@ -20,18 +20,20 @@ - Control how Prettier formats quoted code embedded in the file. - Defaults to auto. +@@ -35,10 +35,12 @@ --end-of-line Which end of line characters to apply. Defaults to lf. + --no-export-curly-spacing + Disable spaces between export curly braces. + --foo-string foo description + Defaults to bar. + --generator-star-spacing Put spaces around the star (\`*\`) in generator functions (before and after - similar to the corresponding eslint option). (Default is after only.) + Defaults to false. --html-whitespace-sensitivity How to handle whitespaces in HTML. Defaults to css. - --jsx-bracket-same-line Put > on the last line instead of at a new line. - Defaults to false. - --jsx-single-quote Use single quotes in JSX. +@@ -55,11 +57,11 @@ + --no-object-curly-spacing + Disable spaces between object curly braces. + --offset-ternary-expressions + Indent and align ternary expression branches more consistently with \\"Standard JS\\" (similar to the corresponding eslint option). Defaults to false. - --parser + --parser diff --git a/tests/integration/__tests__/__snapshots__/plugin-options.js.snap b/tests/integration/__tests__/__snapshots__/plugin-options.js.snap index 276c950e74..087ba4ac42 100644 --- a/tests/integration/__tests__/__snapshots__/plugin-options.js.snap +++ b/tests/integration/__tests__/__snapshots__/plugin-options.js.snap @@ -60,20 +60,24 @@ exports[`show external options with \`--help\` 1`] = ` - First value + Second value -@@ -20,18 +20,20 @@ - Control how Prettier formats quoted code embedded in the file. - Defaults to auto. +@@ -35,10 +35,12 @@ --end-of-line Which end of line characters to apply. Defaults to lf. + --no-export-curly-spacing + Disable spaces between export curly braces. + --foo-option foo description + Defaults to bar. + --generator-star-spacing Put spaces around the star (\`*\`) in generator functions (before and after - similar to the corresponding eslint option). (Default is after only.) + Defaults to false. --html-whitespace-sensitivity How to handle whitespaces in HTML. Defaults to css. - --jsx-bracket-same-line Put > on the last line instead of at a new line. - Defaults to false. - --jsx-single-quote Use single quotes in JSX. +@@ -55,11 +57,11 @@ + --no-object-curly-spacing + Disable spaces between object curly braces. + --offset-ternary-expressions + Indent and align ternary expression branches more consistently with \\"Standard JS\\" (similar to the corresponding eslint option). Defaults to false. - --parser + --parser diff --git a/tests/integration/__tests__/__snapshots__/schema.js.snap b/tests/integration/__tests__/__snapshots__/schema.js.snap index 58a6567248..78ac791420 100644 --- a/tests/integration/__tests__/__snapshots__/schema.js.snap +++ b/tests/integration/__tests__/__snapshots__/schema.js.snap @@ -6,6 +6,16 @@ Object { "definitions": Object { "optionsDefinition": Object { "properties": Object { + "alignObjectProperties": Object { + "default": false, + "description": "Align colons in multiline object literals.", + "type": "boolean", + }, + "arrayBracketSpacing": Object { + "default": false, + "description": "Put spaces between array brackets (similar to the corresponding eslint option). Status: experimental, with limited testing.", + "type": "boolean", + }, "arrowParens": Object { "default": "always", "description": "Include parentheses around a sole arrow function parameter.", @@ -29,6 +39,21 @@ Object { "description": "Print spaces between brackets.", "type": "boolean", }, + "breakBeforeElse": Object { + "default": false, + "description": "Always add a line break before else.", + "type": "boolean", + }, + "breakLongMethodChains": Object { + "default": false, + "description": "Break method chains with more than 3 method calls, like Prettier 1.x.", + "type": "boolean", + }, + "computedPropertySpacing": Object { + "default": false, + "description": "Put spaces between computed property brackets (similar to the corresponding eslint option). Status: experimental, with limited testing.", + "type": "boolean", + }, "cursorOffset": Object { "default": -1, "description": "Print (to stderr) where a cursor at the given position would move to after formatting. @@ -84,11 +109,21 @@ This option cannot be used with --range-start and --range-end.", }, ], }, + "exportCurlySpacing": Object { + "default": true, + "description": "Put spaces between export curly braces.", + "type": "boolean", + }, "filepath": Object { "default": undefined, "description": "Specify the input filepath. This will be used to do parser inference.", "type": "string", }, + "generatorStarSpacing": Object { + "default": false, + "description": "Put spaces around the star (\`*\`) in generator functions (before and after - similar to the corresponding eslint option). (Default is after only.)", + "type": "boolean", + }, "htmlWhitespaceSensitivity": Object { "default": "css", "description": "How to handle whitespaces in HTML.", @@ -113,6 +148,34 @@ This option cannot be used with --range-start and --range-end.", }, ], }, + "importCurlySpacing": Object { + "default": true, + "description": "Put spaces between import curly braces.", + "type": "boolean", + }, + "importFormatting": Object { + "default": "auto", + "description": "Formatting of import statements, may be \`oneline\` to avoid conflict with VSCode \\"Organize Imports\\" feature.", + "oneOf": Array [ + Object { + "description": "automatic formatting, like Prettier", + "enum": Array [ + "auto", + ], + }, + Object { + "description": "keep import statements on one line", + "enum": Array [ + "oneline", + ], + }, + ], + }, + "indentChains": Object { + "default": true, + "description": "Put indents at the start of chained calls.", + "type": "boolean", + }, "insertPragma": Object { "default": false, "description": "Insert @format pragma into file's first docblock comment.", @@ -128,6 +191,16 @@ This option cannot be used with --range-start and --range-end.", "description": "Use single quotes in JSX.", "type": "boolean", }, + "objectCurlySpacing": Object { + "default": true, + "description": "Put spaces between object curly braces (similar to the corresponding eslint option).", + "type": "boolean", + }, + "offsetTernaryExpressions": Object { + "default": false, + "description": "Indent and align ternary expression branches more consistently with \\"Standard JS\\" (similar to the corresponding eslint option).", + "type": "boolean", + }, "parser": Object { "anyOf": Array [ Object { @@ -371,11 +444,31 @@ in order for it to be formatted.", "description": "Use single quotes instead of double quotes.", "type": "boolean", }, + "spaceBeforeFunctionParen": Object { + "default": false, + "description": "Put a space before function parenthesis in all declarations (similar to the corresponding eslint option). (Default is to put a space before function parenthesis for untyped anonymous functions only.)", + "type": "boolean", + }, + "spaceInParens": Object { + "default": false, + "description": "Print spaces in between parens, WordPress style (similar to the corresponding eslint option). Not recommended in combination with the default \`arrowParens: \\"always\\"\` option. Status: experimental, with limited testing.", + "type": "boolean", + }, + "spaceUnaryOps": Object { + "default": false, + "description": "Put spaces after unary operator symbols, except in the middle of \`!!\` (similar to the corresponding eslint option). Status: experimental, with limited testing.", + "type": "boolean", + }, "tabWidth": Object { "default": 2, "description": "Number of spaces per indentation level.", "type": "integer", }, + "templateCurlySpacing": Object { + "default": false, + "description": "Put spaces between template curly brackets (similar to the corresponding eslint option). Status: experimental, with limited testing.", + "type": "boolean", + }, "trailingComma": Object { "default": "es5", "description": "Print trailing commas wherever possible when multi-line.", @@ -400,6 +493,21 @@ in order for it to be formatted.", }, ], }, + "typeAngleBracketSpacing": Object { + "default": false, + "description": "Put spaces between type angle brackets. Status: experimental, with limited testing.", + "type": "boolean", + }, + "typeBracketSpacing": Object { + "default": false, + "description": "Print spaces between type brackets. Status: experimental, with limited testing.", + "type": "boolean", + }, + "typeCurlySpacing": Object { + "default": true, + "description": "Put spaces between type curly braces.", + "type": "boolean", + }, "useTabs": Object { "default": false, "description": "Indent with tabs instead of spaces.", @@ -410,6 +518,11 @@ in order for it to be formatted.", "description": "Indent script and style tags in Vue files.", "type": "boolean", }, + "yieldStarSpacing": Object { + "default": false, + "description": "Put spaces around the star (\`*\`) in \`yield*\` expressions (before and after - similar to the corresponding eslint option). (Default is after only.)", + "type": "boolean", + }, }, "type": "object", }, diff --git a/tests/integration/__tests__/__snapshots__/support-info.js.snap b/tests/integration/__tests__/__snapshots__/support-info.js.snap index aa93eae216..5d05634f01 100644 --- a/tests/integration/__tests__/__snapshots__/support-info.js.snap +++ b/tests/integration/__tests__/__snapshots__/support-info.js.snap @@ -10,8 +10,8 @@ Object { "css", ], "Flow": Array [ - "flow", "babel-flow", + "flow", ], "GraphQL": Array [ "graphql", @@ -71,12 +71,12 @@ Object { "scss", ], "TSX": Array [ - "typescript", "babel-ts", + "typescript", ], "TypeScript": Array [ - "typescript", "babel-ts", + "typescript", ], "Vue": Array [ "vue", @@ -86,6 +86,14 @@ Object { ], }, "options": Object { + "alignObjectProperties": Object { + "default": false, + "type": "boolean", + }, + "arrayBracketSpacing": Object { + "default": false, + "type": "boolean", + }, "arrowParens": Object { "choices": Array [ "always", @@ -98,6 +106,18 @@ Object { "default": true, "type": "boolean", }, + "breakBeforeElse": Object { + "default": false, + "type": "boolean", + }, + "breakLongMethodChains": Object { + "default": false, + "type": "boolean", + }, + "computedPropertySpacing": Object { + "default": false, + "type": "boolean", + }, "cursorOffset": Object { "default": -1, "range": Object { @@ -125,10 +145,18 @@ Object { "default": "lf", "type": "choice", }, + "exportCurlySpacing": Object { + "default": true, + "type": "boolean", + }, "filepath": Object { "default": undefined, "type": "path", }, + "generatorStarSpacing": Object { + "default": false, + "type": "boolean", + }, "htmlWhitespaceSensitivity": Object { "choices": Array [ "css", @@ -138,6 +166,22 @@ Object { "default": "css", "type": "choice", }, + "importCurlySpacing": Object { + "default": true, + "type": "boolean", + }, + "importFormatting": Object { + "choices": Array [ + "auto", + "oneline", + ], + "default": "auto", + "type": "choice", + }, + "indentChains": Object { + "default": true, + "type": "boolean", + }, "insertPragma": Object { "default": false, "type": "boolean", @@ -150,6 +194,14 @@ Object { "default": false, "type": "boolean", }, + "objectCurlySpacing": Object { + "default": true, + "type": "boolean", + }, + "offsetTernaryExpressions": Object { + "default": false, + "type": "boolean", + }, "parser": Object { "choices": Array [ "flow", @@ -243,6 +295,18 @@ Object { "default": false, "type": "boolean", }, + "spaceBeforeFunctionParen": Object { + "default": false, + "type": "boolean", + }, + "spaceInParens": Object { + "default": false, + "type": "boolean", + }, + "spaceUnaryOps": Object { + "default": false, + "type": "boolean", + }, "tabWidth": Object { "default": 2, "range": Object { @@ -252,6 +316,10 @@ Object { }, "type": "int", }, + "templateCurlySpacing": Object { + "default": false, + "type": "boolean", + }, "trailingComma": Object { "choices": Array [ "es5", @@ -261,6 +329,18 @@ Object { "default": "es5", "type": "choice", }, + "typeAngleBracketSpacing": Object { + "default": false, + "type": "boolean", + }, + "typeBracketSpacing": Object { + "default": false, + "type": "boolean", + }, + "typeCurlySpacing": Object { + "default": true, + "type": "boolean", + }, "useTabs": Object { "default": false, "type": "boolean", @@ -269,6 +349,10 @@ Object { "default": false, "type": "boolean", }, + "yieldStarSpacing": Object { + "default": false, + "type": "boolean", + }, }, } `; @@ -359,7 +443,7 @@ exports[`CLI --support-info (stdout) 1`] = ` ], \\"linguistLanguageId\\": 183, \\"name\\": \\"Flow\\", - \\"parsers\\": [\\"flow\\", \\"babel-flow\\"], + \\"parsers\\": [\\"babel-flow\\", \\"flow\\"], \\"since\\": \\"0.0.0\\", \\"tmScope\\": \\"source.js\\", \\"type\\": \\"programming\\", @@ -397,7 +481,7 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"interpreters\\": [\\"deno\\", \\"ts-node\\"], \\"linguistLanguageId\\": 378, \\"name\\": \\"TypeScript\\", - \\"parsers\\": [\\"typescript\\", \\"babel-ts\\"], + \\"parsers\\": [\\"babel-ts\\", \\"typescript\\"], \\"since\\": \\"1.4.0\\", \\"tmScope\\": \\"source.ts\\", \\"type\\": \\"programming\\", @@ -411,7 +495,7 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"group\\": \\"TypeScript\\", \\"linguistLanguageId\\": 94901924, \\"name\\": \\"TSX\\", - \\"parsers\\": [\\"typescript\\", \\"babel-ts\\"], + \\"parsers\\": [\\"babel-ts\\", \\"typescript\\"], \\"since\\": \\"1.4.0\\", \\"tmScope\\": \\"source.tsx\\", \\"type\\": \\"programming\\", @@ -754,6 +838,22 @@ exports[`CLI --support-info (stdout) 1`] = ` } ], \\"options\\": [ + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Align colons in multiline object literals.\\", + \\"name\\": \\"alignObjectProperties\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Put spaces between array brackets (similar to the corresponding eslint option). Status: experimental, with limited testing.\\", + \\"name\\": \\"arrayBracketSpacing\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, { \\"category\\": \\"JavaScript\\", \\"choices\\": [ @@ -783,6 +883,30 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"since\\": \\"0.0.0\\", \\"type\\": \\"boolean\\" }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Always add a line break before else.\\", + \\"name\\": \\"breakBeforeElse\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Break method chains with more than 3 method calls, like Prettier 1.x.\\", + \\"name\\": \\"breakLongMethodChains\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Put spaces between computed property brackets (similar to the corresponding eslint option). Status: experimental, with limited testing.\\", + \\"name\\": \\"computedPropertySpacing\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, { \\"category\\": \\"Special\\", \\"default\\": -1, @@ -839,6 +963,15 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"since\\": \\"1.15.0\\", \\"type\\": \\"choice\\" }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": true, + \\"description\\": \\"Put spaces between export curly braces.\\", + \\"name\\": \\"exportCurlySpacing\\", + \\"oppositeDescription\\": \\"Disable spaces between export curly braces.\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, { \\"category\\": \\"Special\\", \\"description\\": \\"Specify the input filepath. This will be used to do parser inference.\\", @@ -847,6 +980,14 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"since\\": \\"1.4.0\\", \\"type\\": \\"path\\" }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Put spaces around the star (\`*\`) in generator functions (before and after - similar to the corresponding eslint option). (Default is after only.)\\", + \\"name\\": \\"generatorStarSpacing\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, { \\"category\\": \\"HTML\\", \\"choices\\": [ @@ -870,6 +1011,42 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"since\\": \\"1.15.0\\", \\"type\\": \\"choice\\" }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": true, + \\"description\\": \\"Put spaces between import curly braces.\\", + \\"name\\": \\"importCurlySpacing\\", + \\"oppositeDescription\\": \\"Disable spaces between import curly braces.\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, + { + \\"category\\": \\"JavaScript\\", + \\"choices\\": [ + { + \\"description\\": \\"automatic formatting, like Prettier\\", + \\"value\\": \\"auto\\" + }, + { + \\"description\\": \\"keep import statements on one line\\", + \\"value\\": \\"oneline\\" + } + ], + \\"default\\": \\"auto\\", + \\"description\\": \\"Formatting of import statements, may be \`oneline\` to avoid conflict with VSCode \\\\\\"Organize Imports\\\\\\" feature.\\", + \\"name\\": \\"importFormatting\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"choice\\" + }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": true, + \\"description\\": \\"Put indents at the start of chained calls.\\", + \\"name\\": \\"indentChains\\", + \\"oppositeDescription\\": \\"Disable indents at the start of chained calls.\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, { \\"category\\": \\"Special\\", \\"default\\": false, @@ -897,6 +1074,23 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"since\\": \\"1.15.0\\", \\"type\\": \\"boolean\\" }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": true, + \\"description\\": \\"Put spaces between object curly braces (similar to the corresponding eslint option).\\", + \\"name\\": \\"objectCurlySpacing\\", + \\"oppositeDescription\\": \\"Disable spaces between object curly braces.\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Indent and align ternary expression branches more consistently with \\\\\\"Standard JS\\\\\\" (similar to the corresponding eslint option).\\", + \\"name\\": \\"offsetTernaryExpressions\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, { \\"category\\": \\"Global\\", \\"choices\\": [ @@ -1072,6 +1266,30 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"since\\": \\"0.0.0\\", \\"type\\": \\"boolean\\" }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Put a space before function parenthesis in all declarations (similar to the corresponding eslint option). (Default is to put a space before function parenthesis for untyped anonymous functions only.)\\", + \\"name\\": \\"spaceBeforeFunctionParen\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Print spaces in between parens, WordPress style (similar to the corresponding eslint option). Not recommended in combination with the default \`arrowParens: \\\\\\"always\\\\\\"\` option. Status: experimental, with limited testing.\\", + \\"name\\": \\"spaceInParens\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Put spaces after unary operator symbols, except in the middle of \`!!\` (similar to the corresponding eslint option). Status: experimental, with limited testing.\\", + \\"name\\": \\"spaceUnaryOps\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, { \\"category\\": \\"Global\\", \\"default\\": 2, @@ -1081,6 +1299,14 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"range\\": { \\"end\\": null, \\"start\\": 0, \\"step\\": 1 }, \\"type\\": \\"int\\" }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Put spaces between template curly brackets (similar to the corresponding eslint option). Status: experimental, with limited testing.\\", + \\"name\\": \\"templateCurlySpacing\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, { \\"category\\": \\"JavaScript\\", \\"choices\\": [ @@ -1101,6 +1327,31 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"since\\": \\"0.0.0\\", \\"type\\": \\"choice\\" }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Put spaces between type angle brackets. Status: experimental, with limited testing.\\", + \\"name\\": \\"typeAngleBracketSpacing\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Print spaces between type brackets. Status: experimental, with limited testing.\\", + \\"name\\": \\"typeBracketSpacing\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": true, + \\"description\\": \\"Put spaces between type curly braces.\\", + \\"name\\": \\"typeCurlySpacing\\", + \\"oppositeDescription\\": \\"Disable spaces between type curly braces.\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" + }, { \\"category\\": \\"Global\\", \\"default\\": false, @@ -1118,6 +1369,14 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"pluginDefaults\\": {}, \\"since\\": \\"1.19.0\\", \\"type\\": \\"boolean\\" + }, + { + \\"category\\": \\"JavaScript\\", + \\"default\\": false, + \\"description\\": \\"Put spaces around the star (\`*\`) in \`yield*\` expressions (before and after - similar to the corresponding eslint option). (Default is after only.)\\", + \\"name\\": \\"yieldStarSpacing\\", + \\"pluginDefaults\\": {}, + \\"type\\": \\"boolean\\" } ] } diff --git a/tests/integration/__tests__/doc-builders.js b/tests/integration/__tests__/doc-builders.js index 47f25516f5..2010123dce 100644 --- a/tests/integration/__tests__/doc-builders.js +++ b/tests/integration/__tests__/doc-builders.js @@ -53,6 +53,8 @@ describe("doc builders", () => { "group", group(concat(["1"])), { + // [prettierx] for --paren-spacing option support (...) + addedLine: false, type: "group", id: undefined, contents: { type: "concat", parts: ["1"] }, @@ -64,6 +66,8 @@ describe("doc builders", () => { "group (array)", group(["1"]), { + // [prettierx] for --paren-spacing option support (...) + addedLine: false, type: "group", id: undefined, contents: ["1"],