|
1 | 1 | import {Display} from '../Display'; |
2 | | -import {RuleSelection} from '@salesforce/code-analyzer-core'; |
| 2 | +import {RuleSelection, RunResults, SeverityLevel, Violation} from '@salesforce/code-analyzer-core'; |
3 | 3 | import {toStyledHeader, indent} from '../utils/StylingUtil'; |
4 | 4 | import {BundleName, getMessage} from '../messages'; |
5 | 5 |
|
@@ -75,6 +75,64 @@ export class RulesActionSummaryViewer extends AbstractActionSummaryViewer { |
75 | 75 | this.display.displayLog(indent(getMessage(BundleName.ActionSummaryViewer, 'rules-action.rules-item', [ruleCountForEngine, engineName]))); |
76 | 76 | } |
77 | 77 | } |
| 78 | +} |
| 79 | + |
| 80 | +export class RunActionSummaryViewer extends AbstractActionSummaryViewer { |
| 81 | + public constructor(display: Display) { |
| 82 | + super(display); |
| 83 | + } |
| 84 | + |
| 85 | + public view(results: RunResults, logFile: string, outfiles: string[]): void { |
| 86 | + // Start with separator to cleanly break from anything that's already been logged. |
| 87 | + this.displayLineSeparator(); |
| 88 | + this.displaySummaryHeader(); |
| 89 | + this.displayLineSeparator(); |
| 90 | + |
| 91 | + if (results.getViolationCount() === 0) { |
| 92 | + this.display.displayLog(getMessage(BundleName.ActionSummaryViewer, 'run-action.found-no-violations')); |
| 93 | + } else { |
| 94 | + this.displayResultsSummary(results); |
| 95 | + } |
| 96 | + this.displayLineSeparator(); |
78 | 97 |
|
| 98 | + if (outfiles.length > 0) { |
| 99 | + this.displayOutfiles(outfiles); |
| 100 | + this.displayLineSeparator(); |
| 101 | + } |
79 | 102 |
|
| 103 | + this.displayLogFileInfo(logFile); |
| 104 | + } |
| 105 | + |
| 106 | + private displayResultsSummary(results: RunResults): void { |
| 107 | + this.display.displayLog(getMessage(BundleName.ActionSummaryViewer, 'run-action.violations-total', [results.getViolationCount(), this.countUniqueFiles(results.getViolations())])); |
| 108 | + for (const sev of Object.values(SeverityLevel)) { |
| 109 | + // Some of the keys will be numbers, since the enum is numerical. Skip those. |
| 110 | + if (typeof sev !== 'string') { |
| 111 | + continue; |
| 112 | + } |
| 113 | + const sevCount = results.getViolationCountOfSeverity(SeverityLevel[sev] as SeverityLevel); |
| 114 | + if (sevCount > 0) { |
| 115 | + this.display.displayLog(indent(getMessage(BundleName.ActionSummaryViewer, 'run-action.violations-item', [sevCount, sev]))); |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + private countUniqueFiles(violations: Violation[]): number { |
| 121 | + const fileSet: Set<string> = new Set(); |
| 122 | + violations.forEach(v => { |
| 123 | + const primaryLocation = v.getCodeLocations()[v.getPrimaryLocationIndex()]; |
| 124 | + const file = primaryLocation.getFile(); |
| 125 | + if (file) { |
| 126 | + fileSet.add(file); |
| 127 | + } |
| 128 | + }); |
| 129 | + return fileSet.size; |
| 130 | + } |
| 131 | + |
| 132 | + private displayOutfiles(outfiles: string[]): void { |
| 133 | + this.display.displayLog(getMessage(BundleName.ActionSummaryViewer, 'run-action.outfiles-total')); |
| 134 | + for (const outfile of outfiles) { |
| 135 | + this.display.displayLog(indent(outfile)); |
| 136 | + } |
| 137 | + } |
80 | 138 | } |
0 commit comments