Skip to content

Remove useless PMD data from readups #25

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

Merged
merged 1 commit into from
Jan 29, 2018
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
8 changes: 6 additions & 2 deletions src/OutputParser.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ class OutputParser {

public void print(String line) {
if(isJson(line)) {
super.print(line)
super.print(sanitize(line))
} else {
this.err.print(line)
}
}

boolean isJson(txt) {
return txt.startsWith("{");
return txt.trim().startsWith("{")
}

String sanitize(line) {
return line.replaceFirst('(?s)### \\[PMD properties\\][^"]*', '')
}
}
}
58 changes: 55 additions & 3 deletions test/OutputParserTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,66 @@ class OutputParserTest {
public void redirectNonJsonInput() {
parser.out.print("This is a warning")
assert out.toString("UTF-8").isEmpty()
assert "This is a warning", err.toString("UTF-8")
assertEquals "This is a warning", err.toString("UTF-8")
}

@Test
public void printJsonLines() {
parser.out.print("{}")
assert err.toString("UTF-8").isEmpty()
assert "{}", out.toString("UTF-8")
assertEquals "{}", out.toString("UTF-8")
}
}

@Test
public void removeDeveloperPropertiesFromReadup() {
def issue = '''
{
"type": "issue",
"check_name": "AvoidMultipleUnaryOperators",
"description": "Using multiple unary operators may be a bug, and/or is confusing.",
"content": {
"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"
},
"categories": [
"Style"
],
"location": {
"path": "src/main/java/com/google/common/collect/Lists.java",
"lines": {
"begin": 1007,
"end": 1007
}
},
"severity": "normal",
"remediation_points": 50000
}
'''
def expectedIssue = '''
{
"type": "issue",
"check_name": "AvoidMultipleUnaryOperators",
"description": "Using multiple unary operators may be a bug, and/or is confusing.",
"content": {
"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"
},
"categories": [
"Style"
],
"location": {
"path": "src/main/java/com/google/common/collect/Lists.java",
"lines": {
"begin": 1007,
"end": 1007
}
},
"severity": "normal",
"remediation_points": 50000
}
'''

parser.out.print(issue)

assert err.toString("UTF-8").isEmpty()
assertEquals expectedIssue, out.toString("UTF-8")
}
}