Skip to content

Commit

Permalink
Merge branch 'roact_dangling_connection' of https://github.com/chrisc…
Browse files Browse the repository at this point in the history
…erie/selene into react-unreleased
  • Loading branch information
chriscerie committed Jan 8, 2024
2 parents 3a1a394 + 3008199 commit 8549d31
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 205 deletions.
8 changes: 7 additions & 1 deletion selene-lib/src/lints/roblox_roact_dangling_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ impl Visitor for RoactDanglingConnectionVisitor {
let last_suffix =
get_last_function_call_suffix(call.prefix(), &call.suffixes().collect::<Vec<_>>());

if !self.function_contexts.is_empty() {
// Only warn in useEffect to prevent false negatives with unrelated functions. Ideally this should also work anywhere
// in the component body. Can we detect React components better?
if self
.function_contexts
.iter()
.any(|(_, context)| *context == ConnectionContext::UseEffect)
{
if let Some(call_range) = call.range() {
if self
.dangling_connection_start_ranges
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,37 @@ local useEffect = React.useEffect

a:connect()

local function c()
local function Component()
a:Connect()
a:connect()
a:ConnectParallel()
a:Once()

a.Connect()
a.connect()
a.ConnectParallel()
a.Once()

-- Ignore since `a` might take ownership of connections
a(b:Connect())
a(function() end, b:Connect())

useEffect(function()
a:connect()
-- Ignore since `a` might take ownership of connections
a(b:Connect())
local b = a:connect()
a(function() end, b:Connect())

a:Connect()
a:connect()

a.b:Connect()
a.b:connect()

a.b.c:Connect()
a.b.c:connect()

good = a:Connect()
good = a:connect()

good = a.b:Connect()
good = a.b:connect()

good = a.b.c:Connect()
good = a.b.c:connect()
end)

React.useEffect(function()
a:connect()
a(b:Connect())
local b = a:connect()

a:connect()
end)
end
Original file line number Diff line number Diff line change
@@ -1,60 +1,42 @@
error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ roblox_roact_dangling_connection.lua:7:5
7 │ a:Connect()
│ ^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ roblox_roact_dangling_connection.lua:8:5
8 │ a:connect()
│ ^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ roblox_roact_dangling_connection.lua:9:5
9 │ a:ConnectParallel()
│ ^^^^^^^^^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ roblox_roact_dangling_connection.lua:10:5
error[roblox_roact_dangling_connection]: disconnect the connection in the useEffect cleanup function
┌─ roblox_roact_dangling_connection.lua:14:9
10a:Once()
│ ^^^^^^^^
14 a:Connect()
^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ roblox_roact_dangling_connection.lua:12:5
error[roblox_roact_dangling_connection]: disconnect the connection in the useEffect cleanup function
┌─ roblox_roact_dangling_connection.lua:15:9
12a.Connect()
│ ^^^^^^^^^^^
15 a:connect()
^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ roblox_roact_dangling_connection.lua:13:5
error[roblox_roact_dangling_connection]: disconnect the connection in the useEffect cleanup function
┌─ roblox_roact_dangling_connection.lua:17:9
13a.connect()
│ ^^^^^^^^^^^
17 a.b:Connect()
^^^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ roblox_roact_dangling_connection.lua:14:5
error[roblox_roact_dangling_connection]: disconnect the connection in the useEffect cleanup function
┌─ roblox_roact_dangling_connection.lua:18:9
14a.ConnectParallel()
^^^^^^^^^^^^^^^^^^^
18 a.b:connect()
^^^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ roblox_roact_dangling_connection.lua:15:5
error[roblox_roact_dangling_connection]: disconnect the connection in the useEffect cleanup function
┌─ roblox_roact_dangling_connection.lua:20:9
15a.Once()
│ ^^^^^^^^
20 a.b.c:Connect()
^^^^^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection in the useEffect cleanup function
┌─ roblox_roact_dangling_connection.lua:22:9
┌─ roblox_roact_dangling_connection.lua:21:9
22 │ a:connect()
│ ^^^^^^^^^^^
21 │ a.b.c:connect()
│ ^^^^^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection in the useEffect cleanup function
┌─ roblox_roact_dangling_connection.lua:28:9
┌─ roblox_roact_dangling_connection.lua:37:9
28 │ a:connect()
37 │ a:connect()
│ ^^^^^^^^^^^

Original file line number Diff line number Diff line change
@@ -1,76 +1,7 @@
local Roact = a
local Roact

a:Connect()
a.Connect()
a:connect()
a.connect()

a.b:Connect()
a.b.Connect()
a.b:connect()
a.b.connect()

a.b.c:Connect()
a.b.c.Connect()
a.b.c:connect()
a.b.c.connect()

local foo = a:Connect()
local foo = a.Connect()
local foo = a:connect()
local foo = a.connect()

foo = a:Connect()
foo = a.Connect()
foo = a:connect()
foo = a.connect()

foo = a.b:Connect()
foo = a.b.Connect()
foo = a.b:connect()
foo = a.b.connect()

foo = a.b.c:Connect()
foo = a.b.c.Connect()
foo = a.b.c:connect()
foo = a.b.c.connect()

local function c()
a:Connect()
a:connect()

a.b:Connect()
a.b:connect()

a.b.c:Connect()
a.b.c:connect()

foo = a:Connect()
foo = a:connect()

foo = a.b:Connect()
foo = a.b:connect()

foo = a.b.c:Connect()
foo = a.b.c:connect()
end

function d:e()
a:Connect()
a:connect()

a.b:Connect()
a.b:connect()

a.b.c:Connect()
a.b.c:connect()

foo = a:Connect()
foo = a:connect()

foo = a.b:Connect()
foo = a.b:connect()

foo = a.b.c:Connect()
foo = a.b.c:connect()
local function Component()
Roact.useEffect(function()
a:Connect()
end)
end
Original file line number Diff line number Diff line change
@@ -1,72 +1,6 @@
error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ with_roact.lua:39:5
39 │ a:Connect()
│ ^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ with_roact.lua:40:5
40 │ a:connect()
│ ^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ with_roact.lua:42:5
42 │ a.b:Connect()
│ ^^^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ with_roact.lua:43:5
43 │ a.b:connect()
│ ^^^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ with_roact.lua:45:5
45 │ a.b.c:Connect()
│ ^^^^^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ with_roact.lua:46:5
46 │ a.b.c:connect()
│ ^^^^^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ with_roact.lua:59:5
59 │ a:Connect()
│ ^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ with_roact.lua:60:5
60 │ a:connect()
│ ^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ with_roact.lua:62:5
62 │ a.b:Connect()
│ ^^^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ with_roact.lua:63:5
63 │ a.b:connect()
│ ^^^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ with_roact.lua:65:5
65 │ a.b.c:Connect()
│ ^^^^^^^^^^^^^^^

error[roblox_roact_dangling_connection]: disconnect the connection where appropriate
┌─ with_roact.lua:66:5
66 │ a.b.c:connect()
│ ^^^^^^^^^^^^^^^
error[roblox_roact_dangling_connection]: disconnect the connection in the useEffect cleanup function
┌─ with_roact.lua:5:9
5 │ a:Connect()
│ ^^^^^^^^^^^

0 comments on commit 8549d31

Please sign in to comment.