Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Roact dangling connection lint #533

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

chriscerie
Copy link
Collaborator

@chriscerie chriscerie commented Jun 26, 2023

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

Copy link
Owner

@Kampfkarren Kampfkarren left a comment

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?

selene-lib/src/lints/roblox_roact_dangling_connection.rs Outdated Show resolved Hide resolved
@chriscerie
Copy link
Collaborator Author

chriscerie commented Aug 19, 2023

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
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