From 33806220121449e9a06b0ed6d3d3059d25202879 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 29 Aug 2021 17:35:10 +0200 Subject: [PATCH] Rename variable --- src/report/finalize.js | 8 ++++---- src/report/insert.js | 22 +++++++++------------- src/report/main.js | 2 +- src/report/output.js | 12 ++++++------ 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/report/finalize.js b/src/report/finalize.js index f4f5847bb..ccebae6ae 100644 --- a/src/report/finalize.js +++ b/src/report/finalize.js @@ -25,10 +25,10 @@ const hasContent = function ({ content }) { // Also add footer and padding. const joinContents = function (contents) { const [{ output, format, colors, footerString }] = contents - const contentsString = contents.map(getContentProperty).join('\n') - const contentsStringA = `${contentsString}${footerString}` - const contentsStringB = handleContent(contentsStringA, format, colors) - return { contentsString: contentsStringB, output } + const content = contents.map(getContentProperty).join('\n') + const contentA = `${content}${footerString}` + const contentB = handleContent(contentA, format, colors) + return { content: contentB, output } } const getContentProperty = function ({ content }) { diff --git a/src/report/insert.js b/src/report/insert.js index bbb33b470..fef8119c8 100644 --- a/src/report/insert.js +++ b/src/report/insert.js @@ -38,30 +38,26 @@ const getFileContent = async function (output) { } } -export const insertContents = async function ( - output, - contentsString, - fileContent, -) { +export const insertContents = async function (output, content, fileContent) { const newline = detectNewline.graceful(fileContent) const lines = fileContent.split(newline) - const contentsStringA = replaceNewline(contentsString, newline) - const linesA = insertToLines(lines, contentsStringA, output) + const contentA = replaceNewline(content, newline) + const linesA = insertToLines(lines, contentA, output) - const contentsStringB = linesA.join(newline) - await writeFileContent(output, contentsStringB) + const contentB = linesA.join(newline) + await writeFileContent(output, contentB) } -const replaceNewline = function (contentsString, newline) { - return stripFinalNewline(contentsString.split(UNIX_NEWLINE).join(newline)) +const replaceNewline = function (content, newline) { + return stripFinalNewline(content.split(UNIX_NEWLINE).join(newline)) } const UNIX_NEWLINE = '\n' // We require both delimiters so that user is aware that both should be moved // when moving lines around -const insertToLines = function (lines, contentsString, output) { +const insertToLines = function (lines, content, output) { const startLine = getLineIndex(lines, START_LINE_TOKEN) const endLine = getLineIndex(lines, END_LINE_TOKEN) @@ -79,7 +75,7 @@ const insertToLines = function (lines, contentsString, output) { const start = lines.slice(0, startLine + 1) const end = lines.slice(endLine) - return [...start, contentsString, ...end] + return [...start, content, ...end] } const getLineIndex = function (lines, token) { diff --git a/src/report/main.js b/src/report/main.js index c37813ad8..6bc0197c4 100644 --- a/src/report/main.js +++ b/src/report/main.js @@ -55,7 +55,7 @@ export const reportStart = async function (result, previous, config) { export const reportPreview = async function (result, historyInfo, config) { const contents = await computeContents(result, historyInfo, config) const contentsA = finalizeContents(contents) - return contentsA.length === 0 ? '' : contentsA[0].contentsString + return contentsA.length === 0 ? '' : contentsA[0].content } // Compute the report contents. diff --git a/src/report/output.js b/src/report/output.js index 81c7d7c03..b6588fa6d 100644 --- a/src/report/output.js +++ b/src/report/output.js @@ -17,9 +17,9 @@ export const outputContents = async function (contents) { await Promise.all(contents.map(outputContent)) } -const outputContent = async function ({ contentsString, output }) { +const outputContent = async function ({ content, output }) { if (output === 'stdout') { - await printToStdout(contentsString) + await printToStdout(content) return } @@ -32,19 +32,19 @@ const outputContent = async function ({ contentsString, output }) { const fileContent = await detectInsert(output) if (fileContent !== undefined) { - await insertContents(output, contentsString, fileContent) + await insertContents(output, content, fileContent) return } - await overwriteContents(output, contentsString) + await overwriteContents(output, content) } -const overwriteContents = async function (output, contentsString) { +const overwriteContents = async function (output, content) { const outputDir = dirname(output) await fs.mkdir(outputDir, { recursive: true }) try { - await writeFileAtomic(output, contentsString) + await writeFileAtomic(output, content) } catch (error) { throw new UserError( `Could not write to "output" "${output}"\n${error.message}`,