Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle empty rule description #133

Merged
merged 1 commit into from
Sep 24, 2022
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
5 changes: 4 additions & 1 deletion lib/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ function createAnnotation(location, title) {
}

function createDescription(rule) {
const lines = rule.fullDescription.text.split(/\n|\r\n/);
const lines = rule.fullDescription.text !== undefined
? rule.fullDescription.text.split(/\n|\r\n/)
: [''];

// remove empty first line
if (lines.length > 1 && lines[0] === '') {
lines.splice(0, 1);
Expand Down
33 changes: 33 additions & 0 deletions tests/annotations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,37 @@ https://pmd.github.io/pmd-6.40.0/pmd_rules_apex_bestpractices.html#unusedlocalva
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 });
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 });
});

it('can deal with empty full description (issue #127)', () => {
const report = sarif.loadReport(path.join(__dirname, 'data', 'pmd-report-empty-full-description.sarif'));
annotations.processSarifReport(report);

expect(core.error).toHaveBeenCalledTimes(0);
expect(core.warning).toHaveBeenCalledTimes(1);
expect(core.warning).toHaveBeenNthCalledWith(1, `The first parameter of System.debug, when using the signature with two parameters, is a LoggingLevel enum.

Having the Logging Level specified provides a cleaner log, and improves readability of it.

DebugsShouldUseLoggingLevel (Priority: 3, Ruleset: Best Practices)
https://pmd.github.io/pmd-6.49.0/pmd_rules_apex_bestpractices.html#debugsshoulduselogginglevel`,
{
title: 'Calls to System.debug should specify a logging level.',
file: '/home/andreas/PMD/source/pmd-it/pmd-github-action-issue-127/src/Test.cls',
startLine: 3,
endLine: 3
}
);
expect(core.notice).toHaveBeenCalledTimes(1);
expect(core.notice).toHaveBeenNthCalledWith(1, `

AvoidProductionDebugLogs (Priority: 5, Ruleset: My Default)
`,
{
title: 'Avoid leaving System.debug() statments in code as they negativly influence performance.',
file: '/home/andreas/PMD/source/pmd-it/pmd-github-action-issue-127/src/Test.cls',
startLine: 3,
endLine: 3
}
);
});
});
106 changes: 106 additions & 0 deletions tests/data/pmd-report-empty-full-description.sarif
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "PMD",
"version": "6.49.0",
"informationUri": "https://pmd.github.io/pmd/",
"rules": [
{
"id": "AvoidProductionDebugLogs",
"shortDescription": {
"text": "Avoid leaving System.debug() statments in code as they negativly influence performance."
},
"fullDescription": {},
"helpUri": "",
"help": {},
"properties": {
"ruleset": "My Default",
"priority": 5,
"tags": [
"My Default"
]
}
},
{
"id": "DebugsShouldUseLoggingLevel",
"shortDescription": {
"text": "Calls to System.debug should specify a logging level."
},
"fullDescription": {
"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 "
},
"helpUri": "https://pmd.github.io/pmd-6.49.0/pmd_rules_apex_bestpractices.html#debugsshoulduselogginglevel",
"help": {
"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 "
},
"properties": {
"ruleset": "Best Practices",
"priority": 3,
"tags": [
"Best Practices"
]
}
}
]
}
},
"results": [
{
"ruleId": "AvoidProductionDebugLogs",
"ruleIndex": 0,
"message": {
"text": "Avoid leaving System.debug() statments in code as they negativly influence performance."
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "/home/andreas/PMD/source/pmd-it/pmd-github-action-issue-127/src/Test.cls"
},
"region": {
"startLine": 3,
"startColumn": 12,
"endLine": 3,
"endColumn": 16
}
}
}
]
},
{
"ruleId": "DebugsShouldUseLoggingLevel",
"ruleIndex": 1,
"message": {
"text": "Calls to System.debug should specify a logging level."
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "/home/andreas/PMD/source/pmd-it/pmd-github-action-issue-127/src/Test.cls"
},
"region": {
"startLine": 3,
"startColumn": 12,
"endLine": 3,
"endColumn": 16
}
}
}
]
}
],
"invocations": [
{
"executionSuccessful": true,
"toolConfigurationNotifications": [],
"toolExecutionNotifications": []
}
]
}
]
}