-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CHANGE @W-17053004@ Polished run command output #1669
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import {Display} from '../Display'; | ||
import {RuleSelection} from '@salesforce/code-analyzer-core'; | ||
import {RuleSelection, RunResults, SeverityLevel, Violation} from '@salesforce/code-analyzer-core'; | ||
import {toStyledHeader, indent} from '../utils/StylingUtil'; | ||
import {BundleName, getMessage} from '../messages'; | ||
|
||
|
@@ -75,6 +75,64 @@ export class RulesActionSummaryViewer extends AbstractActionSummaryViewer { | |
this.display.displayLog(indent(getMessage(BundleName.ActionSummaryViewer, 'rules-action.rules-item', [ruleCountForEngine, engineName]))); | ||
} | ||
} | ||
} | ||
|
||
export class RunActionSummaryViewer extends AbstractActionSummaryViewer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is almost identical to the code from |
||
public constructor(display: Display) { | ||
super(display); | ||
} | ||
|
||
public view(results: RunResults, logFile: string, outfiles: string[]): void { | ||
// Start with separator to cleanly break from anything that's already been logged. | ||
this.displayLineSeparator(); | ||
this.displaySummaryHeader(); | ||
this.displayLineSeparator(); | ||
|
||
if (results.getViolationCount() === 0) { | ||
this.display.displayLog(getMessage(BundleName.ActionSummaryViewer, 'run-action.found-no-violations')); | ||
} else { | ||
this.displayResultsSummary(results); | ||
} | ||
this.displayLineSeparator(); | ||
|
||
if (outfiles.length > 0) { | ||
this.displayOutfiles(outfiles); | ||
this.displayLineSeparator(); | ||
} | ||
|
||
this.displayLogFileInfo(logFile); | ||
} | ||
|
||
private displayResultsSummary(results: RunResults): void { | ||
this.display.displayLog(getMessage(BundleName.ActionSummaryViewer, 'run-action.violations-total', [results.getViolationCount(), this.countUniqueFiles(results.getViolations())])); | ||
for (const sev of Object.values(SeverityLevel)) { | ||
// Some of the keys will be numbers, since the enum is numerical. Skip those. | ||
if (typeof sev !== 'string') { | ||
continue; | ||
} | ||
const sevCount = results.getViolationCountOfSeverity(SeverityLevel[sev] as SeverityLevel); | ||
if (sevCount > 0) { | ||
this.display.displayLog(indent(getMessage(BundleName.ActionSummaryViewer, 'run-action.violations-item', [sevCount, sev]))); | ||
} | ||
} | ||
} | ||
|
||
private countUniqueFiles(violations: Violation[]): number { | ||
const fileSet: Set<string> = new Set(); | ||
violations.forEach(v => { | ||
const primaryLocation = v.getCodeLocations()[v.getPrimaryLocationIndex()]; | ||
const file = primaryLocation.getFile(); | ||
if (file) { | ||
fileSet.add(file); | ||
} | ||
}); | ||
return fileSet.size; | ||
} | ||
|
||
private displayOutfiles(outfiles: string[]): void { | ||
this.display.displayLog(getMessage(BundleName.ActionSummaryViewer, 'run-action.outfiles-total')); | ||
for (const outfile of outfiles) { | ||
this.display.displayLog(indent(outfile)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,21 +20,14 @@ abstract class AbstractResultsDisplayer implements ResultsViewer { | |
if (results.getViolationCount() === 0) { | ||
return; | ||
} else { | ||
this.displayLineSeparator(); | ||
this._view(results); | ||
this.display.displayLog('\n'); | ||
this.displayLineSeparator(); | ||
} | ||
} | ||
|
||
protected countUniqueFiles(violations: Violation[]): number { | ||
const fileSet: Set<string> = new Set(); | ||
violations.forEach(v => { | ||
const primaryLocation = v.getCodeLocations()[v.getPrimaryLocationIndex()]; | ||
const file = primaryLocation.getFile(); | ||
if (file) { | ||
fileSet.add(file); | ||
} | ||
}); | ||
return fileSet.size; | ||
protected displayLineSeparator(): void { | ||
this.display.displayLog(''); | ||
} | ||
|
||
protected abstract _view(results: RunResults): void; | ||
|
@@ -44,8 +37,6 @@ export class ResultsDetailDisplayer extends AbstractResultsDisplayer { | |
protected _view(results: RunResults): void { | ||
const violations = sortViolations(results.getViolations()); | ||
|
||
this.display.displayLog(getMessage(BundleName.ResultsViewer, 'summary.detail.found-results', [ | ||
violations.length, this.countUniqueFiles(violations)])); | ||
this.displayDetails(violations); | ||
} | ||
|
||
|
@@ -147,8 +138,7 @@ export class ResultsTableDisplayer extends AbstractResultsDisplayer { | |
} | ||
}); | ||
|
||
this.display.displayLog(getMessage(BundleName.ResultsViewer, 'summary.table.found-results', [ | ||
violations.length, this.countUniqueFiles(violations), parentFolder])); | ||
this.display.displayLog(getMessage(BundleName.ResultsViewer, 'summary.table.results-relative-to', [parentFolder])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to show this if there are no results? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't show if there are no results. The method is only called when there are results to show. |
||
this.display.displayTable(resultRows, TABLE_COLUMNS); | ||
} | ||
} | ||
|
@@ -164,22 +154,22 @@ function sortViolations(violations: Violation[]): Violation[] { | |
// Next, compare file names. | ||
const v1PrimaryLocation = v1.getCodeLocations()[v1.getPrimaryLocationIndex()]; | ||
const v2PrimaryLocation = v2.getCodeLocations()[v2.getPrimaryLocationIndex()]; | ||
const v1File = v1PrimaryLocation.getFile() || ''; | ||
const v2File = v2PrimaryLocation.getFile() || ''; | ||
const v1File = v1PrimaryLocation.getFile() || /* istanbul ignore next */ ''; | ||
const v2File = v2PrimaryLocation.getFile() || /* istanbul ignore next */ ''; | ||
if (v1File !== v2File) { | ||
return v1File.localeCompare(v2File); | ||
} | ||
|
||
// Next, compare start lines. | ||
const v1StartLine = v1PrimaryLocation.getStartLine() || 0; | ||
const v2StartLine = v2PrimaryLocation.getStartLine() || 0; | ||
const v1StartLine = v1PrimaryLocation.getStartLine() || /* istanbul ignore next */ 0; | ||
const v2StartLine = v2PrimaryLocation.getStartLine() || /* istanbul ignore next */ 0; | ||
if (v1StartLine !== v2StartLine) { | ||
return v1StartLine - v2StartLine; | ||
} | ||
|
||
// Next, compare start columns. | ||
const v1StartColumn = v1PrimaryLocation.getStartColumn() || 0; | ||
const v2StartColumn = v2PrimaryLocation.getStartColumn() || 0; | ||
const v1StartColumn = v1PrimaryLocation.getStartColumn() || /* istanbul ignore next */ 0; | ||
const v2StartColumn = v2PrimaryLocation.getStartColumn() || /* istanbul ignore next */ 0; | ||
return v1StartColumn - v2StartColumn; | ||
}); | ||
} | ||
|
@@ -196,6 +186,7 @@ function getPrimaryLocation(violation: Violation): CodeLocation { | |
export function findLongestCommonParentFolderOf(filePaths: string[]): string { | ||
const roots: string[] = filePaths.map(filePath => path.parse(filePath).root); | ||
const commonRoot: string = (new Set(roots)).size === 1 ? roots[0] : ''; | ||
// istanbul ignore next - Hard to test outside of Windows | ||
if (!commonRoot) { | ||
return ''; | ||
} | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
=== Summary | ||
|
||
Found 0 violations. | ||
|
||
Additional log information written to: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
=== Summary | ||
|
||
Found 1 violation(s) across 1 file(s): | ||
1 Low severity violation(s) found. | ||
|
||
Results written to: | ||
{{PATH_TO_FILE1}} | ||
{{PATH_TO_FILE2}} | ||
|
||
Additional log information written to: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
=== Summary | ||
|
||
Found 2 violation(s) across 1 file(s): | ||
1 High severity violation(s) found. | ||
1 Low severity violation(s) found. | ||
|
||
Additional log information written to: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Found 4 violation(s) across 1 file(s): | ||
|
||
=== 1. stub1RuleA | ||
severity: 4 (Low) | ||
engine: stubEngine1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New messages are the still-relevant ones from the now-deleted
run-summary-viewer.md
.