rokucommunity / bslint

A linter for BrightScript and BrighterScript.
MIT License
28 stars 14 forks source link

Variable set at the end of a loop gets flagged as unused #47

Open chrisdp opened 2 years ago

chrisdp commented 2 years ago
function convertKeyValueArrayToBase64(keyValueArray as Object) as String
    binaryByte = ""
    ba = createObject("roByteArray")
    topIndex = getLastIndex(keyValueArray)
    for i = 0 to topIndex
        item = keyValueArray[i]
        if getBooleanAtKeyPath(item, "value") then
            binaryByte = binaryByte + "1"
        else
            binaryByte = binaryByte + "0"
        end if

        if i = topIndex then
            ' NOTE!!! THIS is opposite of updateKeyValueArrayFromBase64String() on purpose
            binaryByte = binaryByte + string(8 - binaryByte.len(), "0")
        end if

        if binaryByte.len() = 8 OR i = topIndex then
            ba.push(val(binaryByte, 2))
            binaryByte = ""
        end if
    end for
    base64String = ba.toBase64String()

    return base64String
end function

In the above function the binaryByte = "" near the end of the loop is getting flagged with the following:

image

The same thing can be see in this code with focusedChild in the while loop

function getCurrentFocusedNode(parent = Invalid as Object, maxDepth = 30 as Integer) as Dynamic
    if isNode(parent) then
        node = parent
    else
        node = getScene()
    end if

    focusedChild = node.focusedChild

    if isNode(focusedChild) then
        while maxDepth > 0 AND focusedChild <> Invalid AND NOT node.isSameNode(focusedChild)
            node = focusedChild
            focusedChild = node.focusedChild
            maxDepth--
        end while

        return node
    end if

    return Invalid
end function

image

elsassph commented 2 years ago

Same within a goto loop.