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
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');
}
Comment on lines +48 to +51
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there might be value in having a tag-less rule display with tags: none or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You'll have to ask John and Marcelino if that's what they want. Last I heard, we just wanted to hide the fields if they were empty.


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');
}
Comment on lines +61 to +64
Copy link
Contributor

Choose a reason for hiding this comment

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

Genuine question: Why is it valid for a rule to have no description? That seems like it should be a required property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IDK... if people don't put in a description in their custom PMD that might occur.


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.