diff --git a/src/main/java/com/cflint/JSONOutput.java b/src/main/java/com/cflint/JSONOutput.java index 30aa8caf9..7963d46a2 100644 --- a/src/main/java/com/cflint/JSONOutput.java +++ b/src/main/java/com/cflint/JSONOutput.java @@ -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())); @@ -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(); } } diff --git a/src/test/java/com/cflint/TestJSONOutput.java b/src/test/java/com/cflint/TestJSONOutput.java index c92b72cf6..a53a51e89 100644 --- a/src/test/java/com/cflint/TestJSONOutput.java +++ b/src/test/java/com/cflint/TestJSONOutput.java @@ -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()); } @@ -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()); } diff --git a/src/test/resources/com/cflint/tests/CompareInsteadOfAssign/Compare1.expected.txt b/src/test/resources/com/cflint/tests/CompareInsteadOfAssign/Compare1.expected.txt index 7eb4ae2ea..171fd750b 100644 --- a/src/test/resources/com/cflint/tests/CompareInsteadOfAssign/Compare1.expected.txt +++ b/src/test/resources/com/cflint/tests/CompareInsteadOfAssign/Compare1.expected.txt @@ -4,8 +4,8 @@ "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", @@ -13,15 +13,15 @@ "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", @@ -29,5 +29,5 @@ "message" : "CWE-482: Comparing instead of Assigning", "variable" : "EQ", "expression" : "x.x EQ 6" - } + } ] } ] \ No newline at end of file diff --git a/src/test/resources/com/cflint/tests/UnusedArgument/UnusedArgument_152b.expected.txt b/src/test/resources/com/cflint/tests/UnusedArgument/UnusedArgument_152b.expected.txt index 5dd733944..3e871b878 100644 --- a/src/test/resources/com/cflint/tests/UnusedArgument/UnusedArgument_152b.expected.txt +++ b/src/test/resources/com/cflint/tests/UnusedArgument/UnusedArgument_152b.expected.txt @@ -4,8 +4,8 @@ "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", @@ -13,5 +13,5 @@ "message" : "Argument xyzzy is not used in function helloWorld, consider removing it.", "variable" : "xyzzy", "expression" : "" - } + } ] } ] \ No newline at end of file