Skip to content

Commit

Permalink
Merge pull request #1684 from forcedotcom/sc/W-17321151
Browse files Browse the repository at this point in the history
CHANGE: @W-17321151@: Only show fields in detail view of rules command if they are non-empty
  • Loading branch information
stephen-carter-at-sf authored Nov 27, 2024
2 parents e1e84f2 + 2c59eb7 commit be7eb26
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
27 changes: 22 additions & 5 deletions src/lib/viewers/RuleViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,31 @@ export class RuleDetailDisplayer extends AbstractRuleDisplayer {
const rule = rules[i];
const header = getMessage(BundleName.RuleViewer, 'summary.detail.header', [i + 1, rule.getName()]);
const severity = rule.getSeverityLevel();

const body = {
engine: rule.getEngineName(),
severity: `${severity.valueOf()} (${SeverityLevel[severity]})`,
tags: rule.getTags().join(', '),
resources: rule.getResourceUrls().join(', '),
description: rule.getDescription()
engine: rule.getEngineName(),
};
const keys = ['severity', 'engine', 'tags', 'resources', 'description'];
const keys: string[] = ['severity', 'engine'];

if (rule.getTags().length > 0) {
body['tags'] = rule.getTags().join(', ');
keys.push('tags');
}

if (rule.getResourceUrls().length == 1) {
body['resource'] = rule.getResourceUrls()[0];
keys.push('resource');
} else if (rule.getResourceUrls().length > 1) {
body['resources'] = rule.getResourceUrls();
keys.push('resources');
}

if (rule.getDescription().length > 0) {
body['description'] = rule.getDescription();
keys.push('description');
}

styledRules.push(toStyledHeaderAndBody(header, body, keys));
}
this.display.displayLog(styledRules.join('\n\n'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
severity: 2 (High)
engine: FakeEngine1
tags: Recommended, Security
resources: www.google.com
resource: www.google.com
description: This is the description for a stub rule. Blah blah blah.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
severity: 2 (High)
engine: FakeEngine1
tags: Recommended, Security
resources: www.google.com
resource: www.google.com
description: This is the description for a stub rule. Blah blah blah.

=== 2. StubRule2
severity: 4 (Low)
engine: FakeEngine1
tags: CodeStyle, Performance
resources: www.bing.com, www.salesforce.com
resources:
www.bing.com
www.salesforce.com
description: This is the description for a second stub rule. Blah blah blah.

0 comments on commit be7eb26

Please sign in to comment.