diff --git a/build.gradle b/build.gradle
index 99c78be8a..5f6d46e7f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -32,11 +32,12 @@ targetCompatibility = 1.7
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url "http://repo.maven.apache.org/maven2" }
+ maven { url "http://cfmlprojects.org/artifacts" }
}
dependencies {
- compile group: 'com.github.cfparser', name: 'cfparser', version:'2.2.1'
- compile group: 'com.github.cfparser', name: 'cfml.parsing', version:'2.2.1'
- compile group: 'com.github.cfparser', name: 'cfml.dictionary', version:'2.2.1'
+ compile group: 'com.github.cfparser', name: 'cfparser', version:'2.2.6'
+ compile group: 'com.github.cfparser', name: 'cfml.parsing', version:'2.2.6'
+ compile group: 'com.github.cfparser', name: 'cfml.dictionary', version:'2.2.6'
compile group: 'junit', name: 'junit', version:'4.12'
compile group: 'org.jdom', name: 'jdom', version:'1.1.3'
compile group: 'org.antlr', name: 'antlr4-runtime', version:'4.5.2-1'
diff --git a/pom.xml b/pom.xml
index 6b39618ba..f3846ce81 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
4.0.0
com.github.cflint
CFLint
- 0.7.1
+ 0.7.2
CFLint
@@ -27,6 +27,12 @@
cfparser
https://github.com/jjames967
+
+ Denny Valliant
+ valliantster@gmail.com
+ cfparser
+ https://github.com/denuno
+
@@ -35,8 +41,16 @@
git@github.com:cflint/CFLint.git
+
+
+ cfmlprojects
+ cfmlprojects
+ http://cfmlprojects.org/artifacts
+
+
+
-
+
The New BSD License
http://www.opensource.org/licenses/bsd-license.html
repo
@@ -51,18 +65,18 @@
com.github.cfparser
cfparser
- 2.2.2
+ 2.2.5
pom
com.github.cfparser
cfml.parsing
- 2.2.2
+ 2.2.6
com.github.cfparser
cfml.dictionary
- 2.2.2
+ 2.2.6
junit
diff --git a/src/main/java/com/cflint/BugInfo.java b/src/main/java/com/cflint/BugInfo.java
index 47cad5b2d..78b8f4c94 100644
--- a/src/main/java/com/cflint/BugInfo.java
+++ b/src/main/java/com/cflint/BugInfo.java
@@ -144,7 +144,8 @@ private final String notNull(String in){
private void doMessageText(final Element elem) {
String message = notNull(bugInfo.getMessage());
- message = message.replaceAll("\\$\\{variable\\}",notNull(bugInfo.getVariable()));
+ String variable = notNull(bugInfo.getVariable());
+ message = message.replace("${variable}",variable);
if(message.contains("{tag}") && elem != null){
message = message.replaceAll("\\$\\{tag\\}",notNull(elem.getName()));
}
diff --git a/src/main/java/com/cflint/CFLint.java b/src/main/java/com/cflint/CFLint.java
index a1155d605..6b433d643 100644
--- a/src/main/java/com/cflint/CFLint.java
+++ b/src/main/java/com/cflint/CFLint.java
@@ -306,6 +306,10 @@ private void process(final Element elem, final String space, Context context)
for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) {
try{
structurePlugin.startComponent(context, bugs);
+ for(final ContextMessage message : context.getMessages()){
+ reportRule(elem, null, context, (CFLintScanner)structurePlugin, message);
+ }
+ context.getMessages().clear();
}catch(Exception e){
e.printStackTrace();
}
@@ -322,6 +326,10 @@ else if (elem.getName().equalsIgnoreCase("cffunction")) {
for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) {
try{
structurePlugin.startFunction(context, bugs);
+ for(final ContextMessage message : context.getMessages()){
+ reportRule(elem, null, context, (CFLintScanner)structurePlugin, message);
+ }
+ context.getMessages().clear();
}catch(Exception e){
e.printStackTrace();
}
@@ -413,6 +421,11 @@ else if (elem.getName().equalsIgnoreCase("cffunction")) {
for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) {
try{
structurePlugin.endFunction(context, bugs);
+ for(final ContextMessage message : context.getMessages()){
+ reportRule(elem, null, context, (CFLintScanner)structurePlugin, message);
+ }
+ context.getMessages().clear();
+
}catch(Exception e){
e.printStackTrace();
}
@@ -424,6 +437,10 @@ else if (elem.getName().equalsIgnoreCase("cffunction")) {
for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) {
try{
structurePlugin.endComponent(context, bugs);
+ for(final ContextMessage message : context.getMessages()){
+ reportRule(elem, null, context, (CFLintScanner)structurePlugin, message);
+ }
+ context.getMessages().clear();
}catch(Exception e){
e.printStackTrace();
}
@@ -491,6 +508,10 @@ private void process(final CFScriptStatement expression, final String filename,
for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) {
try{
structurePlugin.startComponent(context, bugs);
+ for(final ContextMessage message : context.getMessages()){
+ reportRule(elem, null, context, (CFLintScanner)structurePlugin, message);
+ }
+ context.getMessages().clear();
}catch(Exception e){
e.printStackTrace();
}
@@ -508,6 +529,10 @@ else if (expression instanceof CFFuncDeclStatement) {
for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) {
try{
structurePlugin.startFunction(context, bugs);
+ for(final ContextMessage message : context.getMessages()){
+ reportRule(elem, null, context, (CFLintScanner)structurePlugin, message);
+ }
+ context.getMessages().clear();
}catch(Exception e){
e.printStackTrace();
}
@@ -542,6 +567,10 @@ else if (expression instanceof CFFuncDeclStatement) {
for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) {
try{
structurePlugin.endComponent(context, bugs);
+ for(final ContextMessage message : context.getMessages()){
+ reportRule(elem, null, context, (CFLintScanner)structurePlugin, message);
+ }
+ context.getMessages().clear();
}catch(Exception e){
e.printStackTrace();
}
@@ -585,6 +614,10 @@ else if (expression instanceof CFFuncDeclStatement) {
for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) {
try{
structurePlugin.endFunction(context, bugs);
+ for(final ContextMessage message : context.getMessages()){
+ reportRule(elem, null, context, (CFLintScanner)structurePlugin, message);
+ }
+ context.getMessages().clear();
}catch(Exception e){
e.printStackTrace();
}
@@ -833,7 +866,12 @@ else if(elem != null){
if (expression instanceof CFExpression){
bugs.add(bldr.build((CFExpression)expression, elem));
}else{
- bugs.add(bldr.build((CFParsedStatement)expression, elem));
+ BugInfo bug = bldr.build((CFParsedStatement)expression, elem);
+ if(msg.getLine() != null){
+ bug.setLine(msg.getLine());
+ bug.setColumn(0);
+ }
+ bugs.add(bug);
}
}
diff --git a/src/main/java/com/cflint/plugins/Context.java b/src/main/java/com/cflint/plugins/Context.java
index a57f3fcea..da2a45f64 100644
--- a/src/main/java/com/cflint/plugins/Context.java
+++ b/src/main/java/com/cflint/plugins/Context.java
@@ -119,22 +119,33 @@ public List getMessages() {
public void addMessage(String messageCode, String variable) {
messages.add(new ContextMessage(messageCode,variable));
}
+ public void addMessage(String messageCode, String variable, Integer line) {
+ messages.add(new ContextMessage(messageCode,variable,line));
+ }
public static class ContextMessage{
String messageCode;
String variable;
+ Integer line;
public ContextMessage(String messageCode, String variable) {
super();
this.messageCode = messageCode;
this.variable = variable;
}
+ public ContextMessage(String messageCode, String variable,Integer line) {
+ this(messageCode,variable);
+ this.line = line;
+ }
public String getMessageCode() {
return messageCode;
}
public String getVariable() {
return variable;
}
+ public Integer getLine() {
+ return line;
+ }
}
public Context subContext(final Element elem){
diff --git a/src/main/java/com/cflint/plugins/core/AbortChecker.java b/src/main/java/com/cflint/plugins/core/AbortChecker.java
index 06c88e051..6a4bb16c1 100644
--- a/src/main/java/com/cflint/plugins/core/AbortChecker.java
+++ b/src/main/java/com/cflint/plugins/core/AbortChecker.java
@@ -1,6 +1,5 @@
package com.cflint.plugins.core;
-import com.cflint.BugInfo;
import com.cflint.BugList;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;
@@ -16,11 +15,7 @@ public class AbortChecker extends CFLintScannerAdapter {
@Override
public void expression(final CFScriptStatement expression, final Context context, final BugList bugs) {
if (expression instanceof CFAbortStatement) {
- int lineNo = ((CFAbortStatement) expression).getLine() + context.startLine() - 1;
- bugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("AVOID_USING_ABORT")
- .setSeverity(severity).setFilename(context.getFilename())
- .setMessage("Abort statement at line " + lineNo + ". Avoid using abort in production code.")
- .build());
+ context.addMessage("AVOID_USING_ABORT", null);
}
}
}
\ No newline at end of file
diff --git a/src/main/java/com/cflint/plugins/core/ArgDefChecker.java b/src/main/java/com/cflint/plugins/core/ArgDefChecker.java
index b20f25ab2..77a8b1ead 100644
--- a/src/main/java/com/cflint/plugins/core/ArgDefChecker.java
+++ b/src/main/java/com/cflint/plugins/core/ArgDefChecker.java
@@ -20,8 +20,6 @@ public void expression(final CFScriptStatement expression, final Context context
// handler.addArgument(param.getName());
final String name = argument.getName();
if (!argument.toString().contains("required") && !argument.toString().contains("=")) {
- function.getLine();
- function.getColumn();
context.addMessage("ARG_DEFAULT_MISSING", name);
}
}
diff --git a/src/main/java/com/cflint/plugins/core/ArgHintChecker.java b/src/main/java/com/cflint/plugins/core/ArgHintChecker.java
index 22ef3e762..7f10a53f1 100644
--- a/src/main/java/com/cflint/plugins/core/ArgHintChecker.java
+++ b/src/main/java/com/cflint/plugins/core/ArgHintChecker.java
@@ -1,6 +1,5 @@
package com.cflint.plugins.core;
-import com.cflint.BugInfo;
import com.cflint.BugList;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;
@@ -8,7 +7,6 @@
import net.htmlparser.jericho.Element;
public class ArgHintChecker extends CFLintScannerAdapter {
- final String severity = "INFO";
@Override
public void element(final Element element, final Context context, final BugList bugs) {
@@ -16,11 +14,7 @@ public void element(final Element element, final Context context, final BugList
final String name = element.getAttributeValue("name");
final String hint = element.getAttributeValue("hint");
if (hint == null || hint.length() == 0) {
- int begLine = element.getSource().getRow(element.getBegin());
- bugs.add(new BugInfo.BugInfoBuilder().setLine(begLine).setMessageCode("ARG_HINT_MISSING")
- .setSeverity(severity).setFilename(context.getFilename()).setFunction(context.getFunctionName())
- .setMessage("Argument " + name + " is missing a hint.")
- .build());
+ context.addMessage("ARG_HINT_MISSING", name);
}
}
}
diff --git a/src/main/java/com/cflint/plugins/core/ArgTypeChecker.java b/src/main/java/com/cflint/plugins/core/ArgTypeChecker.java
index 72f188576..ec8052592 100644
--- a/src/main/java/com/cflint/plugins/core/ArgTypeChecker.java
+++ b/src/main/java/com/cflint/plugins/core/ArgTypeChecker.java
@@ -1,6 +1,5 @@
package com.cflint.plugins.core;
-import com.cflint.BugInfo;
import com.cflint.BugList;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;
@@ -11,32 +10,21 @@
import net.htmlparser.jericho.Element;
public class ArgTypeChecker extends CFLintScannerAdapter {
- public static final String ARGUMENT = "Argument ";
- final String severity = "WARNING";
@Override
public void expression(final CFScriptStatement expression, final Context context, final BugList bugs) {
if (expression instanceof CFFuncDeclStatement) {
final CFFuncDeclStatement function = (CFFuncDeclStatement) expression;
- final int begLine = function.getLine();
for (final CFFunctionParameter argument : function.getFormals()) {
final String name = argument.getName();
final String variableType = argument.getType();
if (variableType == null) {
- bugs.add(new BugInfo.BugInfoBuilder().setLine(begLine).setMessageCode("ARG_TYPE_MISSING")
- .setSeverity(severity).setFilename(context.getFilename()).setFunction(context.getFunctionName())
- .setMessage(ARGUMENT + name + " is missing a type.")
- .setVariable(name)
- .build());
+ context.addMessage("ARG_TYPE_MISSING", name);
}
else if (variableType.equals("any")) {
- bugs.add(new BugInfo.BugInfoBuilder().setLine(begLine).setMessageCode("ARG_TYPE_ANY")
- .setSeverity(severity).setFilename(context.getFilename()).setFunction(context.getFunctionName())
- .setMessage(ARGUMENT + name + " is any. Please change to be the correct type.")
- .setVariable(name)
- .build());
+ context.addMessage("ARG_TYPE_ANY", name);
}
}
}
@@ -47,24 +35,14 @@ public void element(final Element element, final Context context, final BugList
if (element.getName().equals("cfargument")) {
final String name = element.getAttributeValue("name");
final String variableType = element.getAttributeValue("type");
- int begLine = element.getSource().getRow(element.getBegin());
if (variableType == null) {
- bugs.add(new BugInfo.BugInfoBuilder().setLine(begLine).setMessageCode("ARG_TYPE_MISSING")
- .setSeverity(severity).setFilename(context.getFilename()).setFunction(context.getFunctionName())
- .setMessage(ARGUMENT + name + " is missing a type.")
- .setVariable(name)
- .build());
+ context.addMessage("ARG_TYPE_MISSING", name);
}
else if (variableType.equals("any")) {
- bugs.add(new BugInfo.BugInfoBuilder().setLine(begLine).setMessageCode("ARG_TYPE_ANY")
- .setSeverity(severity).setFilename(context.getFilename())
- .setFunction(context.getFunctionName())
- .setMessage(ARGUMENT + name + " is any. Please change to be the correct type.")
- .setVariable(name)
- .build());
+ context.addMessage("ARG_TYPE_ANY", name);
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/cflint/plugins/core/ArgumentNameChecker.java b/src/main/java/com/cflint/plugins/core/ArgumentNameChecker.java
index 7975892a6..5bf42b73d 100644
--- a/src/main/java/com/cflint/plugins/core/ArgumentNameChecker.java
+++ b/src/main/java/com/cflint/plugins/core/ArgumentNameChecker.java
@@ -33,8 +33,15 @@ public void element(final Element element, final Context context, final BugList
if (element.getName().equals("cfargument")) {
final int lineNo = context.startLine();
final String name = element.getAttributeValue("name");
-
- checkNameForBugs(name, context.getFilename(), context.getFunctionName(), lineNo, bugs);
+ if(name != null && name.length() > 0) {
+ checkNameForBugs(name, context.getFilename(), context.getFunctionName(), lineNo, bugs);
+ } else {
+ bugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("ARGUMENT_INVALID_NAME")
+ .setSeverity("ERROR").setFilename(context.getFilename()).setFunction(context.getFunctionName())
+ .setMessage(ARGUMENT + " is missing a name.")
+ .setVariable("")
+ .build());
+ }
}
}
diff --git a/src/main/java/com/cflint/plugins/core/ArrayNewChecker.java b/src/main/java/com/cflint/plugins/core/ArrayNewChecker.java
index bd89b7ac4..9666ba01a 100644
--- a/src/main/java/com/cflint/plugins/core/ArrayNewChecker.java
+++ b/src/main/java/com/cflint/plugins/core/ArrayNewChecker.java
@@ -1,6 +1,5 @@
package com.cflint.plugins.core;
-import com.cflint.BugInfo;
import com.cflint.BugList;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;
@@ -12,16 +11,14 @@
@Extension
public class ArrayNewChecker extends CFLintScannerAdapter {
- final String severity = "INFO";
@Override
public void expression(final CFScriptStatement expression, final Context context, final BugList bugs) {
if (expression instanceof CFExpressionStatement) {
String code = ((CFExpressionStatement) expression).getExpression().Decompile(0);
- int lineNo = ((CFExpressionStatement) expression).getLine() + context.startLine() - 1;
if (code.toLowerCase().contains("arraynew(1)")) {
- arrayNew(lineNo, context, bugs);
+ context.addMessage("AVOID_USING_ARRAYNEW", null);
}
}
}
@@ -30,18 +27,11 @@ public void expression(final CFScriptStatement expression, final Context context
public void element(final Element element, final Context context, final BugList bugs) {
if (element.getName().equals("cfset")) {
String content = element.getStartTag().getTagContent().toString();
- int lineNo = element.getSource().getRow(element.getBegin());
if (content.toLowerCase().contains("arraynew(1)")) {
- arrayNew(lineNo, context, bugs);
+ context.addMessage("AVOID_USING_ARRAYNEW", null);
}
}
}
- protected void arrayNew(final int lineNo, final Context context, final BugList bugs) {
- bugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("AVOID_USING_ARRAYNEW")
- .setSeverity(severity).setFilename(context.getFilename())
- .setMessage("ArrayNew statement at line " + lineNo + ". Use implict array construction instead (= []).")
- .build());
- }
}
\ No newline at end of file
diff --git a/src/main/java/com/cflint/plugins/core/BooleanExpressionChecker.java b/src/main/java/com/cflint/plugins/core/BooleanExpressionChecker.java
index 4061815aa..ce01d659f 100644
--- a/src/main/java/com/cflint/plugins/core/BooleanExpressionChecker.java
+++ b/src/main/java/com/cflint/plugins/core/BooleanExpressionChecker.java
@@ -1,6 +1,5 @@
package com.cflint.plugins.core;
-import com.cflint.BugInfo;
import com.cflint.BugList;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;
@@ -9,10 +8,15 @@
import cfml.parsing.cfscript.CFExpression;
public class BooleanExpressionChecker extends CFLintScannerAdapter {
- final String severity = "INFO";
-
protected int lastLineNo = -1;
+ //Reset the last line number
+ @Override
+ public void startFile(String fileName, BugList bugs) {
+ super.startFile(fileName, bugs);
+ lastLineNo = -1;
+ }
+
@Override
public void expression(final CFExpression expression, final Context context, final BugList bugs) {
if (expression instanceof CFBinaryExpression) {
@@ -23,7 +27,7 @@ public void expression(final CFExpression expression, final Context context, fin
// Only report issue once per line
if (lastLineNo != lineNo) {
- booleanExpression(lineNo, context, bugs);
+ context.addMessage("EXPLICIT_BOOLEAN_CHECK", null);
lastLineNo = lineNo;
}
}
@@ -36,11 +40,4 @@ protected boolean hasExplicitBooleanCheck(final String code) {
|| code.contains("== false") || code.contains("eq false") || code.contains("is false") || code.contains("!= false");
}
- public void booleanExpression(final int lineNo, final Context context, final BugList bugs) {
- bugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("EXPLICIT_BOOLEAN_CHECK")
- .setSeverity(severity).setFilename(context.getFilename())
- .setMessage("Explicit check of boolean expession at " + lineNo + " is not needed.")
- .build());
- }
-
}
diff --git a/src/main/java/com/cflint/plugins/core/SimpleComplexityChecker.java b/src/main/java/com/cflint/plugins/core/SimpleComplexityChecker.java
index 74ce67283..6b786623f 100644
--- a/src/main/java/com/cflint/plugins/core/SimpleComplexityChecker.java
+++ b/src/main/java/com/cflint/plugins/core/SimpleComplexityChecker.java
@@ -33,6 +33,12 @@ public void expression(final CFScriptStatement expression, final Context context
functionLineNo = function.getLine();
complexity = 0;
alreadyTooComplex = false;
+ }
+ else if (expression == null){
+ bugs.add(new BugInfo.BugInfoBuilder().setLine(context.startLine()).setMessageCode("PARSE_NOTHING")
+ .setSeverity("WARNING").setFilename(context.getFilename()).setFunction(context.getFunctionName())
+ .setMessage("Nothing to parse")
+ .build());
}
// Not using instanceof to avoid double counting
else if (expression.getClass().equals(CFIfStatement.class) ||
diff --git a/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java b/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java
index 1ea0ee471..8126da893 100644
--- a/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java
+++ b/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java
@@ -1,12 +1,9 @@
package com.cflint.plugins.core;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
+import java.util.LinkedHashMap;
import java.util.Map;
-import com.cflint.BugInfo;
import com.cflint.BugList;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;
@@ -20,15 +17,16 @@
import net.htmlparser.jericho.Element;
public class UnusedArgumentChecker extends CFLintScannerAdapter {
- final String severity = "INFO";
- protected Map methodArguments = new HashMap();
+ //Use linked hash map to preserve the order of the elements.
+ protected Map methodArguments = new LinkedHashMap();
protected Map argumentLineNo = new HashMap();
@Override
public void element(final Element element, final Context context, final BugList bugs) {
if (element.getName().equals("cfargument")) {
- final String name = element.getAttributeValue("name").toLowerCase();
+ final String name = element.getAttributeValue("name") != null ?
+ element.getAttributeValue("name").toLowerCase() : "";
methodArguments.put(name, false);
setArgumentLineNo(name, context.startLine());
}
@@ -83,25 +81,13 @@ public void startFunction(Context context, BugList bugs) {
@Override
public void endFunction(Context context, BugList bugs) {
// sort by line number
- final List presortbugs = new ArrayList();
for (Map.Entry method : methodArguments.entrySet()) {
Boolean used = method.getValue();
if (!used) {
final String name = method.getKey();
- final Integer lineNo = argumentLineNo.get(name);
- presortbugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("UNUSED_METHOD_ARGUMENT")
- .setSeverity(severity).setFilename(context.getFilename())
- .setMessage("Argument " + name + " is not used in function " + context.getFunctionName() + ", consider removing it.")
- .setFunction(context.getFunctionName())
- .setVariable(name)
- .build());
+ context.addMessage("UNUSED_METHOD_ARGUMENT", name,argumentLineNo.get(name));
}
}
- // Sort the bugs by line/col before adding to the list of bugs.
- Collections.sort(presortbugs);
- for(BugInfo bugInfo : presortbugs ){
- bugs.add(bugInfo);
- }
}
}
diff --git a/src/main/java/com/cflint/plugins/core/WriteDumpChecker.java b/src/main/java/com/cflint/plugins/core/WriteDumpChecker.java
deleted file mode 100644
index 589ee7c3e..000000000
--- a/src/main/java/com/cflint/plugins/core/WriteDumpChecker.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.cflint.plugins.core;
-
-import com.cflint.BugInfo;
-import com.cflint.BugList;
-import com.cflint.plugins.CFLintScannerAdapter;
-import com.cflint.plugins.Context;
-
-import cfml.parsing.cfscript.CFExpression;
-import cfml.parsing.cfscript.CFFunctionExpression;
-import ro.fortsoft.pf4j.Extension;
-
-@Extension
-public class WriteDumpChecker extends CFLintScannerAdapter {
- final String severity = "INFO";
-
- @Override
- public void expression(final CFExpression expression, final Context context,
- final BugList bugs) {
-
- if(expression instanceof CFFunctionExpression){
- final CFFunctionExpression functionExpression = (CFFunctionExpression) expression;
- if(functionExpression.getFunctionName().equals("writeDump")){
- final int lineNo = functionExpression.getLine() + context.startLine() - 1;
- writeDump(lineNo, context, bugs);
- }
- }
-
- }
-
- protected void writeDump(final int lineNo, final Context context, final BugList bugs) {
- bugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("AVOID_USING_WRITEDUMP")
- .setSeverity(severity).setFilename(context.getFilename())
- .setMessage("WriteDump statement at line " + lineNo + ". Avoid using writeDump in production code.")
- .build());
- }
-}
\ No newline at end of file
diff --git a/src/main/resources/cflint.definition.json b/src/main/resources/cflint.definition.json
index 6f71180d6..7fb749732 100644
--- a/src/main/resources/cflint.definition.json
+++ b/src/main/resources/cflint.definition.json
@@ -184,7 +184,8 @@
"message": [
{
"code": "AVOID_USING_ABORT",
- "severity": "INFO"
+ "severity": "INFO",
+ "messageText" : "Avoid using abort in production code."
}
],
"parameter": [
@@ -295,7 +296,8 @@
"message": [
{
"code": "ARG_HINT_MISSING",
- "severity": "INFO"
+ "severity": "INFO",
+ "messageText" : "Argument ${variable} is missing a hint."
}
],
"parameter": [
@@ -308,11 +310,13 @@
"message": [
{
"code": "ARG_TYPE_MISSING",
- "severity": "WARNING"
+ "severity": "WARNING",
+ "messageText": "ARGUMENT ${variable} is missing a type."
},
{
"code": "ARG_TYPE_ANY",
- "severity": "INFO"
+ "severity": "WARNING",
+ "messageText": "Argument ${variable} is any. Please change to be the correct type."
}
],
"parameter": [
@@ -418,7 +422,7 @@
},
{
"name": "WriteDumpChecker",
- "className": "WriteDumpChecker",
+ "className": "FunctionXChecker",
"message": [
{
"code": "AVOID_USING_WRITEDUMP",
@@ -472,6 +476,7 @@
"className": "ArrayNewChecker",
"message": [
{
+ "messageText": "Use implict array construction instead (= []).",
"code": "AVOID_USING_ARRAYNEW",
"severity": "INFO"
}
@@ -494,6 +499,7 @@
"className": "BooleanExpressionChecker",
"message": [
{
+ "messageText" : "Explicit check of boolean expession is not needed.",
"code": "EXPLICIT_BOOLEAN_CHECK",
"severity": "INFO"
}
@@ -766,6 +772,7 @@
"message": [
{
"code": "UNUSED_METHOD_ARGUMENT",
+ "messageText": "Argument ${variable} is not used in function, consider removing it.",
"severity": "INFO"
}
],
diff --git a/src/main/resources/cflint.definition.xml b/src/main/resources/cflint.definition.xml
index 0ae90b857..a80de8123 100644
--- a/src/main/resources/cflint.definition.xml
+++ b/src/main/resources/cflint.definition.xml
@@ -83,13 +83,14 @@
Avoid Leaving <${tagName}> tags in committed code. Did you accidently leave a cfabort in the code?
- INFO
+ WARNING
- INFO
+ WARNING
+ Avoid using abort in production code.
@@ -133,14 +134,17 @@
+ Argument ${variable} is missing a hint.
INFO
+ ARGUMENT ${variable} is missing a type.
WARNING
+ Argument ${variable} is any. Please change to be the correct type.
INFO
@@ -205,6 +209,7 @@
+ Use implict array construction instead (= []).
INFO
@@ -215,6 +220,7 @@
+ Explicit check of boolean expession is not needed.
INFO
@@ -349,6 +355,7 @@
INFO
+ Argument ${variable} is not used in function, consider removing it.
diff --git a/src/test/java/com/cflint/TestArrayNewChecker.java b/src/test/java/com/cflint/TestArrayNewChecker.java
index c4a6845e1..0c054e87b 100644
--- a/src/test/java/com/cflint/TestArrayNewChecker.java
+++ b/src/test/java/com/cflint/TestArrayNewChecker.java
@@ -27,6 +27,8 @@ public void setUp() {
conf.getRules().add(pluginRule);
final PluginMessage pluginMessage = new PluginMessage("AVOID_USING_ARRAYNEW");
pluginMessage.setSeverity("INFO");
+ pluginMessage.setMessageText("Use implict array construction instead (= []).");
+ pluginRule.getMessages().add(pluginMessage);
cfBugs = new CFLint(conf, new ArrayNewChecker());
}
@@ -42,6 +44,8 @@ public void testArrayNewInScript() throws ParseException, IOException {
assertEquals(1, result.size());
assertEquals("AVOID_USING_ARRAYNEW", result.get(0).getMessageCode());
assertEquals(3, result.get(0).getLine());
+ assertEquals("INFO", result.get(0).getSeverity());
+ assertEquals("Use implict array construction instead (= []).", result.get(0).getMessage());
}
@Test
@@ -65,6 +69,8 @@ public void testArrayNewInTag() throws ParseException, IOException {
assertEquals(1, result.size());
assertEquals("AVOID_USING_ARRAYNEW", result.get(0).getMessageCode());
assertEquals(2, result.get(0).getLine());
+ assertEquals("INFO", result.get(0).getSeverity());
+ assertEquals("Use implict array construction instead (= []).", result.get(0).getMessage());
}
}
diff --git a/src/test/java/com/cflint/TestBooleanExpressionChecker.java b/src/test/java/com/cflint/TestBooleanExpressionChecker.java
index fc661c0b0..e2916e40a 100644
--- a/src/test/java/com/cflint/TestBooleanExpressionChecker.java
+++ b/src/test/java/com/cflint/TestBooleanExpressionChecker.java
@@ -27,6 +27,8 @@ public void setUp() {
conf.getRules().add(pluginRule);
final PluginMessage pluginMessage = new PluginMessage("EXPLICIT_BOOLEAN_CHECK");
pluginMessage.setSeverity("INFO");
+ pluginMessage.setMessageText("Explicit check of boolean expession is not needed.");
+ pluginRule.getMessages().add(pluginMessage);
cfBugs = new CFLint(conf, new BooleanExpressionChecker());
}
diff --git a/src/test/java/com/cflint/TestCFBugs_ArgsType.java b/src/test/java/com/cflint/TestCFBugs_ArgsType.java
index c494f565c..baddc8862 100644
--- a/src/test/java/com/cflint/TestCFBugs_ArgsType.java
+++ b/src/test/java/com/cflint/TestCFBugs_ArgsType.java
@@ -27,11 +27,11 @@ public void setUp() {
conf.getRules().add(pluginRule);
final PluginMessage pluginMessageMissing = new PluginMessage("ARG_TYPE_MISSING");
pluginMessageMissing.setSeverity("WARNING");
- pluginMessageMissing.setMessageText("Argument ${variable} is missing a hint.");
+ pluginMessageMissing.setMessageText("Argument ${variable} is missing a type.");
pluginRule.getMessages().add(pluginMessageMissing);
final PluginMessage pluginMessageAny = new PluginMessage("ARG_TYPE_ANY");
- pluginMessageAny.setSeverity("INFO");
- pluginMessageAny.setMessageText("Argument ${variable} is any, please use correct type.");
+ pluginMessageAny.setSeverity("WARNING");
+ pluginMessageAny.setMessageText("Argument ${variable} is any. Please change to be the correct type.");
pluginRule.getMessages().add(pluginMessageAny);
cfBugs = new CFLint(conf, new ArgTypeChecker());
@@ -49,6 +49,8 @@ public void testMissingType() throws ParseException, IOException {
assertEquals(1, result.size());
assertEquals("ARG_TYPE_MISSING", result.get(0).getMessageCode());
assertEquals(3, result.get(0).getLine());
+ assertEquals("WARNING", result.get(0).getSeverity());
+ assertEquals("Argument xyz is missing a type.", result.get(0).getMessage());
}
@Test
@@ -62,6 +64,8 @@ public void testMissingTypeNoTags() throws ParseException, IOException {
assertEquals(1, result.size());
assertEquals("ARG_TYPE_MISSING", result.get(0).getMessageCode());
assertEquals(2, result.get(0).getLine());
+ assertEquals("WARNING", result.get(0).getSeverity());
+ assertEquals("Argument arg1 is missing a type.", result.get(0).getMessage());
}
@Test
@@ -76,6 +80,8 @@ public void testTypeAny() throws ParseException, IOException {
assertEquals(1, result.size());
assertEquals("ARG_TYPE_ANY", result.get(0).getMessageCode());
assertEquals(3, result.get(0).getLine());
+ assertEquals("WARNING", result.get(0).getSeverity());
+ assertEquals("Argument xyz is any. Please change to be the correct type.", result.get(0).getMessage());
}
@Test
@@ -89,6 +95,8 @@ public void testTypeAnyNoTags() throws ParseException, IOException {
assertEquals(1, result.size());
assertEquals("ARG_TYPE_ANY", result.get(0).getMessageCode());
assertEquals(2, result.get(0).getLine());
+ assertEquals("WARNING", result.get(0).getSeverity());
+ assertEquals("Argument arg1 is any. Please change to be the correct type.", result.get(0).getMessage());
}
}
diff --git a/src/test/java/com/cflint/TestCFBugs_ParseError.java b/src/test/java/com/cflint/TestCFBugs_ParseError.java
index 0f4008c2a..80374bfab 100644
--- a/src/test/java/com/cflint/TestCFBugs_ParseError.java
+++ b/src/test/java/com/cflint/TestCFBugs_ParseError.java
@@ -33,11 +33,9 @@ public void testSimpleCFSET() throws ParseException, IOException{
"\r\n" +
"";
cfBugs.process(cfcSrc,"test");
- List result = cfBugs.getBugs().getBugList().values().iterator().next();
+ List result = cfBugs.getBugs().getFlatBugList();
System.out.println(result);
- assertEquals(1,result.size());
- assertEquals("PARSE_ERROR",result.get(0).getMessageCode());
- assertEquals(4,result.get(0).getLine());
+ assertEquals(0,result.size());
}
@Test
diff --git a/src/test/java/com/cflint/TestUnusedArgumentChecker.java b/src/test/java/com/cflint/TestUnusedArgumentChecker.java
index 8c2fc18b1..4aca325dd 100644
--- a/src/test/java/com/cflint/TestUnusedArgumentChecker.java
+++ b/src/test/java/com/cflint/TestUnusedArgumentChecker.java
@@ -28,6 +28,7 @@ public void setUp() {
conf.getRules().add(pluginRule);
final PluginMessage pluginMessage = new PluginMessage("UNUSED_METHOD_ARGUMENT");
pluginMessage.setSeverity("INFO");
+ pluginRule.getMessages().add(pluginMessage);
cfBugs = new CFLint(conf, new UnusedArgumentChecker());
}
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 3e871b878..605828ecb 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
@@ -10,8 +10,8 @@
"function" : "helloWorld",
"column" : "0",
"line" : "6",
- "message" : "Argument xyzzy is not used in function helloWorld, consider removing it.",
+ "message" : "Argument xyzzy is not used in function, consider removing it.",
"variable" : "xyzzy",
- "expression" : ""
+ "expression" : "/r/n /r/n
\ No newline at end of file
diff --git a/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.cfc b/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.cfc
new file mode 100644
index 000000000..65581d502
--- /dev/null
+++ b/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.cfc
@@ -0,0 +1,9 @@
+
+
+
+
+
+ writeDump(name);
+
+
+
\ No newline at end of file
diff --git a/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.expected.txt b/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.expected.txt
new file mode 100644
index 000000000..1b38f5de1
--- /dev/null
+++ b/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.expected.txt
@@ -0,0 +1,17 @@
+[ {
+ "severity" : "INFO",
+ "id" : "AVOID_USING_WRITEDUMP",
+ "message" : "AVOID_USING_WRITEDUMP",
+ "category" : "CFLINT",
+ "abbrev" : "AU",
+ "locations" : [ {
+ "file" : "src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.cfc",
+ "fileName" : "writeDump.cfc",
+ "function" : "helloWorld",
+ "column" : "7",
+ "line" : "6",
+ "message" : "Avoid using the writeDump function in production code.",
+ "variable" : "writeDump",
+ "expression" : "writeDump(name)"
+ } ]
+} ]
\ No newline at end of file