cflint / CFLint

Static code analysis for CFML (a linter)
BSD 3-Clause "New" or "Revised" License
174 stars 84 forks source link

UNUSED_LOCAL_VARIABLE incompatible with cfquery #693

Open jaredbeck opened 4 years ago

jaredbeck commented 4 years ago

EDIT: better example below

Possibly related to https://github.com/cflint/CFLint/issues/657

jaredbeck commented 4 years ago

A more complete example:

<cffunction name="f">
  <cfquery>
    <cfloop list="a,b,c" index="local.x">
      #x#
    </cfloop>
  </cfquery>
</cffunction>
Message code:UNUSED_LOCAL_VARIABLE
    File:redacted.cfm
    Column:11
    Line:3
        Message:Local variable x is not used in function f. Consider removing it.
        Variable:'x' in function: f
        Expression:x
jaredbeck commented 4 years ago

For comparison, the following passes:

    <cfset var x = 0>
    <cfloop list="a,b,c" index="x">
jaredbeck commented 4 years ago

To further simplify the example:

<cffunction name="f">
  <cfset var x = 0>
  <cfquery datasource="#request.app_datasource#">
    #x#
  </cfquery>
</cffunction>

It seems that using a variable in cfquery is not recognized.

jaredbeck commented 4 years ago

This issue is very similar to https://github.com/cflint/CFLint/issues/632. If it's helpful to you to combine them, @ryaneberly, please feel free to.

CreativeNotice commented 3 years ago

Can confirm this happens when in script syntax as well. In this example, header will trigger the rule.

for( var header in requestHeaders ){
    cfhttpparam( type = 'header', name = header.name, value = header.value );
}

Also ocures when using cfhttp().

var fullURL = 'https://www.google.com/';
cfhttp( URL = fullURL, result = 'myResult' ){ ..... };