From c3b0af874d901f946317330d282f07efbe0f727d Mon Sep 17 00:00:00 2001 From: fisker Date: Wed, 20 Jan 2021 15:19:13 +0800 Subject: [PATCH] Enable `unicorn/prefer-spread` --- .eslintrc.yml | 1 + package.json | 2 +- scripts/build/build.js | 4 +--- scripts/build/config.js | 2 +- scripts/release/utils.js | 2 +- scripts/sync-flow-tests.js | 6 +++--- src/cli/expand-patterns.js | 7 ++++--- src/cli/usage.js | 2 +- src/common/load-plugins.js | 19 +++++++++--------- src/config/resolve-config.js | 4 ++-- src/document/doc-printer.js | 2 +- src/language-css/parser-postcss.js | 2 +- src/language-css/utils.js | 4 ++-- src/language-html/index.js | 5 +++-- src/language-html/print-preprocess.js | 17 +++++++++------- src/language-html/printer-html.js | 20 +++++++++---------- src/language-js/clean.js | 2 +- src/language-js/print/angular.js | 8 ++++---- src/language-js/print/binaryish.js | 7 ++++--- src/language-js/print/call-arguments.js | 10 ++++++---- src/language-js/print/interface.js | 6 ++---- src/language-js/print/object.js | 4 ++-- src/language-js/printer-estree.js | 2 +- src/language-markdown/index.js | 2 +- src/language-markdown/parser-markdown.js | 2 +- src/language-markdown/printer-markdown.js | 4 ++-- src/language-markdown/utils.js | 7 ++++--- src/language-yaml/printer-yaml.js | 2 +- src/language-yaml/utils.js | 12 ++++++------ src/main/comments.js | 9 ++++----- src/main/options-normalizer.js | 2 +- src/main/support.js | 2 +- tests_config/utils/create-snapshot.js | 24 +++++++++++------------ tests_integration/runPrettier.js | 2 +- website/playground/markdown.js | 8 ++++---- yarn.lock | 15 +++++++++----- 36 files changed, 119 insertions(+), 110 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 8ad9b79f042e..acd4f83886ce 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -73,6 +73,7 @@ rules: unicorn/prefer-includes: error unicorn/prefer-number-properties: error unicorn/prefer-regexp-test: error + unicorn/prefer-spread: error unicorn/prefer-string-slice: error overrides: - files: diff --git a/package.json b/package.json index c9cd34883b55..7cf3d20bd7f5 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "eslint-plugin-jest": "24.1.3", "eslint-plugin-prettier-internal-rules": "link:scripts/tools/eslint-plugin-prettier-internal-rules", "eslint-plugin-react": "7.22.0", - "eslint-plugin-unicorn": "26.0.1", + "eslint-plugin-unicorn": "fisker/eslint-plugin-unicorn#more-concat-fix", "execa": "5.0.0", "jest": "26.6.3", "jest-snapshot-serializer-ansi": "1.0.0", diff --git a/scripts/build/build.js b/scripts/build/build.js index 0c4dccc3418b..fffd46edd76a 100644 --- a/scripts/build/build.js +++ b/scripts/build/build.js @@ -97,9 +97,7 @@ async function createBundle(bundleConfig, cache, options) { const esmFile = path.join("dist/esm", output.replace(".js", ".mjs")); sizeTexts.push(`esm ${await getSizeText(esmFile)}`); } - process.stdout.write( - fitTerminal(output, sizeTexts.join(", ").concat(" ")) - ); + process.stdout.write(fitTerminal(output, [...sizeTexts.join(", "), " "])); } console.log(status.DONE); diff --git a/scripts/build/config.js b/scripts/build/config.js index c154f53d5721..b99ecd2f1516 100644 --- a/scripts/build/config.js +++ b/scripts/build/config.js @@ -168,7 +168,7 @@ function getFileOutput(bundle) { return bundle.output || path.basename(bundle.input); } -module.exports = coreBundles.concat(parsers).map((bundle) => ({ +module.exports = [...coreBundles, ...parsers].map((bundle) => ({ ...bundle, output: getFileOutput(bundle), })); diff --git a/scripts/release/utils.js b/scripts/release/utils.js index 22a8370e79eb..7bfe0d99e94e 100644 --- a/scripts/release/utils.js +++ b/scripts/release/utils.js @@ -37,7 +37,7 @@ function runYarn(script) { if (typeof script === "string") { script = [script]; } - return execa("yarn", ["--silent"].concat(script)).catch((error) => { + return execa("yarn", ["--silent", ...script]).catch((error) => { throw new Error(`\`yarn ${script}\` failed\n${error.stdout}`); }); } diff --git a/scripts/sync-flow-tests.js b/scripts/sync-flow-tests.js index a42309b59cda..9e5e7ce78d76 100644 --- a/scripts/sync-flow-tests.js +++ b/scripts/sync-flow-tests.js @@ -101,9 +101,9 @@ function run(argv) { "but that's not interesting for Prettier's tests.", "This is the skipped stuff:", "", - ] - .concat(skipped, "") - .join("\n") + ...skipped, + "", + ].join("\n") ); } diff --git a/src/cli/expand-patterns.js b/src/cli/expand-patterns.js index 7dba07ddbf8b..424f69aa7738 100644 --- a/src/cli/expand-patterns.js +++ b/src/cli/expand-patterns.js @@ -130,9 +130,10 @@ function* expandPatternsInternal(context) { const filenames = flat( context.languages.map((lang) => lang.filenames || []) ); - supportedFilesGlob = `**/{${extensions - .map((ext) => "*" + (ext[0] === "." ? ext : "." + ext)) - .concat(filenames)}}`; + supportedFilesGlob = `**/{${[ + ...extensions.map((ext) => "*" + (ext[0] === "." ? ext : "." + ext)), + ...filenames, + ]}}`; } return supportedFilesGlob; } diff --git a/src/cli/usage.js b/src/cli/usage.js index 2babc28e36fa..151de5a6a4e1 100644 --- a/src/cli/usage.js +++ b/src/cli/usage.js @@ -148,7 +148,7 @@ function createUsage(context) { return `${category} options:\n\n${indent(categoryOptions, 2)}`; }); - return [constant.usageSummary].concat(optionsUsage, [""]).join("\n\n"); + return [constant.usageSummary, ...optionsUsage, ""].join("\n\n"); } function createDetailedUsage(context, flag) { diff --git a/src/common/load-plugins.js b/src/common/load-plugins.js index 6b1934133e95..cae907486d0e 100644 --- a/src/common/load-plugins.js +++ b/src/common/load-plugins.js @@ -85,19 +85,20 @@ function load(plugins, pluginSearchDirs) { requirePath: resolve(pluginName, { paths: [resolvedPluginSearchDir] }), })); }) - .reduce((a, b) => a.concat(b), []); + .reduce((a, b) => [...a, ...b], []); - const externalPlugins = uniqBy( - externalManualLoadPluginInfos.concat(externalAutoLoadPluginInfos), - "requirePath" - ) - .map((externalPluginInfo) => ({ + const externalPlugins = [ + ...uniqBy( + [...externalManualLoadPluginInfos, ...externalAutoLoadPluginInfos], + "requirePath" + ).map((externalPluginInfo) => ({ name: externalPluginInfo.name, ...eval("require")(externalPluginInfo.requirePath), - })) - .concat(externalPluginInstances); + })), + ...externalPluginInstances, + ]; - return internalPlugins.concat(externalPlugins); + return [...internalPlugins, ...externalPlugins]; } function findPluginsInNodeModules(nodeModulesDir) { diff --git a/src/config/resolve-config.js b/src/config/resolve-config.js index 6bce18398143..c2fbe9255a39 100644 --- a/src/config/resolve-config.js +++ b/src/config/resolve-config.js @@ -155,8 +155,8 @@ function mergeOverrides(configResult, filePath) { // Based on eslint: https://github.com/eslint/eslint/blob/master/lib/config/config-ops.js function pathMatchesGlobs(filePath, patterns, excludedPatterns) { - const patternList = [].concat(patterns); - const excludedPatternList = [].concat(excludedPatterns || []); + const patternList = [...patterns]; + const excludedPatternList = [...(excludedPatterns || [])]; const opts = { matchBase: true, dot: true }; return ( diff --git a/src/document/doc-printer.js b/src/document/doc-printer.js index a425012eb20e..7a570a7e5bfa 100644 --- a/src/document/doc-printer.js +++ b/src/document/doc-printer.js @@ -45,7 +45,7 @@ function generateInd(ind, newPart, options) { const queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) - : ind.queue.concat(newPart); + : [...ind.queue, ...newPart]; let value = ""; let length = 0; diff --git a/src/language-css/parser-postcss.js b/src/language-css/parser-postcss.js index 1dbdfcb6ae12..81c14991df52 100644 --- a/src/language-css/parser-postcss.js +++ b/src/language-css/parser-postcss.js @@ -73,7 +73,7 @@ function parseValueNode(valueNode, options) { for (let i = 0; i < groups.length; i++) { const group = groups[i]; if (group.type === "comma_group") { - groupList = groupList.concat(group.groups); + groupList = [...groupList, ...group.groups]; } else { groupList.push(group); } diff --git a/src/language-css/utils.js b/src/language-css/utils.js index 20e1bff38e9d..06392f6d3168 100644 --- a/src/language-css/utils.js +++ b/src/language-css/utils.js @@ -30,7 +30,7 @@ const colorAdjusterFunctions = new Set([ ]); function getAncestorCounter(path, typeOrTypes) { - const types = [].concat(typeOrTypes); + const types = [...typeOrTypes]; let counter = -1; let ancestorNode; @@ -149,7 +149,7 @@ function insideICSSRuleNode(path) { } function insideAtRuleNode(path, atRuleNameOrAtRuleNames) { - const atRuleNames = [].concat(atRuleNameOrAtRuleNames); + const atRuleNames = [...atRuleNameOrAtRuleNames]; const atRuleAncestorNode = getAncestorNode(path, "css-atrule"); return ( diff --git a/src/language-html/index.js b/src/language-html/index.js index 61882c524a9a..1caf94c651a1 100644 --- a/src/language-html/index.js +++ b/src/language-html/index.js @@ -17,9 +17,10 @@ const languages = [ since: "1.15.0", parsers: ["html"], vscodeLanguageIds: ["html"], - extensions: data.extensions.concat([ + extensions: [ + ...data.extensions, ".mjml", // MJML is considered XML in Linguist but it should be formatted as HTML - ]), + ], })), createLanguage(require("linguist-languages/data/HTML.json"), () => ({ name: "Lightning Web Components", diff --git a/src/language-html/print-preprocess.js b/src/language-html/print-preprocess.js index 5a790780ff55..896d72bcdc0a 100644 --- a/src/language-html/print-preprocess.js +++ b/src/language-html/print-preprocess.js @@ -331,7 +331,7 @@ function extractWhitespaces(ast /*, options*/) { // extract whitespace nodes .reduce((newChildren, child) => { if (child.type !== "text" || isWhitespaceSensitive) { - return newChildren.concat(child); + return [...newChildren, child]; } const localChildren = []; @@ -361,7 +361,7 @@ function extractWhitespaces(ast /*, options*/) { localChildren.push({ type: TYPE_WHITESPACE }); } - return newChildren.concat(localChildren); + return [...newChildren, ...localChildren]; }, []) // set hasLeadingSpaces/hasTrailingSpaces and filter whitespace nodes .reduce((newChildren, child, i, children) => { @@ -375,11 +375,14 @@ function extractWhitespaces(ast /*, options*/) { i !== children.length - 1 && children[i + 1].type === TYPE_WHITESPACE; - return newChildren.concat({ - ...child, - hasLeadingSpaces, - hasTrailingSpaces, - }); + return [ + ...newChildren, + { + ...child, + hasLeadingSpaces, + hasTrailingSpaces, + }, + ]; }, []), }); }); diff --git a/src/language-html/printer-html.js b/src/language-html/printer-html.js index d72cc68b3425..6056daea620c 100644 --- a/src/language-html/printer-html.js +++ b/src/language-html/printer-html.js @@ -228,13 +228,13 @@ function genericPrint(path, options, print) { case "element": case "ieConditionalComment": { if (shouldPreserveContent(node, options)) { - return [].concat( + return [ printOpeningTagPrefix(node, options), group(printOpeningTag(path, options, print)), replaceEndOfLineWith(getNodeContent(node, options), literalline), printClosingTag(node, options), - printClosingTagSuffix(node, options) - ); + printClosingTagSuffix(node, options), + ]; } /** * do not break: @@ -505,23 +505,23 @@ function printChildren(path, options, print) { } } - return [].concat( - prevParts, + return [ + ...prevParts, group([ ...leadingParts, group([printChild(childPath), ...trailingParts], { id: groupIds[childIndex], }), ]), - nextParts - ); + ...nextParts, + ]; }, "children"); function printChild(childPath) { const child = childPath.getValue(); if (hasPrettierIgnore(child)) { - return [].concat( + return [ printOpeningTagPrefix(child, options), replaceEndOfLineWith( options.originalText.slice( @@ -536,8 +536,8 @@ function printChildren(path, options, print) { ), literalline ), - printClosingTagSuffix(child, options) - ); + printClosingTagSuffix(child, options), + ]; } return print(childPath); diff --git a/src/language-js/clean.js b/src/language-js/clean.js index 9ff115bc1992..0a9cfe423959 100644 --- a/src/language-js/clean.js +++ b/src/language-js/clean.js @@ -103,7 +103,7 @@ function clean(ast, newObj, parent) { .map((container) => container.expression); const quasis = templateLiterals.reduce( - (quasis, templateLiteral) => quasis.concat(templateLiteral.quasis), + (quasis, templateLiteral) => [...quasis, ...templateLiteral.quasis], [] ); diff --git a/src/language-js/print/angular.js b/src/language-js/print/angular.js index 166150a0fad8..ff6e3e52ccc3 100644 --- a/src/language-js/print/angular.js +++ b/src/language-js/print/angular.js @@ -12,12 +12,12 @@ function printAngular(path, options, print) { const n = path.getValue(); switch (n.type) { case "NGRoot": - return [].concat( + return [ path.call(print, "node"), - !hasComment(n.node) + ...(!hasComment(n.node) ? [] - : [" //", getComments(n.node)[0].value.trimEnd()] - ); + : [" //", getComments(n.node)[0].value.trimEnd()]), + ]; case "NGPipeExpression": return printBinaryishExpression(path, options, print); case "NGChainedExpression": diff --git a/src/language-js/print/binaryish.js b/src/language-js/print/binaryish.js index c38235cbda29..81c03231c3b2 100644 --- a/src/language-js/print/binaryish.js +++ b/src/language-js/print/binaryish.js @@ -196,7 +196,8 @@ function printBinaryishExpressions( // which is unique in that it is right-associative.) if (shouldFlatten(node.operator, node.left.operator)) { // Flatten them out by recursively calling this function. - parts = parts.concat( + parts = [ + ...parts, path.call( (left) => printBinaryishExpressions( @@ -207,8 +208,8 @@ function printBinaryishExpressions( isInsideParenthesis ), "left" - ) - ); + ), + ]; } else { parts.push(group(path.call(print, "left"))); } diff --git a/src/language-js/print/call-arguments.js b/src/language-js/print/call-arguments.js index 9ee644498429..8121ec3a4007 100644 --- a/src/language-js/print/call-arguments.js +++ b/src/language-js/print/call-arguments.js @@ -159,12 +159,14 @@ function printCallArguments(path, options, print) { hasEmptyLineFollowingFirstArg ? hardline : line, hasEmptyLineFollowingFirstArg ? hardline : "", ], - ].concat(printedArguments.slice(1)); + ...printedArguments.slice(1), + ]; } if (shouldGroupLast && i === args.length - 1) { - printedExpanded = printedArguments - .slice(0, -1) - .concat(argPath.call((p) => print(p, { expandLastArg: true }))); + printedExpanded = [ + ...printedArguments.slice(0, -1), + argPath.call((p) => print(p, { expandLastArg: true })), + ]; } }); diff --git a/src/language-js/print/interface.js b/src/language-js/print/interface.js index c6811babef05..428fbd8210d4 100644 --- a/src/language-js/print/interface.js +++ b/src/language-js/print/interface.js @@ -63,12 +63,10 @@ function printInterface(path, options, print) { const printedExtends = extendsParts; if (shouldIndentOnlyHeritageClauses) { parts.push( - group( - partsGroup.concat(ifBreak(indent(printedExtends), printedExtends)) - ) + group([...partsGroup, ifBreak(indent(printedExtends), printedExtends)]) ); } else { - parts.push(group(indent(partsGroup.concat(printedExtends)))); + parts.push(group(indent([...partsGroup, ...printedExtends]))); } } else { parts.push(...partsGroup, ...extendsParts); diff --git a/src/language-js/print/object.js b/src/language-js/print/object.js index c84307f46f1b..041d2d6d1c0a 100644 --- a/src/language-js/print/object.js +++ b/src/language-js/print/object.js @@ -113,7 +113,7 @@ function printObject(path, options, print) { const props = propsAndLoc .sort((a, b) => a.loc - b.loc) .map((prop) => { - const result = separatorParts.concat(group(prop.printed)); + const result = [...separatorParts, group(prop.printed)]; separatorParts = [separator, line]; if ( (prop.node.type === "TSPropertySignature" || @@ -149,7 +149,7 @@ function printObject(path, options, print) { } else { printed = "..."; } - props.push(separatorParts.concat(printed)); + props.push([...separatorParts, printed]); } const lastElem = getLast(n[propertiesField]); diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 456c069d52d3..d702ce8ea962 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -195,7 +195,7 @@ function genericPrint(path, options, printPath, args) { } if (decorators.length > 0) { - return group(decorators.concat(parts)); + return group([...decorators, ...parts]); } return parts; } diff --git a/src/language-markdown/index.js b/src/language-markdown/index.js index 318a691a4979..994023c4366e 100644 --- a/src/language-markdown/index.js +++ b/src/language-markdown/index.js @@ -9,7 +9,7 @@ const languages = [ since: "1.8.0", parsers: ["markdown"], vscodeLanguageIds: ["markdown"], - filenames: data.filenames.concat(["README"]), + filenames: [...data.filenames, "README"], extensions: data.extensions.filter((extension) => extension !== ".mdx"), })), createLanguage(require("linguist-languages/data/Markdown.json"), () => ({ diff --git a/src/language-markdown/parser-markdown.js b/src/language-markdown/parser-markdown.js index 67008abaf0fe..494b779777f5 100644 --- a/src/language-markdown/parser-markdown.js +++ b/src/language-markdown/parser-markdown.js @@ -64,7 +64,7 @@ function htmlToJsx() { function frontMatter() { const proto = this.Parser.prototype; - proto.blockMethods = ["frontMatter"].concat(proto.blockMethods); + proto.blockMethods = ["frontMatter", ...proto.blockMethods]; proto.blockTokenizers.frontMatter = tokenizer; function tokenizer(eat, value) { diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index 3f008dac9019..0acf5d9b1bf5 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -522,7 +522,7 @@ function getNthSiblingIndex(node, parentNode, condition) { } function getAncestorCounter(path, typeOrTypes) { - const types = [].concat(typeOrTypes); + const types = [...typeOrTypes]; let counter = -1; let ancestorNode; @@ -841,7 +841,7 @@ function shouldRemainTheSameContent(path) { } function printUrl(url, dangerousCharOrChars) { - const dangerousChars = [" "].concat(dangerousCharOrChars || []); + const dangerousChars = [" ", ...(dangerousCharOrChars || [])]; return new RegExp(dangerousChars.map((x) => `\\${x}`).join("|")).test(url) ? `<${url}>` : url; diff --git a/src/language-markdown/utils.js b/src/language-markdown/utils.js index 166fc37f4e10..10b6bbded32b 100644 --- a/src/language-markdown/utils.js +++ b/src/language-markdown/utils.js @@ -28,11 +28,12 @@ const INLINE_NODE_TYPES = [ "inlineMath", ]; -const INLINE_NODE_WRAPPER_TYPES = INLINE_NODE_TYPES.concat([ +const INLINE_NODE_WRAPPER_TYPES = [ + ...INLINE_NODE_TYPES, "tableCell", "paragraph", "heading", -]); +]; const kRegex = new RegExp(kPattern); const punctuationRegex = new RegExp(punctuationPattern); @@ -214,7 +215,7 @@ function mapAst(ast, handler) { const newNode = { ...handler(node, index, parentStack) }; if (newNode.children) { newNode.children = newNode.children.map((child, index) => - preorder(child, index, [newNode].concat(parentStack)) + preorder(child, index, [newNode, ...parentStack]) ); } diff --git a/src/language-yaml/printer-yaml.js b/src/language-yaml/printer-yaml.js index bf6da30b503a..3e2510d67169 100644 --- a/src/language-yaml/printer-yaml.js +++ b/src/language-yaml/printer-yaml.js @@ -241,7 +241,7 @@ function printNode(node, parentNode, path, options, print) { ]; } case "directive": - return ["%", join(" ", [node.name].concat(node.parameters))]; + return ["%", join(" ", [node.name, ...node.parameters])]; case "comment": return ["#", node.value]; case "alias": diff --git a/src/language-yaml/utils.js b/src/language-yaml/utils.js index a413cbf6ad1c..39b1054204f5 100644 --- a/src/language-yaml/utils.js +++ b/src/language-yaml/utils.js @@ -227,8 +227,8 @@ function getFlowScalarLineContents(nodeType, content, options) { getLast(getLast(reduced)).endsWith("\\") ) ) - ? reduced.concat([reduced.pop().concat(lineContentWords)]) - : reduced.concat([lineContentWords]), + ? [...reduced, [...reduced.pop(), ...lineContentWords]] + : [...reduced, lineContentWords], [] ) .map((lineContentWords) => @@ -281,8 +281,8 @@ function getBlockValueLineContents( lineContentWords.length > 0 && !/^\s/.test(lineContentWords[0]) && !/^\s|\s$/.test(getLast(reduced)) - ? reduced.concat([reduced.pop().concat(lineContentWords)]) - : reduced.concat([lineContentWords]), + ? [...reduced, [...reduced.pop(), ...lineContentWords]] + : [...reduced, lineContentWords], [] ) .map((lineContentWords) => @@ -290,8 +290,8 @@ function getBlockValueLineContents( (reduced, word) => // disallow trailing spaces reduced.length > 0 && /\s$/.test(getLast(reduced)) - ? reduced.concat(reduced.pop() + " " + word) - : reduced.concat(word), + ? [...reduced, reduced.pop() + " " + word] + : [...reduced, word], [] ) ) diff --git a/src/main/comments.js b/src/main/comments.js index 15dc38dc0f6c..0eb4654dd029 100644 --- a/src/main/comments.js +++ b/src/main/comments.js @@ -581,11 +581,10 @@ function printComments(path, print, options, needsSemi) { } }, "comments"); - return prependCursorPlaceholder( - path, - options, - leadingParts.concat(trailingParts) - ); + return prependCursorPlaceholder(path, options, [ + ...leadingParts, + ...trailingParts, + ]); } function ensureAllCommentsPrinted(astComments) { diff --git a/src/main/options-normalizer.js b/src/main/options-normalizer.js index d8438aac96ff..a834b61a8ae0 100644 --- a/src/main/options-normalizer.js +++ b/src/main/options-normalizer.js @@ -205,7 +205,7 @@ function optionInfoToSchema(optionInfo, { isCLI, optionInfos }) { return optionInfo.array ? vnopts.ArraySchema.create({ - ...(isCLI ? { preprocess: (v) => [].concat(v) } : {}), + ...(isCLI ? { preprocess: (v) => [...v] } : {}), ...handlers, valueSchema: SchemaConstructor.create(parameters), }) diff --git a/src/main/support.js b/src/main/support.js index 8bff0cf03d69..a6aa0d83f083 100644 --- a/src/main/support.js +++ b/src/main/support.js @@ -30,7 +30,7 @@ function getSupportInfo({ const version = currentVersion.split("-", 1)[0]; const languages = plugins - .reduce((all, plugin) => all.concat(plugin.languages || []), []) + .reduce((all, plugin) => [...all, ...(plugin.languages || [])], []) .filter(filterSince); const options = arrayify( diff --git a/tests_config/utils/create-snapshot.js b/tests_config/utils/create-snapshot.js index 0db847e48209..7fdedc5539c7 100644 --- a/tests_config/utils/create-snapshot.js +++ b/tests_config/utils/create-snapshot.js @@ -28,20 +28,18 @@ function createSnapshot(input, output, options, { codeOffset }) { ? (codeOffset ? " ".repeat(codeOffset - 1) + "|" : "") + " ".repeat(options.printWidth) + "| printWidth" - : []; + : ""; return raw( - [] - .concat( - printSeparator(separatorWidth, "options"), - printOptions(options), - printWidthIndicator, - printSeparator(separatorWidth, "input"), - input, - printSeparator(separatorWidth, "output"), - output, - printSeparator(separatorWidth) - ) - .join("\n") + [ + printSeparator(separatorWidth, "options"), + printOptions(options), + printWidthIndicator, + printSeparator(separatorWidth, "input"), + input, + printSeparator(separatorWidth, "output"), + output, + printSeparator(separatorWidth), + ].join("\n") ); } diff --git a/tests_integration/runPrettier.js b/tests_integration/runPrettier.js index ce568c462183..a5bf26ac7744 100644 --- a/tests_integration/runPrettier.js +++ b/tests_integration/runPrettier.js @@ -66,7 +66,7 @@ function runPrettier(dir, args, options) { process.chdir(normalizeDir(dir)); process.stdin.isTTY = !!options.isTTY; process.stdout.isTTY = !!options.stdoutIsTTY; - process.argv = ["path/to/node", "path/to/prettier/bin"].concat(args); + process.argv = ["path/to/node", "path/to/prettier/bin", ...args]; jest.resetModules(); diff --git a/website/playground/markdown.js b/website/playground/markdown.js index e500655553bb..9a1214b00f4e 100644 --- a/website/playground/markdown.js +++ b/website/playground/markdown.js @@ -22,11 +22,11 @@ function formatMarkdown( "", "**Output:**", codeBlock(output, syntax), + ...(isIdempotent + ? [] + : ["", "**Second Output:**", codeBlock(output2, syntax)]), + ...(full ? ["", "**Expected behavior:**", ""] : []), ] - .concat( - isIdempotent ? [] : ["", "**Second Output:**", codeBlock(output2, syntax)] - ) - .concat(full ? ["", "**Expected behavior:**", ""] : []) .filter((part) => part != null) .join("\n"); } diff --git a/yarn.lock b/yarn.lock index 523dfe08d271..7698cc4582f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3085,6 +3085,7 @@ eslint-plugin-jest@24.1.3: "eslint-plugin-prettier-internal-rules@link:scripts/tools/eslint-plugin-prettier-internal-rules": version "0.0.0" + uid "" eslint-plugin-react@7.22.0: version "7.22.0" @@ -3103,10 +3104,9 @@ eslint-plugin-react@7.22.0: resolve "^1.18.1" string.prototype.matchall "^4.0.2" -eslint-plugin-unicorn@26.0.1: +eslint-plugin-unicorn@fisker/eslint-plugin-unicorn#more-concat-fix: version "26.0.1" - resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-26.0.1.tgz#65f476bb7624beb417066259dc14c7ebb21eb6fc" - integrity sha512-SWgF9sIVY74zqkkSN2dclSCqRfocWSUGD0haC0NX2oRfmdp9p8dQvJYkYSQePaCyssPUE/pqpsIEEZNTh8crUA== + resolved "https://codeload.github.com/fisker/eslint-plugin-unicorn/tar.gz/93b42e8aa101079946179aa43306fcce49cc24c6" dependencies: ci-info "^2.0.0" clean-regexp "^1.0.0" @@ -3117,7 +3117,7 @@ eslint-plugin-unicorn@26.0.1: lodash "^4.17.20" pluralize "^8.0.0" read-pkg-up "^7.0.1" - regexp-tree "^0.1.21" + regexp-tree "^0.1.22" reserved-words "^0.1.2" safe-regex "^2.1.1" semver "^7.3.4" @@ -6055,7 +6055,12 @@ regex-not@^1.0.0, regex-not@^1.0.2: extend-shallow "^3.0.2" safe-regex "^1.1.0" -regexp-tree@^0.1.21, regexp-tree@~0.1.1: +regexp-tree@^0.1.22: + version "0.1.22" + resolved "https://registry.npm.taobao.org/regexp-tree/download/regexp-tree-0.1.22.tgz?cache=0&sync_timestamp=1610970258072&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fregexp-tree%2Fdownload%2Fregexp-tree-0.1.22.tgz#495bb485bc25422f1967b85d71fac0e9d731aa1b" + integrity sha1-SVu0hbwlQi8ZZ7hdcfrA6dcxqhs= + +regexp-tree@~0.1.1: version "0.1.21" resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.21.tgz#55e2246b7f7d36f1b461490942fa780299c400d7" integrity sha512-kUUXjX4AnqnR8KRTCrayAo9PzYMRKmVoGgaz2tBuz0MF3g1ZbGebmtW0yFHfFK9CmBjQKeYIgoL22pFLBJY7sw==