Use array destructuring for some simple case (#7330)

* Use array destructuring for some simple case

* Revert [0]
This commit is contained in:
fisker Cheung authored and Georgii Dolzhykov committed 2020-01-15 19:24:52 +02:00
1 parent f805388d65
commit 4abd19ae14
7 files changed
+17 -34

No files matched your search

+1 -3
View File
@@ -73,9 +73,7 @@ function _resolveConfig(filePath, opts, sync) {
const loadEditorConfig = resolveEditorConfig.getLoadFunction(loadOpts);
const arr = [load, loadEditorConfig].map(l => l(filePath, opts.config));
const unwrapAndMerge = arr => {
const result = arr[0];
const editorConfigured = arr[1];
const unwrapAndMerge = ([result, editorConfigured]) => {
const merged = Object.assign(
{},
editorConfigured,
+3 -10
View File
@@ -153,10 +153,7 @@ function fits(next, restCommands, width, options, mustBeFlat) {
continue;
}
const x = cmds.pop();
const ind = x[0];
const mode = x[1];
const doc = x[2];
const [ind, mode, doc] = cmds.pop();
if (typeof doc === "string") {
out.push(doc);
@@ -253,10 +250,7 @@ function printDocToString(doc, options) {
let lineSuffix = [];
while (cmds.length !== 0) {
const x = cmds.pop();
const ind = x[0];
const mode = x[1];
const doc = x[2];
const [ind, mode, doc] = cmds.pop();
if (typeof doc === "string") {
out.push(doc);
@@ -383,7 +377,7 @@ function printDocToString(doc, options) {
break;
}
const content = parts[0];
const [content, whitespace] = parts;
const contentFlatCmd = [ind, MODE_FLAT, content];
const contentBreakCmd = [ind, MODE_BREAK, content];
const contentFits = fits(contentFlatCmd, [], rem, options, true);
@@ -397,7 +391,6 @@ function printDocToString(doc, options) {
break;
}
const whitespace = parts[1];
const whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
const whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
+3 -6
View File
@@ -39,15 +39,12 @@ function removeIgnorableFirstLf(ast /*, options */) {
node.children[0].type === "text" &&
node.children[0].value[0] === "\n"
) {
const text = node.children[0];
const [text, ...rest] = node.children;
return node.clone({
children:
text.value.length === 1
? node.children.slice(1)
: [].concat(
text.clone({ value: text.value.slice(1) }),
node.children.slice(1)
)
? rest
: [text.clone({ value: text.value.slice(1) }), ...rest]
});
}
return node;
+1 -2
View File
@@ -3872,8 +3872,7 @@ function shouldGroupFirstArg(args) {
return false;
}
const firstArg = args[0];
const secondArg = args[1];
const [firstArg, secondArg] = args;
return (
(!firstArg.comments || !firstArg.comments.length) &&
(firstArg.type === "FunctionExpression" ||
+7 -5
View File
@@ -23,13 +23,15 @@ function parse(text) {
return { frontMatter: null, content: text };
}
const raw = match[0].replace(/\n$/, "");
const delimiter = match[1];
const value = match[2];
const [raw, delimiter, value] = match;
return {
frontMatter: { type: DELIMITER_MAP[delimiter], value, raw },
content: match[0].replace(/[^\n]/g, " ") + text.slice(match[0].length)
frontMatter: {
type: DELIMITER_MAP[delimiter],
value,
raw: raw.replace(/\n$/, "")
},
content: raw.replace(/[^\n]/g, " ") + text.slice(raw.length)
};
}
+1 -3
View File
@@ -21,9 +21,7 @@ const devVersion = isMasterDevVersion ? masterVersion : null;
const latestVersion = isMasterDevVersion
? rootPackageJson.devDependencies.prettier
: masterVersion;
const latestDocsVersion = versions[0];
const pastDocsVersions = versions.slice(1);
const [latestDocsVersion, ...pastDocsVersions] = versions;
function Versions(props) {
const { config: siteConfig } = props;
+1 -5
View File
@@ -57,11 +57,7 @@ function getMarkdownSyntax(options) {
function formatCLIOptions(cliOptions) {
return cliOptions
.map(option => {
const name = option[0];
const value = option[1];
return value === true ? name : `${name} ${value}`;
})
.map(([name, value]) => (value === true ? name : `${name} ${value}`))
.join("\n");
}