CFLint icon indicating copy to clipboard operation
CFLint copied to clipboard

UNUSED_LOCAL_VARIABLE false positive with var used in closure function

Open timbeadle opened this issue 7 years ago • 2 comments

var address = variables.addressService.getAddressById(
	addressId = billingAddressId
);

addressColumns.each(function (addressColumn) {
	variables['billing' & addressColumn] = address.find(addressColumn, '');
});

[cflint] UNUSED_LOCAL_VARIABLE: Local variable address is not used in function getBillingAddress. Consider removing it.

address (has to be referenced in an unscoped way, as local would be the closure's local scope) is used in the closure function of the Array.each() call.

timbeadle avatar Jan 05 '18 10:01 timbeadle

Same applies for UNUSED_METHOD_ARGUMENT

KamasamaK avatar Oct 09 '18 21:10 KamasamaK

I can reproduce this bug in version 1.4.1. Here's another example:

private array function groupings(){
  var spr = super;
  return memoize('2d_demo_groupings', function(){
      var gs = spr.groupings();
      // ...
Message code:UNUSED_LOCAL_VARIABLE
        File:/Users/jared/redacted/redacted.cfc
        Column:6
        Line:38
                Message:Local variable spr is not used in function groupings. Consider removing it.
                Variable:'spr' in function: groupings
                Expression:null

jaredbeck avatar Jul 19 '19 20:07 jaredbeck