From 25a246b6ae4bec3718efe3686400dfa9044749ca Mon Sep 17 00:00:00 2001 From: Runo Saduwa Date: Thu, 27 Feb 2020 01:20:55 +0100 Subject: [PATCH] Tools: Resolves #2579: Add support for Rule of Hooks plugin (#2579) (#2585) * installed eslint-plugin-react-hooks and set up rules of hooks * fixed linter error * changed react-hooks/exhaustive-deps option to error * changed spaces to tabs in eslint config --- .eslintrc.js | 6 ++++++ ElectronClient/gui/NoteContentPropertiesDialog.tsx | 2 +- package-lock.json | 6 ++++++ package.json | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 934e5dc864..6d25e87a46 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -53,6 +53,11 @@ module.exports = { // possible race conditions in contexts where we know it cannot happen. "require-atomic-updates": 0, + // Checks rules of Hooks + "react-hooks/rules-of-hooks": "error", + // Checks effect dependencies + "react-hooks/exhaustive-deps": "error", + // ------------------------------- // Formatting // ------------------------------- @@ -90,5 +95,6 @@ module.exports = { "plugins": [ "react", "@typescript-eslint", + "react-hooks" ], }; diff --git a/ElectronClient/gui/NoteContentPropertiesDialog.tsx b/ElectronClient/gui/NoteContentPropertiesDialog.tsx index a0cbb9b5ae..0e4c58477f 100644 --- a/ElectronClient/gui/NoteContentPropertiesDialog.tsx +++ b/ElectronClient/gui/NoteContentPropertiesDialog.tsx @@ -34,7 +34,7 @@ export default function NoteContentPropertiesDialog(props:NoteContentPropertiesD setCharactersNoSpace(counter.characters); }); setLines(props.text.split('\n').length); - }, []); + }, [props.text]); const textProperties: TextPropertiesMap = { lines: lines, diff --git a/package-lock.json b/package-lock.json index cbb706b019..d1087c0f43 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1695,6 +1695,12 @@ } } }, + "eslint-plugin-react-hooks": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-2.4.0.tgz", + "integrity": "sha512-bH5DOCP6WpuOqNaux2BlaDCrSgv8s5BitP90bTgtZ1ZsRn2bdIfeMDY5F2RnJVnyKDy6KRQRDbipPLZ1y77QtQ==", + "dev": true + }, "eslint-scope": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.0.0.tgz", diff --git a/package.json b/package.json index 4470f4d3e1..ff06e7625e 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@typescript-eslint/parser": "^2.10.0", "eslint": "^6.1.0", "eslint-plugin-react": "^7.18.0", + "eslint-plugin-react-hooks": "^2.4.0", "fs-extra": "^8.1.0", "glob": "^7.1.6", "gulp": "^4.0.2",