From 1a174ca7868cd3b2862863e458cd44c91d9aee1c Mon Sep 17 00:00:00 2001 From: Christopher Chang <51393127+chriscerie@users.noreply.github.com> Date: Wed, 20 Sep 2023 12:45:52 -0700 Subject: [PATCH] Add other hooks and tests --- .../lints/roblox_roact_non_exhaustive_deps.rs | 14 +++++++++- .../no_deps.lua | 9 +++++++ .../no_deps.std.yml | 2 ++ .../no_deps.stderr | 0 .../roblox_roact_non_exhaustive_deps.lua | 3 ++- .../roblox_roact_non_exhaustive_deps.stderr | 26 +++++++++---------- 6 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/no_deps.lua create mode 100644 selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/no_deps.std.yml create mode 100644 selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/no_deps.stderr diff --git a/selene-lib/src/lints/roblox_roact_non_exhaustive_deps.rs b/selene-lib/src/lints/roblox_roact_non_exhaustive_deps.rs index fa0f5124..30095ed8 100644 --- a/selene-lib/src/lints/roblox_roact_non_exhaustive_deps.rs +++ b/selene-lib/src/lints/roblox_roact_non_exhaustive_deps.rs @@ -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; } @@ -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( diff --git a/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/no_deps.lua b/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/no_deps.lua new file mode 100644 index 00000000..62df4b09 --- /dev/null +++ b/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/no_deps.lua @@ -0,0 +1,9 @@ +local React + +local function Component() + local a = {} + + React.useEffect(function() + print(a) + end) +end diff --git a/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/no_deps.std.yml b/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/no_deps.std.yml new file mode 100644 index 00000000..f434ea3e --- /dev/null +++ b/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/no_deps.std.yml @@ -0,0 +1,2 @@ +--- +name: roblox \ No newline at end of file diff --git a/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/no_deps.stderr b/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/no_deps.stderr new file mode 100644 index 00000000..e69de29b diff --git a/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/roblox_roact_non_exhaustive_deps.lua b/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/roblox_roact_non_exhaustive_deps.lua index fbfd6d5c..395d8336 100644 --- a/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/roblox_roact_non_exhaustive_deps.lua +++ b/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/roblox_roact_non_exhaustive_deps.lua @@ -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 diff --git a/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/roblox_roact_non_exhaustive_deps.stderr b/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/roblox_roact_non_exhaustive_deps.stderr index 993a5d21..d94d5621 100644 --- a/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/roblox_roact_non_exhaustive_deps.stderr +++ b/selene-lib/tests/lints/roblox_roact_non_exhaustive_deps/roblox_roact_non_exhaustive_deps.stderr @@ -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