From 68a6315626eb4c8b98c4a442eceb11807c253c44 Mon Sep 17 00:00:00 2001 From: mabashian Date: Mon, 11 Nov 2019 14:56:25 -0500 Subject: [PATCH] Adds react-hooks eslint rules and fixes a few warnings --- awx/ui_next/.eslintrc | 7 ++++++- .../components/CollapsibleSection/ExpandingContainer.jsx | 2 +- awx/ui_next/src/screens/Job/JobOutput/HostEventModal.jsx | 2 +- awx/ui_next/src/screens/Project/shared/ProjectForm.jsx | 2 +- awx/ui_next/src/screens/Template/shared/LabelSelect.jsx | 2 +- awx/ui_next/src/screens/Template/shared/PlaybookSelect.jsx | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/awx/ui_next/.eslintrc b/awx/ui_next/.eslintrc index c22e9fa16d..367f465aa6 100644 --- a/awx/ui_next/.eslintrc +++ b/awx/ui_next/.eslintrc @@ -8,6 +8,9 @@ "modules": true } }, + "plugins": [ + "react-hooks" + ], "extends": ["airbnb", "prettier", "prettier/react"], "settings": { "import/resolver": { @@ -56,6 +59,8 @@ "react/prop-types": "off", "react/sort-comp": ["error", {}], "jsx-a11y/label-has-for": "off", - "jsx-a11y/label-has-associated-control": "off" + "jsx-a11y/label-has-associated-control": "off", + "react-hooks/rules-of-hooks": "error", + "react-hooks/exhaustive-deps": "warn" } } diff --git a/awx/ui_next/src/components/CollapsibleSection/ExpandingContainer.jsx b/awx/ui_next/src/components/CollapsibleSection/ExpandingContainer.jsx index 5d8c91ef0d..35804d324d 100644 --- a/awx/ui_next/src/components/CollapsibleSection/ExpandingContainer.jsx +++ b/awx/ui_next/src/components/CollapsibleSection/ExpandingContainer.jsx @@ -19,7 +19,7 @@ function ExpandingContainer({ isExpanded, children }) { }); useEffect(() => { setContentHeight(ref.current.scrollHeight); - }); + }, [setContentHeight]); const height = isExpanded ? contentHeight : '0'; return ( { setHostStatus(processEventStatus(hostEvent)); - }, []); + }, [setHostStatus, hostEvent]); const handleTabClick = (event, tabIndex) => { setActiveTabKey(tabIndex); diff --git a/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx b/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx index e1757f4002..fed39b72b4 100644 --- a/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx +++ b/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx @@ -108,7 +108,7 @@ function ProjectForm({ project, ...props }) { } fetchData(); - }, []); + }, [summary_fields.credential]); const scmFormFields = { scm_url: '', diff --git a/awx/ui_next/src/screens/Template/shared/LabelSelect.jsx b/awx/ui_next/src/screens/Template/shared/LabelSelect.jsx index 3443aeb3b4..68cce85193 100644 --- a/awx/ui_next/src/screens/Template/shared/LabelSelect.jsx +++ b/awx/ui_next/src/screens/Template/shared/LabelSelect.jsx @@ -33,7 +33,7 @@ function LabelSelect({ value, onChange, onError }) { const [options, setOptions] = useState([]); useEffect(() => { loadLabelOptions(setOptions, onError); - }, []); + }, [onError]); return (