Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneberly committed May 10, 2016
1 parent c07e625 commit 5a9765c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/cflint/JSONOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ public void output(final BugList bugList, final Writer writer, final boolean sho
jg.writeStringField("message", code);
jg.writeStringField("category", "CFLINT");
jg.writeStringField("abbrev", abbrev(code));
jg.writeFieldName("locations");
jg.writeStartArray();
do {
jg.writeObjectFieldStart("location");
jg.writeStartObject();
jg.writeStringField("file",notNull(bugInfo.getFilename()));
jg.writeStringField("fileName",filename(bugInfo.getFilename()));
jg.writeStringField("function",filename(bugInfo.getFunction()));
Expand All @@ -63,6 +65,7 @@ public void output(final BugList bugList, final Writer writer, final boolean sho
prevbugInfo = bugInfo;
bugInfo = iterator.hasNext() ? iterator.next() : null;
} while (isGrouped(prevbugInfo, bugInfo));
jg.writeEndArray();
jg.writeEndObject();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/cflint/TestJSONOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void testOutput() throws IOException {
BugInfo bugInfo = new BugInfo.BugInfoBuilder().setFunction("testf").setMessageCode("PARSE_ERROR").setFilename("c:\\temp\\test.cfc").build();
bugList.add(bugInfo);
outputer.output(bugList, writer, false);
String expectedText = "[{\"severity\":\"\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"location\":{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":\"0\",\"line\":\"0\",\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}}]";
String expectedText = "[{\"severity\":\"\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":\"0\",\"line\":\"0\",\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]}]";
// assertEquals(JSONValue.parse(expectedText),JSONValue.parse(writer.toString()));
assertEquals(expectedText,writer.toString());
}
Expand All @@ -38,7 +38,7 @@ public void testStats() throws IOException {
BugInfo bugInfo = new BugInfo.BugInfoBuilder().setFunction("testf").setMessageCode("PARSE_ERROR").setFilename("c:\\temp\\test.cfc").build();
bugList.add(bugInfo);
outputer.output(bugList, writer, true);
String expectedText = "[{\"severity\":\"\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"location\":{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":\"0\",\"line\":\"0\",\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}},{\"code\":\"PARSE_ERROR\",\"count\":\"1\"}]";
String expectedText = "[{\"severity\":\"\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":\"0\",\"line\":\"0\",\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]},{\"code\":\"PARSE_ERROR\",\"count\":\"1\"}]";
assertEquals(expectedText,writer.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
"message" : "COMPARE_INSTEAD_OF_ASSIGN",
"category" : "CFLINT",
"abbrev" : "CI",
"location" : {
"file" : "src\\test\\resources\\com\\cflint\\tests\\CompareInsteadOfAssign\\Compare1.cfm",
"locations" : [ {
"file" : "src/test/resources/com/cflint/tests/CompareInsteadOfAssign/Compare1.cfm",
"fileName" : "Compare1.cfm",
"function" : "",
"column" : "5",
"line" : "5",
"message" : "CWE-482: Comparing instead of Assigning",
"variable" : "==",
"expression" : "x.x == 2"
}
} ]
}, {
"severity" : "WARNING",
"id" : "COMPARE_INSTEAD_OF_ASSIGN",
"message" : "COMPARE_INSTEAD_OF_ASSIGN",
"category" : "CFLINT",
"abbrev" : "CI",
"location" : {
"file" : "src\\test\\resources\\com\\cflint\\tests\\CompareInsteadOfAssign\\Compare1.cfm",
"locations" : [ {
"file" : "src/test/resources/com/cflint/tests/CompareInsteadOfAssign/Compare1.cfm",
"fileName" : "Compare1.cfm",
"function" : "",
"column" : "5",
"line" : "9",
"message" : "CWE-482: Comparing instead of Assigning",
"variable" : "EQ",
"expression" : "x.x EQ 6"
}
} ]
} ]
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"message" : "UNUSED_METHOD_ARGUMENT",
"category" : "CFLINT",
"abbrev" : "UM",
"location" : {
"file" : "src\\test\\resources\\com\\cflint\\tests\\UnusedArgument\\UnusedArgument_152b.cfc",
"locations" : [ {
"file" : "src/test/resources/com/cflint/tests/UnusedArgument/UnusedArgument_152b.cfc",
"fileName" : "UnusedArgument_152b.cfc",
"function" : "helloWorld",
"column" : "0",
"line" : "6",
"message" : "Argument xyzzy is not used in function helloWorld, consider removing it.",
"variable" : "xyzzy",
"expression" : ""
}
} ]
} ]

0 comments on commit 5a9765c

Please sign in to comment.