CFLint icon indicating copy to clipboard operation
CFLint copied to clipboard

UNUSED_LOCAL_VARIABLE incompatible with cfquery

Open jaredbeck opened this issue 5 years ago • 5 comments

EDIT: better example below

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

jaredbeck avatar Oct 02 '20 16:10 jaredbeck

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 avatar Oct 02 '20 16:10 jaredbeck

For comparison, the following passes:

    <cfset var x = 0>
    <cfloop list="a,b,c" index="x">

jaredbeck avatar Oct 02 '20 16:10 jaredbeck

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 avatar Oct 02 '20 17:10 jaredbeck

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.

jaredbeck avatar Oct 02 '20 17:10 jaredbeck

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' ){ ..... };

CreativeNotice avatar Dec 31 '20 06:12 CreativeNotice