Skip to content

Commit 3c17c1c

Browse files
Fix readup (#25)
* Related to https://github.com/codeclimate/app/issues/5817 * Remove bogus markdown - intended for PMD internal use only (#25)
1 parent b961f0d commit 3c17c1c

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

src/OutputParser.groovy

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ class OutputParser {
1515

1616
public void print(String line) {
1717
if(isJson(line)) {
18-
super.print(line)
18+
super.print(sanitize(line))
1919
} else {
2020
this.err.print(line)
2121
}
2222
}
2323

2424
boolean isJson(txt) {
25-
return txt.startsWith("{");
25+
return txt.trim().startsWith("{")
26+
}
27+
28+
String sanitize(line) {
29+
return line.replaceFirst('(?s)### \\[PMD properties\\][^"]*', '')
2630
}
2731
}
2832
}

test/OutputParserTest.groovy

+55-3
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,66 @@ class OutputParserTest {
2121
public void redirectNonJsonInput() {
2222
parser.out.print("This is a warning")
2323
assert out.toString("UTF-8").isEmpty()
24-
assert "This is a warning", err.toString("UTF-8")
24+
assertEquals "This is a warning", err.toString("UTF-8")
2525
}
2626

2727
@Test
2828
public void printJsonLines() {
2929
parser.out.print("{}")
3030
assert err.toString("UTF-8").isEmpty()
31-
assert "{}", out.toString("UTF-8")
31+
assertEquals "{}", out.toString("UTF-8")
3232
}
33-
}
3433

34+
@Test
35+
public void removeDeveloperPropertiesFromReadup() {
36+
def issue = '''
37+
{
38+
"type": "issue",
39+
"check_name": "AvoidMultipleUnaryOperators",
40+
"description": "Using multiple unary operators may be a bug, and/or is confusing.",
41+
"content": {
42+
"body": "## AvoidMultipleUnaryOperators\n\nSince: PMD 4.2\n\nPriority: Medium High\n\n[Categories](https://github.com/codeclimate/spec/blob/master/SPEC.md#categories): Style\n\n[Remediation Points](https://github.com/codeclimate/spec/blob/master/SPEC.md#remediation-points): 50000\n\nThe use of multiple unary operators may be problematic, and/or confusing. Ensure that the intended usage is not a bug, or consider simplifying the expression.\n\n### Example:\n\n```java\n\n\n// These are typo bugs, or at best needlessly complex and confusing:\nint i = - -1;\nint j = + - +1;\nint z = ~~2;\nboolean b = !!true;\nboolean c = !!!true;\n\n// These are better:\nint i = 1;\nint j = -1;\nint z = 2;\nboolean b = true;\nboolean c = false;\n\n// And these just make your brain hurt:\nint i = ~-2;\nint j = -~7;\n\n \n``` \n\n### [PMD properties](http://pmd.github.io/pmd-6.0.1/customizing/pmd-developer.html)\n\nName | Value | Description\n--- | --- | ---\nviolationSuppressRegex | | Suppress violations with messages matching a regular expression\nviolationSuppressXPath | | Suppress violations on nodes which match a given relative XPath expression.\n"
43+
},
44+
"categories": [
45+
"Style"
46+
],
47+
"location": {
48+
"path": "src/main/java/com/google/common/collect/Lists.java",
49+
"lines": {
50+
"begin": 1007,
51+
"end": 1007
52+
}
53+
},
54+
"severity": "normal",
55+
"remediation_points": 50000
56+
}
57+
'''
58+
def expectedIssue = '''
59+
{
60+
"type": "issue",
61+
"check_name": "AvoidMultipleUnaryOperators",
62+
"description": "Using multiple unary operators may be a bug, and/or is confusing.",
63+
"content": {
64+
"body": "## AvoidMultipleUnaryOperators\n\nSince: PMD 4.2\n\nPriority: Medium High\n\n[Categories](https://github.com/codeclimate/spec/blob/master/SPEC.md#categories): Style\n\n[Remediation Points](https://github.com/codeclimate/spec/blob/master/SPEC.md#remediation-points): 50000\n\nThe use of multiple unary operators may be problematic, and/or confusing. Ensure that the intended usage is not a bug, or consider simplifying the expression.\n\n### Example:\n\n```java\n\n\n// These are typo bugs, or at best needlessly complex and confusing:\nint i = - -1;\nint j = + - +1;\nint z = ~~2;\nboolean b = !!true;\nboolean c = !!!true;\n\n// These are better:\nint i = 1;\nint j = -1;\nint z = 2;\nboolean b = true;\nboolean c = false;\n\n// And these just make your brain hurt:\nint i = ~-2;\nint j = -~7;\n\n \n``` \n\n"
65+
},
66+
"categories": [
67+
"Style"
68+
],
69+
"location": {
70+
"path": "src/main/java/com/google/common/collect/Lists.java",
71+
"lines": {
72+
"begin": 1007,
73+
"end": 1007
74+
}
75+
},
76+
"severity": "normal",
77+
"remediation_points": 50000
78+
}
79+
'''
80+
81+
parser.out.print(issue)
82+
83+
assert err.toString("UTF-8").isEmpty()
84+
assertEquals expectedIssue, out.toString("UTF-8")
85+
}
86+
}

0 commit comments

Comments
 (0)