Skip to content

Commit

Permalink
fix: minor updates to the markdown formatter (todogroup#180)
Browse files Browse the repository at this point in the history
* fix: fix the markdown formatter sometimes showing an empty list of failed items
  • Loading branch information
prototypicalpro authored Oct 1, 2020
1 parent d030348 commit 45ee596
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
41 changes: 22 additions & 19 deletions formatters/markdown_formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 45ee596

Please sign in to comment.