From 45ee596ef69947319278e2fcbfedd18c2d284aed Mon Sep 17 00:00:00 2001 From: Noah Koontz Date: Thu, 1 Oct 2020 10:01:16 -0700 Subject: [PATCH] fix: minor updates to the markdown formatter (#180) * fix: fix the markdown formatter sometimes showing an empty list of failed items --- formatters/markdown_formatter.js | 41 +++++++++++++++++--------------- index.js | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/formatters/markdown_formatter.js b/formatters/markdown_formatter.js index 6df456e6..f4b00361 100644 --- a/formatters/markdown_formatter.js +++ b/formatters/markdown_formatter.js @@ -111,26 +111,29 @@ class MarkdownFormatter { const start = '\n\n' + opWrap(null, result.ruleInfo.policyInfo, '. ') + opWrap('For more information please visit ', result.ruleInfo.policyUrl, '. ') + - opWrap(null, result.lintResult.message, '. ') + - 'Below is a list of files or patterns that failed:\n\n' + opWrap(null, result.lintResult.message, '. ') formatBase.push(start) - // create bulleted list - // format the result based on these pieces of information - const list = result.lintResult.targets - // filter only failed targets - .filter(t => t.passed === false) - // match each target to it's fix result, if one exists - .map(t => - result.fixResult && t.path ? [t, result.fixResult.targets.find(f => f.path === t.path) || null] : [t, null]) - .map(([lintTarget, fixTarget]) => { - const base = `- \`${lintTarget.path || lintTarget.pattern}\`${opWrap(': ', lintTarget.message, '.')}` - // no fix format - if (!fixTarget || !fixTarget.passed) { return base } - // with fix format - return base + `\n - ${dryRun ? SUGGESTED_FIX : APPLIED_FIX} ${fixTarget.message || result.fixResult.message}` - }) - .join('\n') - formatBase.push(list) + // create bulleted list, filter only failed targets + const failedList = result.lintResult.targets.filter(t => t.passed === false) + if (failedList.length === 0) { + formatBase.push('All files passed this test.') + } else { + formatBase.push('Below is a list of files or patterns that failed:\n\n') + // format the result based on these pieces of information + const list = failedList + // match each target to it's fix result, if one exists + .map(t => + result.fixResult && t.path ? [t, result.fixResult.targets.find(f => f.path === t.path) || null] : [t, null]) + .map(([lintTarget, fixTarget]) => { + const base = `- \`${lintTarget.path || lintTarget.pattern}\`${opWrap(': ', lintTarget.message, '.')}` + // no fix format + if (!fixTarget || !fixTarget.passed) { return base } + // with fix format + return base + `\n - ${dryRun ? SUGGESTED_FIX : APPLIED_FIX} ${fixTarget.message || result.fixResult.message}` + }) + .join('\n') + formatBase.push(list) + } } // suggested fix for overall rule/fix combo if (result.fixResult && result.fixResult.passed) { diff --git a/index.js b/index.js index c10a147e..b8aa9c0f 100644 --- a/index.js +++ b/index.js @@ -152,7 +152,7 @@ async function lint (targetDir, filterPaths = [], ruleset = null, dryRun = false errMsg: e && e.toString(), results: [], targets: {}, - formatOptions: ruleset.formatOptions + formatOptions: ruleset && ruleset.formatOptions } } }