Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,692 changes: 1,598 additions & 2,094 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"bugs": "https://github.com/forcedotcom/code-analyzer/issues",
"type": "module",
"dependencies": {
"@oclif/core": "3.27.0",
"@oclif/core": "^4.6.0",
"@oclif/table": "^0.4.14",
"@salesforce/code-analyzer-core": "0.39.0",
"@salesforce/code-analyzer-engine-api": "0.31.0",
"@salesforce/code-analyzer-eslint-engine": "0.36.0",
Expand All @@ -15,8 +16,8 @@
"@salesforce/code-analyzer-regex-engine": "0.29.0",
"@salesforce/code-analyzer-retirejs-engine": "0.28.0",
"@salesforce/code-analyzer-sfge-engine": "0.14.0",
"@salesforce/core": "6.7.6",
"@salesforce/sf-plugins-core": "5.0.13",
"@salesforce/core": "^8.23.3",
"@salesforce/sf-plugins-core": "^12.2.4",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

"@salesforce/ts-types": "^2.0.12",
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.0.0",
Expand Down
31 changes: 24 additions & 7 deletions src/lib/Display.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Ux, Spinner} from '@salesforce/sf-plugins-core';
import {TableOptions} from '@oclif/table';
import {Spinner} from '@salesforce/sf-plugins-core';

/**
* Interface for objects that display output information to users. E.g., a class that prints to the CLI would implement
Expand Down Expand Up @@ -31,7 +32,7 @@ export interface Display {
/**
* Output table to stdout only if the "--json" flag is not present.
*/
displayTable<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>): void;
displayTable<R extends Record<string, unknown>>(options: TableOptions<R>): void;

/**
* Prompt the user to confirm that the described action should be carried out, and block until they respond (or a timeout
Expand Down Expand Up @@ -73,12 +74,28 @@ export class UxDisplay implements Display {
this.displayable.log(message);
}

public displayTable<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>): void {
this.displayable.table(data, columns);
public displayTable<R extends Record<string, unknown>>(options: TableOptions<R>): void {
// Currently oclif's table options do not allow us to set the width of the table larger than the user's current
// terminal width. This means if the user's terminal width is small then we will table cells with "truncate" by
// default or "wrap" depending on the passed in 'overflow' value in the table options. To work around this
// limitation, we temporarily set the OCLIF_TABLE_COLUMN_OVERRIDE environment variable so that the user's
// terminal width is ignored so that no truncating or wrapping occurs in order to maintain our original table
// view behavior (prior to when we upgraded oclif).
const oldTableColumnOverrideValue = process.env.OCLIF_TABLE_COLUMN_OVERRIDE;

// If we use too large a number (like 99999), then we can get out of memory issues. Using 3000 seems to the best
// number that fits everything without causing memory issues. And if there is more than 3000 characters then at
// that point we are fine wrapping or truncating
process.env.OCLIF_TABLE_COLUMN_OVERRIDE = '3000';
try {
this.displayable.table(options);
} finally {
process.env.OCLIF_TABLE_COLUMN_OVERRIDE = oldTableColumnOverrideValue;
}
}

public confirm(message: string): Promise<boolean> {
return this.displayable.confirm(message);
return this.displayable.confirm({message});
}

public spinnerStart(msg: string, status?: string): void {
Expand Down Expand Up @@ -111,8 +128,8 @@ export interface Displayable {
log(message?: string): void;

// Prompt the user to confirm that the described action should be performed. [Implemented by SfCommand]
confirm(message: string): Promise<boolean>;
confirm(promptInputs: {message: string}): Promise<boolean>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting new syntax - I wonder what else has become available with this upgrade 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there are more options - but I didn't want to pull in all the types if we didn't have to. So I just did minimal update needed for now.


// Output table to stdout only when "--json" flag is not present. [Implemented by SfCommand]
table<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>, options?: Ux.Table.Options): void;
table<R extends Record<string, unknown>>(options: TableOptions<R>): void;
}
2 changes: 1 addition & 1 deletion src/lib/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Messages} from '@salesforce/core';
import {Tokens} from '@salesforce/core/lib/messages.js';
import {Tokens} from '@salesforce/core/messages';

// Initialize Messages with the current plugin directory
Messages.importMessagesDirectory(import.meta.dirname);
Expand Down
36 changes: 22 additions & 14 deletions src/lib/viewers/ResultsViewer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as path from 'node:path';
import {Ux} from '@salesforce/sf-plugins-core';
import {CodeLocation, RunResults, SeverityLevel, Violation} from '@salesforce/code-analyzer-core';
import {Display} from '../Display.js';
import {toStyledHeaderAndBody} from '../utils/StylingUtil.js';
Expand Down Expand Up @@ -119,23 +118,28 @@ type ResultRow = {
message: string;
}

const TABLE_COLUMNS: Ux.Table.Columns<ResultRow> = {
num: {
header: getMessage(BundleName.ResultsViewer, 'summary.table.num-column'),
const TABLE_COLUMNS = [
{
key: 'num' as keyof ResultRow,
name: getMessage(BundleName.ResultsViewer, 'summary.table.num-column'),
},
severity: {
header: getMessage(BundleName.ResultsViewer, 'summary.table.severity-column')
{
key: 'severity' as keyof ResultRow,
name: getMessage(BundleName.ResultsViewer, 'summary.table.severity-column')
},
rule: {
header: getMessage(BundleName.ResultsViewer, 'summary.table.rule-column')
{
key: 'rule' as keyof ResultRow,
name: getMessage(BundleName.ResultsViewer, 'summary.table.rule-column')
},
location: {
header: getMessage(BundleName.ResultsViewer, 'summary.table.location-column')
{
key: 'location' as keyof ResultRow,
name: getMessage(BundleName.ResultsViewer, 'summary.table.location-column')
},
message: {
header: getMessage(BundleName.ResultsViewer, 'summary.table.message-column')
{
key: 'message' as keyof ResultRow,
name: getMessage(BundleName.ResultsViewer, 'summary.table.message-column')
}
};
];

export class ResultsTableDisplayer extends AbstractResultsDisplayer {
protected _view(results: RunResults) {
Expand All @@ -158,7 +162,11 @@ export class ResultsTableDisplayer extends AbstractResultsDisplayer {
});

this.display.displayLog(getMessage(BundleName.ResultsViewer, 'summary.shared.results-relative-to', [parentFolder]));
this.display.displayTable(resultRows, TABLE_COLUMNS);
this.display.displayTable({
data: resultRows,
columns: TABLE_COLUMNS,
overflow: 'wrap' // We do not want to use truncate because it is lossy
});
}
}

Expand Down
36 changes: 22 additions & 14 deletions src/lib/viewers/RuleViewer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Ux} from '@salesforce/sf-plugins-core';
import {Rule, SeverityLevel} from '@salesforce/code-analyzer-core';
import {Display} from '../Display.js';
import {toStyledHeaderAndBody} from '../utils/StylingUtil.js';
Expand Down Expand Up @@ -76,23 +75,28 @@ type RuleRow = {
tag: string;
};

const TABLE_COLUMNS: Ux.Table.Columns<RuleRow> = {
num: {
header: getMessage(BundleName.RuleViewer, 'summary.table.num-column')
const TABLE_COLUMNS = [
{
key: 'num' as keyof RuleRow,
name: getMessage(BundleName.RuleViewer, 'summary.table.num-column')
},
name: {
header: getMessage(BundleName.RuleViewer, 'summary.table.name-column')
{
key: 'name' as keyof RuleRow,
name: getMessage(BundleName.RuleViewer, 'summary.table.name-column')
},
engine: {
header: getMessage(BundleName.RuleViewer, 'summary.table.engine-column')
{
key: 'engine' as keyof RuleRow,
name: getMessage(BundleName.RuleViewer, 'summary.table.engine-column')
},
severity: {
header: getMessage(BundleName.RuleViewer, 'summary.table.severity-column')
{
key: 'severity' as keyof RuleRow,
name: getMessage(BundleName.RuleViewer, 'summary.table.severity-column')
},
tag: {
header: getMessage(BundleName.RuleViewer, 'summary.table.tag-column')
{
key: 'tag' as keyof RuleRow,
name: getMessage(BundleName.RuleViewer, 'summary.table.tag-column')
}
};
];

export class RuleTableDisplayer extends AbstractRuleDisplayer {
protected _view(rules: Rule[]): void {
Expand All @@ -106,7 +110,11 @@ export class RuleTableDisplayer extends AbstractRuleDisplayer {
tag: rule.getTags().join(', ')
};
});
this.display.displayTable(ruleJsons, TABLE_COLUMNS);
this.display.displayTable({
data: ruleJsons,
columns: TABLE_COLUMNS,
overflow: 'wrap' // We do not want to use truncate because it is lossy
});
}
}

Expand Down
9 changes: 5 additions & 4 deletions test/stubs/SpyDisplay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Ux} from '@salesforce/sf-plugins-core';
import { TableOptions } from '@oclif/table';
import {Display} from '../../src/lib/Display.js';

/**
Expand Down Expand Up @@ -53,13 +53,14 @@ export class SpyDisplay implements Display {
/**
* Track that the provided table data was displayed.
*/
public displayTable<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>): void {
const columnNames: string[] = Object.values(columns).map(column => column.header || '');
public displayTable<R extends Record<string, unknown>>(options: TableOptions<R>): void {
const columnNames: string[] = options.columns!.map(
column => typeof(column) === 'string' ? column : (column as object)['name'] ?? (column as object)['key']);
this.displayEvents.push({
type: DisplayEventType.TABLE,
data: JSON.stringify({
columns: columnNames,
rows: data
rows: options.data
})
});
}
Expand Down
16 changes: 16 additions & 0 deletions test/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
export class ConsoleOuputInterceptor {
private origStdOutWrite: typeof process.stdout.write;
private origStdErrWrite: typeof process.stderr.write;
private origConsoleLog: typeof console.log;
private origConsoleError: typeof console.error;
public stdOut: string = '';
public stdErr: string = '';
public out: string = '';

constructor() {
this.origStdOutWrite = process.stdout.write;
this.origStdErrWrite = process.stderr.write;
this.origConsoleLog = console.log;
this.origConsoleError = console.error;
}

start() {
Expand All @@ -21,10 +25,22 @@ export class ConsoleOuputInterceptor {
this.out += chunk;
return true;
}
console.log = (...args) => {
const output = args.join(' ') + '\n';
this.stdOut += output;
this.out += output;
};
console.error = (...args) => {
const output = args.join(' ') + '\n';
this.stdErr += output;
this.out += output;
}
}

stop() {
process.stdout.write = this.origStdOutWrite;
process.stderr.write = this.origStdErrWrite;
console.log = this.origConsoleLog;
console.error = this.origConsoleError;
}
}