Skip to content

Add Roact dangling connection lint#533

Open
chriscerie wants to merge 28 commits into
Kampfkarren:mainfrom
chriscerie:roact_dangling_connection
Open

Add Roact dangling connection lint#533
chriscerie wants to merge 28 commits into
Kampfkarren:mainfrom
chriscerie:roact_dangling_connection

Conversation

@chriscerie

@chriscerie chriscerie commented Jun 26, 2023

Copy link
Copy Markdown
Collaborator

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

@Kampfkarren Kampfkarren left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread selene-lib/src/lints/roblox_roact_dangling_connection.rs Outdated
@chriscerie

chriscerie commented Aug 19, 2023

Copy link
Copy Markdown
Collaborator Author

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

Copy link
Copy Markdown
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling :Connect as a statement in a Roact component should lint

2 participants