Skip to content

Commit

Permalink
Add other hooks and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscerie committed Sep 20, 2023
1 parent db9b0f4 commit 1a174ca
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
14 changes: 13 additions & 1 deletion selene-lib/src/lints/roblox_roact_non_exhaustive_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,10 @@ impl Visitor for RoactMissingDependencyVisitor<'_> {
_ => return,
};

if !["useEffect", "useMemo"].contains(&last_suffix.as_str()) || !is_roact_function(call) {
if !["useEffect", "useMemo", "useCallback", "useLayoutEffect"]
.contains(&last_suffix.as_str())
|| !is_roact_function(call)
{
return;
}

Expand Down Expand Up @@ -616,6 +619,15 @@ mod tests {
);
}

#[test]
fn test_no_deps() {
test_lint(
RoactNonExhaustiveDepsLint::new(()).unwrap(),
"roblox_roact_non_exhaustive_deps",
"no_deps",
);
}

#[test]
fn test_no_roact() {
test_lint(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local React

local function Component()
local a = {}

React.useEffect(function()
print(a)
end)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
name: roblox
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ local React

local notreactive1 = {}

local function Component1()
local function Component1(props)
local reactive1 = {}
local reactive2 = {}

React.useEffect(function()
local allowed = notreactive1
local notallowed = reactive1
local notallowed = props
print(reactive2)
end, {})
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
error[roblox_roact_non_exhaustive_deps]: react hook useEffect has missing dependencies: 'reactive1' and 'reactive2'
┌─ roblox_roact_non_exhaustive_deps.lua:13:10
error[roblox_roact_non_exhaustive_deps]: react hook useEffect has missing dependencies: 'props', 'reactive1', and 'reactive2'
┌─ roblox_roact_non_exhaustive_deps.lua:14:10
13 │ end, {})
14 │ end, {})
│ ^^
= help: either include them or remove the dependency array

error[roblox_roact_non_exhaustive_deps]: react hook useEffect has missing dependency: 'reactive2'
┌─ roblox_roact_non_exhaustive_deps.lua:30:10
┌─ roblox_roact_non_exhaustive_deps.lua:31:10
30 │ end, depArray(reactive1))
31 │ end, depArray(reactive1))
│ ^^^^^^^^^^^^^^^^^^^
= help: either include it or remove the dependency array

error[roblox_roact_non_exhaustive_deps]: react hook useEffect has missing dependency: 'reactive1'
┌─ roblox_roact_non_exhaustive_deps.lua:43:10
┌─ roblox_roact_non_exhaustive_deps.lua:44:10
43 │ end, {})
44 │ end, {})
│ ^^
= help: either include it or remove the dependency array

error[roblox_roact_non_exhaustive_deps]: react hook useEffect has unnecessary dependencies: 'error' and 'notreactive1'
┌─ roblox_roact_non_exhaustive_deps.lua:47:37
┌─ roblox_roact_non_exhaustive_deps.lua:48:37
47 │ React.useEffect(function() end, { error, notreactive1 })
48 │ React.useEffect(function() end, { error, notreactive1 })
│ ^^^^^^^^^^^^^^^^^^^^^^^
= help: either exclude them or remove the dependency array
= outer scope variables like 'error' aren't valid dependencies because mutating them doesn't re-render the component

error[roblox_roact_non_exhaustive_deps]: react hook useEffect has missing dependency: 'reactive1'
┌─ roblox_roact_non_exhaustive_deps.lua:55:10
┌─ roblox_roact_non_exhaustive_deps.lua:56:10
55 │ end, { notreactive1 })
56 │ end, { notreactive1 })
│ ^^^^^^^^^^^^^^^^
= help: either include it or remove the dependency array

error[roblox_roact_non_exhaustive_deps]: react hook useEffect has unnecessary dependency: 'notreactive1'
┌─ roblox_roact_non_exhaustive_deps.lua:55:10
┌─ roblox_roact_non_exhaustive_deps.lua:56:10
55 │ end, { notreactive1 })
56 │ end, { notreactive1 })
│ ^^^^^^^^^^^^^^^^
= help: either exclude it or remove the dependency array
Expand Down

0 comments on commit 1a174ca

Please sign in to comment.