everyday-as / pivity-issues

The GmodStore issue tracker
https://gmodstore.com
8 stars 0 forks source link

Incorrect Global Function Definition Detection for Localized Functions within do Blocks #1310

Open filipovskis opened 3 months ago

filipovskis commented 3 months ago

Expected Behavior

It should not declare localized variables as global ones.

Actual Behavior

The code report detects an issue in actually localized variable, which it defines as a global one. The code report ignores if you prior localized the variable name. I actually do not know if it is a global issue related to localizing prior or just related to do blocks.

It returns an issue called: _Global function definitions are prohibited. Namespace them inside your addon's global table_.

Example:

local split do
    local len = string.len
    local sub = string.sub
    local maxBytes = netchunk.maxBytes

    function split(data)
        local length = len(data)
        local index = 1
        local last = 1
        local chunks = {}

        for i = 1, length do
            if (i - last + 1) > maxBytes then
                chunks[index] = sub(data, last, i)
                index = index + 1
                last = i + 1
            end
        end

        chunks[index] = sub(data, last, length)

        return chunks
    end
end

Result:

Image

Reproduction Steps

1. Paste somewhere in the code the example above.
2. Run code report.
3. Check the issues.

Browsers

Vivaldi

Example URL

https://www.gmodstore.com/dashboard/products/onyx-scoreboard-a-modern-scoreboard/code-reports/rkhUPOF8QBqvkzAf40Ew7g

Pivity Marketplace Version

v18.4.0

Event ID

No response

Additional Information

No response

Indecisiv3 commented 3 months ago

Yeah, would be amazing if this could be fixed same thing happened with one of my submissions.