Skip to content

Commit 2bbb76f

Browse files
authored
CHANGE @W-17053004@ Polished run command output (#1669)
1 parent 4981ee1 commit 2bbb76f

23 files changed

+262
-296
lines changed

messages/action-summary-viewer.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,19 @@ Found %d rule(s) from %d engine(s):
2121
# rules-action.rules-item
2222

2323
%d %s rule(s) found.
24+
25+
# run-action.found-no-violations
26+
27+
Found 0 violations.
28+
29+
# run-action.violations-total
30+
31+
Found %d violation(s) across %d file(s):
32+
33+
# run-action.violations-item
34+
35+
%d %s severity violation(s) found.
36+
37+
# run-action.outfiles-total
38+
39+
Results written to:

messages/progress-event-listener.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ done.
1111
Executing rules
1212

1313
# execution-spinner.progress-summary
14-
%d of %d engines still executing after %ds.
14+
%d of %d engines finished after %ds.
1515

1616
# execution-spinner.engine-status
1717
- %s at %d% completion.

messages/results-viewer.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# summary.detail.found-results
2-
3-
Found %d violation(s) across %d file(s):
4-
51
# summary.detail.violation-header
62

73
%d. %s
84

5+
# summary.table.results-relative-to
6+
7+
Violation file paths relative to '%s'.
8+
99
# summary.table.found-results
1010

1111
Found %d violation(s) across %d file(s) relative to '%s':

messages/run-summary-viewer.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/commands/code-analyzer/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default class ConfigCommand extends SfCommand<void> implements Displayabl
6262

6363
protected createDependencies(outputFile?: string): ConfigDependencies {
6464
const uxDisplay: UxDisplay = new UxDisplay(this, this.spinner);
65-
const modelGeneratorFunction = (relevantEngines: Set<string>, userContext: ConfigContext, defaultContext: ConfigContext) => {
65+
const modelGeneratorFunction = /* istanbul ignore next - Model tested separately */ (relevantEngines: Set<string>, userContext: ConfigContext, defaultContext: ConfigContext) => {
6666
return AnnotatedConfigModel.fromSelection(relevantEngines, userContext, defaultContext);
6767
};
6868
const dependencies: ConfigDependencies = {

src/commands/code-analyzer/run.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {CodeAnalyzerConfigFactoryImpl} from '../../lib/factories/CodeAnalyzerCon
66
import {EnginePluginsFactoryImpl} from '../../lib/factories/EnginePluginsFactory';
77
import {CompositeResultsWriter} from '../../lib/writers/ResultsWriter';
88
import {ResultsDetailDisplayer, ResultsTableDisplayer} from '../../lib/viewers/ResultsViewer';
9-
import {RunSummaryDisplayer} from '../../lib/viewers/RunSummaryViewer';
9+
import {RunActionSummaryViewer} from '../../lib/viewers/ActionSummaryViewer';
1010
import {BundleName, getMessage, getMessages} from '../../lib/messages';
1111
import {LogEventDisplayer} from '../../lib/listeners/LogEventListener';
1212
import {EngineRunProgressSpinner, RuleSelectionProgressSpinner} from '../../lib/listeners/ProgressEventListener';
@@ -108,7 +108,7 @@ export default class RunCommand extends SfCommand<void> implements Displayable {
108108
resultsViewer: view === View.TABLE
109109
? new ResultsTableDisplayer(uxDisplay)
110110
: new ResultsDetailDisplayer(uxDisplay),
111-
runSummaryViewer: new RunSummaryDisplayer(uxDisplay)
111+
actionSummaryViewer: new RunActionSummaryViewer(uxDisplay)
112112
};
113113
}
114114
}

src/lib/actions/RunAction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {EnginePluginsFactory} from '../factories/EnginePluginsFactory';
1313
import {createPathStarts} from '../utils/PathStartUtil';
1414
import {createWorkspace} from '../utils/WorkspaceUtil';
1515
import {ResultsViewer} from '../viewers/ResultsViewer';
16-
import {RunSummaryViewer} from '../viewers/RunSummaryViewer';
16+
import {RunActionSummaryViewer} from '../viewers/ActionSummaryViewer';
1717
import {ResultsWriter} from '../writers/ResultsWriter';
1818
import {LogFileWriter} from '../writers/LogWriter';
1919
import {LogEventListener, LogEventLogger} from '../listeners/LogEventListener';
@@ -27,7 +27,7 @@ export type RunDependencies = {
2727
progressListeners: ProgressEventListener[];
2828
writer: ResultsWriter;
2929
resultsViewer: ResultsViewer;
30-
runSummaryViewer: RunSummaryViewer;
30+
actionSummaryViewer: RunActionSummaryViewer;
3131
}
3232

3333
export type RunInput = {
@@ -80,7 +80,7 @@ export class RunAction {
8080
this.dependencies.logEventListeners.forEach(listener => listener.stopListening());
8181
this.dependencies.writer.write(results);
8282
this.dependencies.resultsViewer.view(results);
83-
this.dependencies.runSummaryViewer.view(results, logWriter.getLogDestination(), input['output-file']);
83+
this.dependencies.actionSummaryViewer.view(results, logWriter.getLogDestination(), input['output-file']);
8484

8585
const thresholdValue = input['severity-threshold'];
8686
if (thresholdValue) {

src/lib/listeners/ProgressEventListener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class EngineRunProgressSpinner extends ProgressSpinner implements Progres
207207
engineLines.push(getMessage(BundleName.ProgressEventListener, 'execution-spinner.engine-status', [name, progress]));
208208
}
209209
return [
210-
getMessage(BundleName.ProgressEventListener, 'execution-spinner.progress-summary', [unfinishedEngines, totalEngines, secondsRunning]),
210+
getMessage(BundleName.ProgressEventListener, 'execution-spinner.progress-summary', [totalEngines - unfinishedEngines, totalEngines, secondsRunning]),
211211
...engineLines
212212
].join('\n');
213213
}

src/lib/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ export function getMessage(bundle: BundleName, messageKey: string, tokens?: Toke
5050
}
5151

5252
export function getMessages(bundle: BundleName, messageKey: string, tokens?: Tokens): string[] {
53-
INSTANCE = INSTANCE || new MessageCatalog();
53+
INSTANCE = INSTANCE || /* istanbul ignore next */ new MessageCatalog();
5454
return INSTANCE.getMessages(bundle, messageKey, tokens);
5555
}

src/lib/viewers/ActionSummaryViewer.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Display} from '../Display';
2-
import {RuleSelection} from '@salesforce/code-analyzer-core';
2+
import {RuleSelection, RunResults, SeverityLevel, Violation} from '@salesforce/code-analyzer-core';
33
import {toStyledHeader, indent} from '../utils/StylingUtil';
44
import {BundleName, getMessage} from '../messages';
55

@@ -75,6 +75,64 @@ export class RulesActionSummaryViewer extends AbstractActionSummaryViewer {
7575
this.display.displayLog(indent(getMessage(BundleName.ActionSummaryViewer, 'rules-action.rules-item', [ruleCountForEngine, engineName])));
7676
}
7777
}
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();
7897

98+
if (outfiles.length > 0) {
99+
this.displayOutfiles(outfiles);
100+
this.displayLineSeparator();
101+
}
79102

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+
}
80138
}

0 commit comments

Comments
 (0)