Skip to content

Commit

Permalink
Added more tags and attributes to check in VarScoper (#495)
Browse files Browse the repository at this point in the history
* Added more tags and attributes to check in VarScoper

* Corrected tests
  • Loading branch information
KamasamaK authored and ryaneberly committed Dec 20, 2017
1 parent 1665aa6 commit b7091f0
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 29 deletions.
33 changes: 31 additions & 2 deletions src/main/java/com/cflint/CF.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class CF {
*/
public static final String CFCATCH = "cfcatch";

/**
* CFChart tag.
*/
public static final String CFCHART = "cfchart";

/**
* CFCollection tag.
*/
Expand Down Expand Up @@ -90,6 +95,11 @@ public class CF {
*/
public static final String CFFUNCTION = "cffunction";

/**
* CFHTMLToPDF Tag.
*/
public static final String CFHTMLTOPDF = "cfhtmltopdf";

/**
* CFHTTP Tag.
*/
Expand All @@ -100,6 +110,16 @@ public class CF {
*/
public static final String CFIF = "cfif";

/**
* CFImage Tag.
*/
public static final String CFIMAGE = "cfimage";

/**
* CFIMAP Tag.
*/
public static final String CFIMAP = "cfimap";

/**
* CFInclude Tag.
*/
Expand Down Expand Up @@ -210,6 +230,16 @@ public class CF {
*/
public static final String CFSETTING = "cfsetting";

/**
* CFSharepoint Tag.
*/
public static final String CFSHAREPOINT = "cfsharepoint";

/**
* CFSpreadsheet Tag.
*/
public static final String CFSPREADSHEET = "cfspreadsheet";

/**
* CFStoredProc Tag.
*/
Expand Down Expand Up @@ -260,7 +290,6 @@ public class CF {
*/
public static final String STRUCT = "struct";


/**
* CFScript dbtype.
*/
Expand Down Expand Up @@ -401,7 +430,7 @@ public class CF {
* CF scope variables.
*/
public static final String VARIABLES = "variables";

/**
* CF scope local.
*/
Expand Down
29 changes: 18 additions & 11 deletions src/main/java/com/cflint/plugins/core/VarScoper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ public class VarScoper extends CFLintScannerAdapter {

public static final String VARIABLE = "variable";
public static final String RESULT = "result";
public static final String STRUCTNAME = "structname";

private final Map<String, List<String>> checkElementAttributes = new HashMap<>();
private final List<String> checkNames = Arrays.asList(CF.CFQUERY, CF.CFSTOREDPROC, CF.CFFEED, CF.CFDIRECTORY,
private final List<String> checkNames = Arrays.asList(CF.CFQUERY, CF.CFFEED, CF.CFDIRECTORY,
CF.CFFORM, CF.CFFTP, CF.CFOBJECT, CF.CFSEARCH, CF.CFPROCRESULT, CF.CFPOP, CF.CFREGISTRY, CF.CFREPORT,
CF.CFDBINFO, CF.CFDOCUMENT, CF.CFCOLLECTION, CF.CFPDF, CF.CFZIP, CF.CFLDAP);
CF.CFDBINFO, CF.CFDOCUMENT, CF.CFCOLLECTION, CF.CFPDF, CF.CFZIP, CF.CFLDAP, CF.CFHTTP, CF.CFCHART,
CF.CFHTMLTOPDF, CF.CFIMAGE, CF.CFIMAP, CF.CFSHAREPOINT, CF.CFSPREADSHEET);
private final Collection<String> scopes = Arrays.asList(CF.APPLICATION, CF.CGI, CF.COOKIE, CF.FORM, CF.REQUEST,
CF.SERVER, CF.SESSION, CF.URL);

Expand Down Expand Up @@ -60,19 +62,24 @@ public void expression(final CFScriptStatement expression, final Context context
}

public VarScoper() {
// checkElementAttributes.put(CF.CFLOOP, Arrays.asList(CF.index, CF.ITEM));
checkElementAttributes.put(CF.CFINVOKE, Arrays.asList(CF.RETURNVARIABLE));
checkElementAttributes.put(CF.CFFILE, Arrays.asList(VARIABLE));
checkElementAttributes.put(CF.CFSAVECONTENT, Arrays.asList(VARIABLE));
checkElementAttributes.put(CF.CFEXECUTE, Arrays.asList(VARIABLE));
checkElementAttributes.put(CF.CFFEED, Arrays.asList(CF.QUERY));
checkElementAttributes.put(CF.CFFILE, Arrays.asList(VARIABLE, RESULT));
checkElementAttributes.put(CF.CFFTP, Arrays.asList(RESULT));
checkElementAttributes.put(CF.CFHTTP, Arrays.asList(RESULT));
checkElementAttributes.put(CF.CFIMAGE, Arrays.asList(STRUCTNAME));
checkElementAttributes.put(CF.CFINVOKE, Arrays.asList(CF.RETURNVARIABLE));
checkElementAttributes.put(CF.CFLOOP, Arrays.asList(CF.INDEX, CF.ITEM));
checkElementAttributes.put(CF.CFNTAUTHENTICATE, Arrays.asList(RESULT));
checkElementAttributes.put(CF.CFPROCPARAM, Arrays.asList(VARIABLE));
checkElementAttributes.put(CF.CFQUERY, Arrays.asList(RESULT));
checkElementAttributes.put(CF.CFMAIL, Arrays.asList(CF.QUERY));
checkElementAttributes.put(CF.CFFTP, Arrays.asList(RESULT));
checkElementAttributes.put(CF.CFREGISTRY, Arrays.asList(VARIABLE));
checkElementAttributes.put(CF.CFSAVECONTENT, Arrays.asList(VARIABLE));
checkElementAttributes.put(CF.CFSPREADSHEET, Arrays.asList(CF.QUERY));
checkElementAttributes.put(CF.CFSTOREDPROC, Arrays.asList(RESULT));
checkElementAttributes.put(CF.CFWDDX, Arrays.asList(CF.OUTPUT));
checkElementAttributes.put(CF.CFEXECUTE, Arrays.asList(VARIABLE));
checkElementAttributes.put(CF.CFNTAUTHENTICATE, Arrays.asList(RESULT));
checkElementAttributes.put(CF.CFXML, Arrays.asList(VARIABLE));

checkElementAttributes.put(CF.CFZIP, Arrays.asList(VARIABLE));
}

@Override
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/com/cflint/TestCFBugs_VarScoper_Names.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.cflint;

/**
* tests from
* tests from
* https://github.com/mschierberl/varscoper/blob/master/varScoper.cfc
*
*
*/
import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -37,12 +37,14 @@ public void setUp() throws CFLintConfigurationException {
@Parameterized.Parameters(name = "{0}")
public static Collection<?> primeNumbers() {
return Arrays.asList(
new String[][] { new String[] { "CFStoredProc" }, new String[] { "CFQuery" }, new String[] { "CFFeed" },
new String[][] { new String[] { "CFQuery" }, new String[] { "CFFeed" }, new String[] { "CFHttp" },
new String[] { "CFDirectory" }, new String[] { "CFForm" }, new String[] { "CFFtp" },
new String[] { "CFObject" }, new String[] { "CFSearch" }, new String[] { "CFProcResult" },
new String[] { "CFPop" }, new String[] { "CFRegistry" }, new String[] { "CFReport" },
new String[] { "CFDBInfo" }, new String[] { "CFDocument" }, new String[] { "CFCollection" },
new String[] { "CFPdf" }, new String[] { "CFZip" }, new String[] { "CFLdap" } });
new String[] { "CFPdf" }, new String[] { "CFZip" }, new String[] { "CFLdap" },
new String[] { "CFChart" }, new String[] { "CFHtmlToPdf" }, new String[] { "CFImage" },
new String[] { "CFImap" }, new String[] { "CFSharepoint" }, new String[] { "CFSpreadsheet" } });
}

public TestCFBugs_VarScoper_Names(final String tagName) {
Expand Down
27 changes: 17 additions & 10 deletions src/test/java/com/cflint/TestCFBugs_VarScoper_TagAttr.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.cflint;

/**
* tests from
* tests from
* https://github.com/mschierberl/varscoper/blob/master/varScoper.cfc
*
*
*/
import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -39,19 +39,26 @@ public void setUp() throws CFLintConfigurationException {
@Parameterized.Parameters(name = "{0}")
public static Collection<String[]> primeNumbers() {
List<String[]> retval = new ArrayList<String[]>();
// retval.add(new String[] { "CFLoop", "Index" });
// retval.add(new String[] { "CFLoop", "Item" });
retval.add(new String[] { "CFInvoke", "ReturnVariable" });
retval.add(new String[] { "CFExecute", "Variable" });
retval.add(new String[] { "CFFeed", "Query" });
retval.add(new String[] { "CFFile", "Variable" });
retval.add(new String[] { "CFSavecontent", "Variable" });
retval.add(new String[] { "CFFile", "Result" });
retval.add(new String[] { "CFFtp", "Result" });
retval.add(new String[] { "CFHttp", "Result" });
retval.add(new String[] { "CFImage", "StructName" });
retval.add(new String[] { "CFInvoke", "ReturnVariable" });
retval.add(new String[] { "CFLoop", "Index" });
retval.add(new String[] { "CFLoop", "Item" });
retval.add(new String[] { "CFNtAuthenticate", "Result" });
retval.add(new String[] { "CFProcParam", "Variable" });
retval.add(new String[] { "CFQuery", "Result" });
retval.add(new String[] { "CFMail", "Query" });
retval.add(new String[] { "CFFtp", "Result" });
retval.add(new String[] { "CFRegistry", "Variable" });
retval.add(new String[] { "CFSavecontent", "Variable" });
retval.add(new String[] { "CFSpreadsheet", "Query" });
retval.add(new String[] { "CFStoredProc", "Result" });
retval.add(new String[] { "CFWddx", "Output" });
retval.add(new String[] { "CFExecute", "Variable" });
retval.add(new String[] { "CFNtAuthenticate", "Result" });
retval.add(new String[] { "CFXml", "Variable" });
retval.add(new String[] { "CFZip", "Variable" });
return retval;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"file" : "src\\test\\resources\\com\\cflint\\tests\\VarScoper\\cfloop_index_413.cfc",
"fileName" : "cfloop_index_413.cfc",
"function" : "foo",
"column" : 2,
"column" : 33,
"line" : 2,
"message" : "Variable idx is not declared with a var statement.",
"variable" : "idx",
"expression" : "idx"
"expression" : "<cfloop from=\"0\" to=\"23\" index=\"idx\">\r\n\t\t<cfset xxx = NumberFormat(idx, \"00\")>\r\n\t</cfloop>"
} ]
}, {
"severity" : "ERROR",
Expand Down

0 comments on commit b7091f0

Please sign in to comment.