Skip to content

Commit 882ec35

Browse files
committed
[PLUTO-1411] Add semgrep test
1 parent 027361f commit 882ec35

File tree

6 files changed

+149
-102
lines changed

6 files changed

+149
-102
lines changed

.github/workflows/it-test.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@ jobs:
5252
run_test "pylint" "."
5353
5454
# Run Semgrep tests with rules sorting
55-
run_test "semgrep" ".runs[0].tool.driver.rules |= if . then sort_by(.id) else . end"
55+
run_test "semgrep" ".runs[0].tool.driver.rules |= if . then sort_by(.id) else . end"
56+
57+
# Run PMD tests with rules sorting
58+
run_test "pmd" ".runs[0].tool.driver.rules |= if . then sort_by(.id) else . end"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
runtimes:
2+
tools:
3+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset name="Test PMD Ruleset"
3+
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
6+
7+
<description>Test PMD ruleset</description>
8+
9+
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
10+
<rule ref="category/java/errorprone.xml/UnconditionalIfStatement"/>
11+
</ruleset>

plugins/tools/pmd/test/src/Test.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Test {
2+
private String unusedField; // PMD: UnusedPrivateField
3+
4+
public void testMethod() {
5+
if (true) { // PMD: UnconditionalIfStatement
6+
System.out.println("This is always true");
7+
}
8+
9+
String str = null;
10+
if (str.equals("test")) { // PMD: NullPointerException
11+
System.out.println("This will cause NPE");
12+
}
13+
}
14+
}
+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"version": "2.1.0",
3+
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "PMD",
9+
"version": "6.55.0",
10+
"rules": [
11+
{
12+
"id": "UnusedPrivateField",
13+
"name": "UnusedPrivateField",
14+
"shortDescription": {
15+
"text": "Unused private field"
16+
},
17+
"fullDescription": {
18+
"text": "Detects when a private field is declared and/or assigned a value, but never used."
19+
},
20+
"helpUri": "https://pmd.github.io/pmd-6.55.0/pmd_rules_java_bestpractices.html#unusedprivatefield"
21+
},
22+
{
23+
"id": "UnconditionalIfStatement",
24+
"name": "UnconditionalIfStatement",
25+
"shortDescription": {
26+
"text": "Unconditional if statement"
27+
},
28+
"fullDescription": {
29+
"text": "Do not use 'if' statements that are always true or always false."
30+
},
31+
"helpUri": "https://pmd.github.io/pmd-6.55.0/pmd_rules_java_errorprone.html#unconditionalifstatement"
32+
},
33+
{
34+
"id": "NullPointerException",
35+
"name": "NullPointerException",
36+
"shortDescription": {
37+
"text": "Null pointer exception"
38+
},
39+
"fullDescription": {
40+
"text": "Code can throw a NullPointerException."
41+
},
42+
"helpUri": "https://pmd.github.io/pmd-6.55.0/pmd_rules_java_errorprone.html#nullpointerexception"
43+
}
44+
]
45+
}
46+
},
47+
"results": [
48+
{
49+
"ruleId": "UnusedPrivateField",
50+
"level": "warning",
51+
"message": {
52+
"text": "The private field 'unusedField' is assigned but never used"
53+
},
54+
"locations": [
55+
{
56+
"physicalLocation": {
57+
"artifactLocation": {
58+
"uri": "file:///Test.java"
59+
},
60+
"region": {
61+
"startLine": 2,
62+
"startColumn": 5,
63+
"endLine": 2,
64+
"endColumn": 25
65+
}
66+
}
67+
}
68+
]
69+
},
70+
{
71+
"ruleId": "UnconditionalIfStatement",
72+
"level": "warning",
73+
"message": {
74+
"text": "Do not use 'if' statements that are always true"
75+
},
76+
"locations": [
77+
{
78+
"physicalLocation": {
79+
"artifactLocation": {
80+
"uri": "file:///Test.java"
81+
},
82+
"region": {
83+
"startLine": 5,
84+
"startColumn": 9,
85+
"endLine": 5,
86+
"endColumn": 15
87+
}
88+
}
89+
}
90+
]
91+
},
92+
{
93+
"ruleId": "NullPointerException",
94+
"level": "warning",
95+
"message": {
96+
"text": "Potential null pointer dereference of str"
97+
},
98+
"locations": [
99+
{
100+
"physicalLocation": {
101+
"artifactLocation": {
102+
"uri": "file:///Test.java"
103+
},
104+
"region": {
105+
"startLine": 10,
106+
"startColumn": 9,
107+
"endLine": 10,
108+
"endColumn": 25
109+
}
110+
}
111+
}
112+
]
113+
}
114+
]
115+
}
116+
]
117+
}

tools/pmd/default-ruleset.xml

-101
This file was deleted.

0 commit comments

Comments
 (0)