Skip to content

Commit

Permalink
Enable unicorn/prefer-spread
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jan 20, 2021
1 parent c7a3c16 commit c3b0af8
Show file tree
Hide file tree
Showing 36 changed files with 119 additions and 110 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 1 addition & 3 deletions scripts/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}));
2 changes: 1 addition & 1 deletion scripts/release/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/sync-flow-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
}

Expand Down
7 changes: 4 additions & 3 deletions src/cli/expand-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 10 additions & 9 deletions src/common/load-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/config/resolve-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion src/document/doc-printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/language-css/parser-postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/language-css/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const colorAdjusterFunctions = new Set([
]);

function getAncestorCounter(path, typeOrTypes) {
const types = [].concat(typeOrTypes);
const types = [...typeOrTypes];

let counter = -1;
let ancestorNode;
Expand Down Expand Up @@ -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 (
Expand Down
5 changes: 3 additions & 2 deletions src/language-html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 10 additions & 7 deletions src/language-html/print-preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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) => {
Expand All @@ -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,
},
];
}, []),
});
});
Expand Down
20 changes: 10 additions & 10 deletions src/language-html/printer-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand All @@ -536,8 +536,8 @@ function printChildren(path, options, print) {
),
literalline
),
printClosingTagSuffix(child, options)
);
printClosingTagSuffix(child, options),
];
}

return print(childPath);
Expand Down
2 changes: 1 addition & 1 deletion src/language-js/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
[]
);

Expand Down
8 changes: 4 additions & 4 deletions src/language-js/print/angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
7 changes: 4 additions & 3 deletions src/language-js/print/binaryish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -207,8 +208,8 @@ function printBinaryishExpressions(
isInsideParenthesis
),
"left"
)
);
),
];
} else {
parts.push(group(path.call(print, "left")));
}
Expand Down
10 changes: 6 additions & 4 deletions src/language-js/print/call-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })),
];
}
});

Expand Down
6 changes: 2 additions & 4 deletions src/language-js/print/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/language-js/print/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" ||
Expand Down Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/language-js/printer-estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/language-markdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"), () => ({
Expand Down
2 changes: 1 addition & 1 deletion src/language-markdown/parser-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit c3b0af8

Please sign in to comment.