selene icon indicating copy to clipboard operation
selene copied to clipboard

Add Roact dangling connection lint

Open chriscerie opened this issue 2 years ago • 2 comments

Closes #383. This only errors when the file has Roact or React defined and when the connection is made within useEffect. In the future if we can reliably detect components vs regular functions we can also warn about dangling connections during render.

a:Connect()

local function a()
    b:Connect()

    useEffect(function()
        local b = c:Connect()
        d(b:Connect())
        e(function() end, f:Connect())

        c:Connect() -- Errors
    end, {})
end

chriscerie avatar Jun 26 '23 06:06 chriscerie

Looks mostly good. Out of curiosity, and it doesn't have to, does this magically work with ReactHooks' useEffect? The one being passed through?

Yes, it will show the useEffect-specific error with useEffect(..., function() end, ...) and anything.useEffect(..., function() end, ...)

chriscerie avatar Aug 19 '23 19:08 chriscerie

To display the useEffect specific error it'll now look for the react/roact/hooks prefix per @matthargett's suggestion for a similar lint

chriscerie avatar Aug 27 '23 16:08 chriscerie