Skip to content

Commit

Permalink
Merge pull request #375 from TheRealAgentK/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
TheRealAgentK authored Jul 28, 2017
2 parents b12a9d2 + a231c75 commit d738ef4
Show file tree
Hide file tree
Showing 112 changed files with 613 additions and 423 deletions.
82 changes: 35 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Example of CFLint XML:
</location>
</issue>
...
<counts totalfiles="108" totalsize="55596">
<counts totallines="108" totalsize="55596">
<count code="CFQUERYPARAM_REQ" count="39"></count>
<count severity="WARNING" count="39"></count>
</counts>
Expand All @@ -236,51 +236,39 @@ JSON output can be created with

Example of CFLint JSON:

[ {
"severity" : "WARNING",
"id" : "CFQUERYPARAM_REQ",
"message" : "CFQUERYPARAM_REQ",
"category" : "CFLINT",
"abbrev" : "CR",
"locations" : [ {
"file" : "/Users/kai/Documents/Code/paypal.cfc",
"fileName" : "qrySearch.cfm",
"function" : "",
"column" : 0,
"line" : 79,
"message" : "<cfquery> should use <cfqueryparam/> for variable 'arguments.something'.",
"variable" : "arguments.something",
"expression" : "<cfquery name=\"qry\" datasource=\"#variables.dsn#\" cachedwithin=\"#createTimeSpan(0,0,arguments.cacheInMins,0)#\">\r\n...some Details..."
} ]
}, {
"severity" : "WARNING",
"id" : "CFQUERYPARAM_REQ",
"message" : "CFQUERYPARAM_REQ",
"category" : "CFLINT",
"abbrev" : "CR",
"locations" : [ {
"file" : "/Users/kai/Documents/Code/paypal.cfc",
"fileName" : "qrySearch.cfm",
"function" : "",
"column" : 0,
"line" : 145,
"message" : "<cfquery> should use <cfqueryparam/> for variable 'arguments.something'.",
"variable" : "arguments.something",
"expression" : "<cfquery name=\"qry\" datasource=\"#variables.dsn#\" cachedwithin=\"#createTimeSpan(0,0,arguments.cacheInMins,0)#\">\r\n...some Details..."
} ]
},
...
, {
"totalfiles" : 108
}, {
"totalsize" : 55690
}, {
"code" : "CFQUERYPARAM_REQ",
"count" : 4
}, {
"severity" : "WARNING",
"count" : 4
} ]
{
"version" : "",
"timestamp" : "1501202128",
"issues" : [ {
"severity" : "ERROR",
"id" : "MISSING_VAR",
"message" : "MISSING_VAR",
"category" : "CFLINT",
"abbrev" : "MV",
"locations" : [ {
"file" : "src/test/resources/com/cflint/tests/Ignores/ignoreCFMLAny2.cfc",
"fileName" : "ignoreCFMLAny2.cfc",
"function" : "testFunction",
"column" : 6,
"line" : 14,
"message" : "Variable someVar is not declared with a var statement.",
"variable" : "someVar",
"expression" : "someVar"
} ]
} ],
"counts" : {
"totalFiles" : 7,
"totalLines" : 49,
"countByCode" : [ {
"code" : "MISSING_VAR",
"count" : 1
} ],
"countBySeverity" : [ {
"severity" : "ERROR",
"count" : 1
} ]
}
}

### Text

Expand Down Expand Up @@ -313,7 +301,7 @@ Example of plain text output:

Total files:108
Total size 55690
Total lines:55690

Issue counts:1
CFQUERYPARAM_REQ:4
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/cflint/CFLintStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,40 @@ public class CFLintStats {
// Number of files
private long fileCount;
// Number of lines
private BigInteger totalSize = BigInteger.ZERO;
private BigInteger totalLines = BigInteger.ZERO;
// Bug counts for current execution
private BugCounts counts = new BugCounts();

public CFLintStats() {
super();
}

public CFLintStats(long timestamp, long fileCount, BigInteger totalSize) {
public CFLintStats(long timestamp, long fileCount, BigInteger totalLines) {
super();
this.timestamp = timestamp;
this.fileCount = fileCount;
this.totalSize = totalSize;
this.totalLines = totalLines;
}

public CFLintStats(long timestamp, long fileCount, BigInteger totalSize, BugCounts counts) {
public CFLintStats(long timestamp, long fileCount, BigInteger totalLines, BugCounts counts) {
super();
this.timestamp = timestamp;
this.fileCount = fileCount;
this.totalSize = totalSize;
this.totalLines = totalLines;
this.counts = counts;
}

public void addFile(long numberOfLines){
fileCount++;
totalSize = totalSize.add(BigInteger.valueOf(numberOfLines));
totalLines = totalLines.add(BigInteger.valueOf(numberOfLines));
}

public long getTimestamp() { return timestamp; }

public long getFileCount() { return fileCount; }

public BigInteger getTotalSize() {
return totalSize;
public BigInteger getTotalLines() {
return totalLines;
}

public BugCounts getCounts() { return counts; }
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/com/cflint/JSONOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public void output(final BugList bugList, final Writer writer, CFLintStats stats
// start global object
jg.writeStartObject();

// timestamp and version
jg.writeStringField("version",Version.getVersion());
jg.writeStringField("timestamp",Long.toString(stats.getTimestamp()));

// start issues array
jg.writeFieldName("issues");
jg.writeStartArray();
Expand Down Expand Up @@ -83,12 +87,13 @@ public void output(final BugList bugList, final Writer writer, CFLintStats stats
// end issues array
jg.writeEndArray();

// start summary object
jg.writeFieldName("summary");
// start counts object
jg.writeFieldName("counts");
jg.writeStartObject();
jg.writeNumberField("totalfiles", stats.getFileCount());
jg.writeFieldName("totalsize");
jg.writeNumber(stats.getTotalSize());
jg.writeNumberField("totalFiles", stats.getFileCount());
// totalLines has to be separated into writing the field name and the number - .writeNumberField() can't deal with BigInt
jg.writeFieldName("totalLines");
jg.writeNumber(stats.getTotalLines());
// start countByCode array
jg.writeFieldName("countByCode");
jg.writeStartArray();
Expand All @@ -113,7 +118,7 @@ public void output(final BugList bugList, final Writer writer, CFLintStats stats
}
// end countBySeverity array
jg.writeEndArray();
// end summary object
// end counts object
jg.writeEndObject();

// end global object
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cflint/TextOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void output(final BugList bugList, final Writer sb, CFLintStats stats) th
}

sb.append(newLine).append(newLine).append("Total files:" + stats.getFileCount());
sb.append(newLine).append("Total size " + stats.getTotalSize());
sb.append(newLine).append("Total lines:" + stats.getTotalLines());

sb.append(newLine).append(newLine).append("Issue counts:" + counts.noBugTypes());

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cflint/XMLOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void output(final BugList bugList, final Writer writer, final CFLintStats

writer.append("<counts");
writer.append(" totalfiles=\"").append(Long.toString(stats.getFileCount())).append("\"");
writer.append(" totalsize=\"").append(stats.getTotalSize().toString()).append("\">").append(System.getProperty(LINE_SEPARATOR));
writer.append(" totallines=\"").append(stats.getTotalLines().toString()).append("\">").append(System.getProperty(LINE_SEPARATOR));

for (final String code : counts.bugTypes()) {
writer.append("<count");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cflint/main/CFLintMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ private void execute() throws IOException, TransformerException, JAXBException,
}
if (verbose) {
display("Total files scanned: " + cflint.getStats().getFileCount());
display("Total size: " + cflint.getStats().getTotalSize());
display("Total LOC scanned: " + cflint.getStats().getTotalLines());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void writeIssues(BugList bugList, XMLStreamWriter xtw, CFLintStats stats
private void writeCounts(XMLStreamWriter xtw, BugCounts counts, CFLintStats stats) throws XMLStreamException {
xtw.writeStartElement("counts");
xtw.writeAttribute("totalfiles", Long.toString(stats.getFileCount()));
xtw.writeAttribute("totalsize", stats.getTotalSize().toString());
xtw.writeAttribute("totallines", stats.getTotalLines().toString());

for (String code : counts.bugTypes()) {
xtw.writeStartElement("count");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/findbugs/cflint-to-findbugs.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<xsl:value-of select="/issues/counts/@totalfiles"/>
</xsl:attribute>
<xsl:attribute name="total_size">
<xsl:value-of select="/issues/counts/@totalsize"/>
<xsl:value-of select="/issues/counts/@totallines"/>
</xsl:attribute>
<xsl:attribute name="priority_1">
<xsl:value-of select="count(/issues/issue[@severity = 'FATAL' or @severity = 'Fatal' or @severity = 'CRITICAL' or @severity = 'Critical'])"/>
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/cflint/TestJSONOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void testOutput() throws IOException {
bugList.add(bugInfo);
CFLintStats stats = new CFLintStats(123456L,1,new BigInteger("545454"));
outputer.output(bugList, writer, stats);
String expectedText = "{\"issues\":[{\"severity\":\"\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":1,\"line\":1,\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]}],\"summary\":{\"totalfiles\":1,\"totalsize\":545454,\"countByCode\":[],\"countBySeverity\":[]}}";
String expectedText = "{\"version\":\"\",\"timestamp\":\"123456\",\"issues\":[{\"severity\":\"\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":1,\"line\":1,\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]}],\"counts\":{\"totalFiles\":1,\"totalLines\":545454,\"countByCode\":[],\"countBySeverity\":[]}}";

assertEquals(expectedText,writer.toString());
}
Expand All @@ -43,7 +43,7 @@ public void testStats() throws IOException {
counts.add("PARSE_ERROR", null);
CFLintStats stats = new CFLintStats(123456L,1,new BigInteger("545454"),counts);
outputer.output(bugList, writer, stats);
String expectedText = "{\"issues\":[{\"severity\":\"\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":1,\"line\":1,\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]}],\"summary\":{\"totalfiles\":1,\"totalsize\":545454,\"countByCode\":[{\"code\":\"PARSE_ERROR\",\"count\":1}],\"countBySeverity\":[]}}";
String expectedText = "{\"version\":\"\",\"timestamp\":\"123456\",\"issues\":[{\"severity\":\"\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":1,\"line\":1,\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]}],\"counts\":{\"totalFiles\":1,\"totalLines\":545454,\"countByCode\":[{\"code\":\"PARSE_ERROR\",\"count\":1}],\"countBySeverity\":[]}}";

assertEquals(expectedText,writer.toString());
}
Expand All @@ -56,7 +56,7 @@ public void testStatsWithSeverity() throws IOException {
counts.add("PARSE_ERROR", "ERROR");
CFLintStats stats = new CFLintStats(123456L,1,new BigInteger("545454"),counts);
outputer.output(bugList, writer, stats);
String expectedText = "{\"issues\":[{\"severity\":\"ERROR\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":1,\"line\":1,\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]}],\"summary\":{\"totalfiles\":1,\"totalsize\":545454,\"countByCode\":[{\"code\":\"PARSE_ERROR\",\"count\":1}],\"countBySeverity\":[{\"severity\":\"ERROR\",\"count\":1}]}}";
String expectedText = "{\"version\":\"\",\"timestamp\":\"123456\",\"issues\":[{\"severity\":\"ERROR\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":1,\"line\":1,\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]}],\"counts\":{\"totalFiles\":1,\"totalLines\":545454,\"countByCode\":[{\"code\":\"PARSE_ERROR\",\"count\":1}],\"countBySeverity\":[{\"severity\":\"ERROR\",\"count\":1}]}}";

assertEquals(expectedText,writer.toString());
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/cflint/TestXMLOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void testOutput() throws IOException {
String expectedText = "<issues version=\"" + Version.getVersion() + "\" timestamp=\"123456\">\n" +
"<issue severity=\"\" id=\"PARSE_ERROR\" message=\"PARSE_ERROR\" category=\"CFLint\" abbrev=\"PE\"><location file=\"c:\\temp\\test.cfc\" fileName=\"test.cfc\" function=\"testf\" column=\"1\" line=\"1\" message=\"\" variable=\"\"><Expression><![CDATA[]]></Expression></location>\n" +
"</issue>\n" +
"<counts totalfiles=\"1\" totalsize=\"545454\">\n" +
"<counts totalfiles=\"1\" totallines=\"545454\">\n" +
"</counts>" +
"</issues>";
//remove the version
Expand All @@ -51,7 +51,7 @@ public void testStats() throws IOException {
String expectedText = "<issues version=\"" + Version.getVersion() + "\" timestamp=\"123456\">\n" +
"<issue severity=\"\" id=\"PARSE_ERROR\" message=\"PARSE_ERROR\" category=\"CFLint\" abbrev=\"PE\"><location file=\"c:\\temp\\test.cfc\" fileName=\"test.cfc\" function=\"testf\" column=\"1\" line=\"1\" message=\"\" variable=\"\"><Expression><![CDATA[]]></Expression></location>\n" +
"</issue>\n" +
"<counts totalfiles=\"1\" totalsize=\"545454\">\n" +
"<counts totalfiles=\"1\" totallines=\"545454\">\n" +
"<count code=\"PARSE_ERROR\" count=\"1\" />\n" +
"</counts>" +
"</issues>";
Expand All @@ -70,7 +70,7 @@ public void testStatsAndSeverity() throws IOException {
String expectedText = "<issues version=\"" + Version.getVersion() + "\" timestamp=\"123456\">\n" +
"<issue severity=\"ERROR\" id=\"PARSE_ERROR\" message=\"PARSE_ERROR\" category=\"CFLint\" abbrev=\"PE\"><location file=\"c:\\temp\\test.cfc\" fileName=\"test.cfc\" function=\"testf\" column=\"1\" line=\"1\" message=\"\" variable=\"\"><Expression><![CDATA[]]></Expression></location>\n" +
"</issue>\n" +
"<counts totalfiles=\"1\" totalsize=\"545454\">\n" +
"<counts totalfiles=\"1\" totallines=\"545454\">\n" +
"<count code=\"PARSE_ERROR\" count=\"1\" />\n" +
"<count severity=\"ERROR\" count=\"1\" />" +
"</counts>" +
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/cflint/integration/TestFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public void exceptionOccurred(Throwable exception, String messageCode, String fi
writeExpectFile(expectedFile, actualTree);
}
assertEquals(
expectedText.replaceAll("\\\\","/").replaceAll("/+","/").replaceAll("\r\n", "\n"),
actualTree.replaceAll("\\\\","/").replaceAll("/+","/").replaceAll("\r\n", "\n"));
expectedText.replaceAll("\\\\","/").replaceAll("/+","/").replaceAll("\r\n", "\n").replaceAll("\"timestamp\" : \"\\d+\"", "\"timestamp\" : \"0\""),
actualTree.replaceAll("\\\\","/").replaceAll("/+","/").replaceAll("\r\n", "\n").replaceAll("\"timestamp\" : \"\\d+\"", "\"timestamp\" : \"0\""));
}
}

Expand Down
Loading

0 comments on commit d738ef4

Please sign in to comment.