diff --git a/src/main/java/com/cflint/CFLint.java b/src/main/java/com/cflint/CFLint.java index 262ed4497..b27e30e07 100644 --- a/src/main/java/com/cflint/CFLint.java +++ b/src/main/java/com/cflint/CFLint.java @@ -89,6 +89,7 @@ import cfml.parsing.cfscript.script.CFScriptStatement; import cfml.parsing.cfscript.script.CFSwitchStatement; import cfml.parsing.cfscript.script.CFTryCatchStatement; +import cfml.parsing.cfscript.script.CFWhileStatement; import cfml.parsing.reporting.ArrayErrorListener; import cfml.parsing.reporting.IErrorReporter; import cfml.parsing.reporting.ParseException; @@ -812,6 +813,10 @@ private void process(final CFScriptStatement expression, final Context context) process(((CFForStatement) expression).getCond(), elem, context); process(((CFForStatement) expression).getNext(), elem, context); process(((CFForStatement) expression).getBody(), context); + } else if (expression instanceof CFWhileStatement) { + scanExpression(expression, context, elem); + process(((CFWhileStatement) expression).getCond(), elem, context); + process(((CFWhileStatement) expression).getBody(), context); } else if (expression instanceof CFForInStatement) { scanExpression(expression, context, elem); final Context forInitContext = context.subContext(elem); diff --git a/src/test/resources/com/cflint/tests/UnusedVariable/while_465.cfc b/src/test/resources/com/cflint/tests/UnusedVariable/while_465.cfc new file mode 100644 index 000000000..2bd06e46a --- /dev/null +++ b/src/test/resources/com/cflint/tests/UnusedVariable/while_465.cfc @@ -0,0 +1,17 @@ +component{ +function safetext(text) { + var obracket = find("<",theText); + var badTag = ""; + var nextStart = ""; + while(obracket){ + badTag = REFindNoCase(); + if(badTag.pos[1]){ + nextStart = badTag.pos[1] + badTag.len[1]; + } + else{ + nextStart = obracket + 1; + } + } + } +} +} \ No newline at end of file diff --git a/src/test/resources/com/cflint/tests/UnusedVariable/while_465.expected.txt b/src/test/resources/com/cflint/tests/UnusedVariable/while_465.expected.txt new file mode 100644 index 000000000..b579778d5 --- /dev/null +++ b/src/test/resources/com/cflint/tests/UnusedVariable/while_465.expected.txt @@ -0,0 +1,65 @@ +{ + "version" : "", + "timestamp" : 1513779574, + "issues" : [ { + "severity" : "INFO", + "id" : "UNUSED_LOCAL_VARIABLE", + "message" : "UNUSED_LOCAL_VARIABLE", + "category" : "CFLINT", + "abbrev" : "UL", + "locations" : [ { + "file" : "src\\test\\resources\\com\\cflint\\tests\\UnusedVariable\\while_465.cfc", + "fileName" : "while_465.cfc", + "function" : "safetext", + "column" : 8, + "line" : 3, + "message" : "Local variable obracket is not used in function safetext, consider removing it.", + "variable" : "obracket", + "expression" : "" + } ] + }, { + "severity" : "INFO", + "id" : "UNUSED_LOCAL_VARIABLE", + "message" : "UNUSED_LOCAL_VARIABLE", + "category" : "CFLINT", + "abbrev" : "UL", + "locations" : [ { + "file" : "src\\test\\resources\\com\\cflint\\tests\\UnusedVariable\\while_465.cfc", + "fileName" : "while_465.cfc", + "function" : "safetext", + "column" : 8, + "line" : 4, + "message" : "Local variable badTag is not used in function safetext, consider removing it.", + "variable" : "badTag", + "expression" : "" + } ] + }, { + "severity" : "INFO", + "id" : "UNUSED_LOCAL_VARIABLE", + "message" : "UNUSED_LOCAL_VARIABLE", + "category" : "CFLINT", + "abbrev" : "UL", + "locations" : [ { + "file" : "src\\test\\resources\\com\\cflint\\tests\\UnusedVariable\\while_465.cfc", + "fileName" : "while_465.cfc", + "function" : "safetext", + "column" : 8, + "line" : 5, + "message" : "Local variable nextStart is not used in function safetext, consider removing it.", + "variable" : "nextStart", + "expression" : "" + } ] + } ], + "counts" : { + "totalFiles" : 0, + "totalLines" : 0, + "countByCode" : [ { + "code" : "UNUSED_LOCAL_VARIABLE", + "count" : 3 + } ], + "countBySeverity" : [ { + "severity" : "INFO", + "count" : 3 + } ] + } +} \ No newline at end of file