Skip to content

Commit f0ee5b7

Browse files
authored
Gracefully handle empty rule description (#133)
Fixes #127
1 parent 76f6e25 commit f0ee5b7

File tree

3 files changed

+143
-1
lines changed

3 files changed

+143
-1
lines changed

lib/annotations.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ function createAnnotation(location, title) {
5252
}
5353

5454
function createDescription(rule) {
55-
const lines = rule.fullDescription.text.split(/\n|\r\n/);
55+
const lines = rule.fullDescription.text !== undefined
56+
? rule.fullDescription.text.split(/\n|\r\n/)
57+
: [''];
58+
5659
// remove empty first line
5760
if (lines.length > 1 && lines[0] === '') {
5861
lines.splice(0, 1);

tests/annotations.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,37 @@ https://pmd.github.io/pmd-6.40.0/pmd_rules_apex_bestpractices.html#unusedlocalva
5959
expect(core.notice).toHaveBeenNthCalledWith(1, 'Full description for Low Prio Rule\n\n4 - low prio rule (Priority: 5, Ruleset: sample ruleset)\nhttps://pmd.github.io/latest/ruleLowPrio', { title: 'Low Prio Rule', file: '/folder/file5.txt', startLine: 8 });
6060
expect(core.notice).toHaveBeenNthCalledWith(2, 'Full description for Low Prio Rule\n\n4 - low prio rule (Priority: 5, Ruleset: sample ruleset)\nhttps://pmd.github.io/latest/ruleLowPrio', { title: 'Low Prio Rule', file: '/folder/file6.txt', startLine: 9 });
6161
});
62+
63+
it('can deal with empty full description (issue #127)', () => {
64+
const report = sarif.loadReport(path.join(__dirname, 'data', 'pmd-report-empty-full-description.sarif'));
65+
annotations.processSarifReport(report);
66+
67+
expect(core.error).toHaveBeenCalledTimes(0);
68+
expect(core.warning).toHaveBeenCalledTimes(1);
69+
expect(core.warning).toHaveBeenNthCalledWith(1, `The first parameter of System.debug, when using the signature with two parameters, is a LoggingLevel enum.
70+
71+
Having the Logging Level specified provides a cleaner log, and improves readability of it.
72+
73+
DebugsShouldUseLoggingLevel (Priority: 3, Ruleset: Best Practices)
74+
https://pmd.github.io/pmd-6.49.0/pmd_rules_apex_bestpractices.html#debugsshoulduselogginglevel`,
75+
{
76+
title: 'Calls to System.debug should specify a logging level.',
77+
file: '/home/andreas/PMD/source/pmd-it/pmd-github-action-issue-127/src/Test.cls',
78+
startLine: 3,
79+
endLine: 3
80+
}
81+
);
82+
expect(core.notice).toHaveBeenCalledTimes(1);
83+
expect(core.notice).toHaveBeenNthCalledWith(1, `
84+
85+
AvoidProductionDebugLogs (Priority: 5, Ruleset: My Default)
86+
`,
87+
{
88+
title: 'Avoid leaving System.debug() statments in code as they negativly influence performance.',
89+
file: '/home/andreas/PMD/source/pmd-it/pmd-github-action-issue-127/src/Test.cls',
90+
startLine: 3,
91+
endLine: 3
92+
}
93+
);
94+
});
6295
});
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
3+
"version": "2.1.0",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "PMD",
9+
"version": "6.49.0",
10+
"informationUri": "https://pmd.github.io/pmd/",
11+
"rules": [
12+
{
13+
"id": "AvoidProductionDebugLogs",
14+
"shortDescription": {
15+
"text": "Avoid leaving System.debug() statments in code as they negativly influence performance."
16+
},
17+
"fullDescription": {},
18+
"helpUri": "",
19+
"help": {},
20+
"properties": {
21+
"ruleset": "My Default",
22+
"priority": 5,
23+
"tags": [
24+
"My Default"
25+
]
26+
}
27+
},
28+
{
29+
"id": "DebugsShouldUseLoggingLevel",
30+
"shortDescription": {
31+
"text": "Calls to System.debug should specify a logging level."
32+
},
33+
"fullDescription": {
34+
"text": "\nThe first parameter of System.debug, when using the signature with two parameters, is a LoggingLevel enum.\n\nHaving the Logging Level specified provides a cleaner log, and improves readability of it.\n "
35+
},
36+
"helpUri": "https://pmd.github.io/pmd-6.49.0/pmd_rules_apex_bestpractices.html#debugsshoulduselogginglevel",
37+
"help": {
38+
"text": "\nThe first parameter of System.debug, when using the signature with two parameters, is a LoggingLevel enum.\n\nHaving the Logging Level specified provides a cleaner log, and improves readability of it.\n "
39+
},
40+
"properties": {
41+
"ruleset": "Best Practices",
42+
"priority": 3,
43+
"tags": [
44+
"Best Practices"
45+
]
46+
}
47+
}
48+
]
49+
}
50+
},
51+
"results": [
52+
{
53+
"ruleId": "AvoidProductionDebugLogs",
54+
"ruleIndex": 0,
55+
"message": {
56+
"text": "Avoid leaving System.debug() statments in code as they negativly influence performance."
57+
},
58+
"locations": [
59+
{
60+
"physicalLocation": {
61+
"artifactLocation": {
62+
"uri": "/home/andreas/PMD/source/pmd-it/pmd-github-action-issue-127/src/Test.cls"
63+
},
64+
"region": {
65+
"startLine": 3,
66+
"startColumn": 12,
67+
"endLine": 3,
68+
"endColumn": 16
69+
}
70+
}
71+
}
72+
]
73+
},
74+
{
75+
"ruleId": "DebugsShouldUseLoggingLevel",
76+
"ruleIndex": 1,
77+
"message": {
78+
"text": "Calls to System.debug should specify a logging level."
79+
},
80+
"locations": [
81+
{
82+
"physicalLocation": {
83+
"artifactLocation": {
84+
"uri": "/home/andreas/PMD/source/pmd-it/pmd-github-action-issue-127/src/Test.cls"
85+
},
86+
"region": {
87+
"startLine": 3,
88+
"startColumn": 12,
89+
"endLine": 3,
90+
"endColumn": 16
91+
}
92+
}
93+
}
94+
]
95+
}
96+
],
97+
"invocations": [
98+
{
99+
"executionSuccessful": true,
100+
"toolConfigurationNotifications": [],
101+
"toolExecutionNotifications": []
102+
}
103+
]
104+
}
105+
]
106+
}

0 commit comments

Comments
 (0)