Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneberly committed Jul 18, 2017
1 parent 24538ba commit 8bfefb9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/main/java/com/cflint/plugins/core/UnusedLocalVarChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cfml.parsing.cfscript.CFIdentifier;
import cfml.parsing.cfscript.CFMember;
import cfml.parsing.cfscript.CFVarDeclExpression;
import net.htmlparser.jericho.Element;

public class UnusedLocalVarChecker extends CFLintScannerAdapter {
final String severity = "INFO";
Expand All @@ -23,7 +24,6 @@ public class UnusedLocalVarChecker extends CFLintScannerAdapter {

@Override
public void expression(final CFExpression expression, final Context context, final BugList bugs) {
System.out.println("::" + expression.Decompile(0));
if (expression instanceof CFFullVarExpression) {
final CFFullVarExpression fullVarExpression = (CFFullVarExpression) expression;
final CFExpression variable = fullVarExpression.getExpressions().get(0);
Expand Down Expand Up @@ -99,4 +99,29 @@ public VarInfo(String name, Boolean used){
this.used=used;
}
}

@Override
public void element(final Element element, final Context context, final BugList bugs) {
//cfquery/@name usage is enough
if(element.getName()!= null && "cfquery".equals(element.getName().toLowerCase())){
final String name = element.getAttributeValue("name");
if(name!= null && localVariables.containsKey(name.toLowerCase())){
localVariables.put(name.toLowerCase(), new VarInfo(name, true));
}
}
//cfloop/@index usage is enough
if(element.getName()!= null && "cfloop".equals(element.getName().toLowerCase())){
final String name = element.getAttributeValue("index");
if(name!= null && localVariables.containsKey(name.toLowerCase())){
localVariables.put(name.toLowerCase(), new VarInfo(name, true));
}
}
//cfloop/@item usage is enough
if(element.getName()!= null && "cfloop".equals(element.getName().toLowerCase())){
final String name = element.getAttributeValue("item");
if(name!= null && localVariables.containsKey(name.toLowerCase())){
localVariables.put(name.toLowerCase(), new VarInfo(name, true));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<cfcomponent>
<cffunction name="foo">
<cfset var iIdx = "">
<cfloop list="#arguments.lID#" index="iIdx">...</cfloop>
<cfset var ifolder = 0>
<cfloop collection="#attributes.foldermapping#" item="ifolder">...</cfloop>
</cffunction>
</cfcomponent>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[ {
"totalfiles" : 0
}, {
"totalsize" : 0
} ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<cfcomponent>
<cffunction name="foo">
<cfset var qWork = "">
<cfquery name="qWork" datasource="#variables.sPublishDataSource#">
</cfquery>
</cffunction>
</cfcomponent>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[ {
"totalfiles" : 0
}, {
"totalsize" : 0
} ]

0 comments on commit 8bfefb9

Please sign in to comment.