From 8bc88c0208fb45ef3c32479e0f0f13efd52f0e62 Mon Sep 17 00:00:00 2001 From: Deland Date: Tue, 5 Jul 2022 16:44:31 +0800 Subject: [PATCH] feat: add eslint-plugin-react-hooks --- .eslintrc.js | 6 +++++- package.json | 1 + src/components/Home/RecoilDemo.tsx | 2 +- src/components/Home/index.tsx | 1 - yarn.lock | 14 ++++++-------- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9bfc75f..88e8d50 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -8,7 +8,7 @@ module.exports = { 'jsx': true, }, }, - plugins: ['react', 'import', '@typescript-eslint'], + plugins: ['react', 'import', '@typescript-eslint', 'react-hooks'], env: { 'browser': true, 'node': true, @@ -43,6 +43,10 @@ module.exports = { ], 'import/no-unresolved': 2, + // react hook rules + 'react-hooks/rules-of-hooks': 2, + 'react-hooks/exhaustive-deps': 2, + // ECMAScript rules 'accessor-pairs': 'warn', 'array-bracket-newline': ['warn', {'multiline': true}], diff --git a/package.json b/package.json index f2ac2ec..38778f9 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "eslint-plugin-babel": "^5.3.1", "eslint-plugin-import": "^2.22.1", "eslint-plugin-react": "^7.7.0", + "eslint-plugin-react-hooks": "^4.6.0", "eslint-rich-reporter": "^0.0.10", "eslint-webpack-plugin": "^3.1.1", "extract-text-webpack-plugin": "^4.0.0-beta.0", diff --git a/src/components/Home/RecoilDemo.tsx b/src/components/Home/RecoilDemo.tsx index b17052d..75c4ee7 100644 --- a/src/components/Home/RecoilDemo.tsx +++ b/src/components/Home/RecoilDemo.tsx @@ -33,7 +33,7 @@ const RecoilDemo = () => { e => { setFilter(e.target.value); }, - [] + [setFilter] ); return ( diff --git a/src/components/Home/index.tsx b/src/components/Home/index.tsx index 3e1a7c5..b041963 100644 --- a/src/components/Home/index.tsx +++ b/src/components/Home/index.tsx @@ -6,7 +6,6 @@ import {FC, useEffect, useCallback, useState} from 'react'; import {Button} from 'antd'; import {useCurrentUser, useActions} from '@/hooks'; import {fetchUserInfo} from '@/actions'; -import {apiGetTest} from '@/apis'; import ConcurrentDemo from './ConcurrentDemo'; import RecoilDemo from './RecoilDemo'; import styles from './index.less'; diff --git a/yarn.lock b/yarn.lock index 0d6533e..ce43ef0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3575,20 +3575,13 @@ copy-descriptor@^0.1.0: resolved "https://registry.npm.taobao.org/copy-descriptor/download/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40= -copy-to-clipboard@^3.2.0: +copy-to-clipboard@^3.2.0, copy-to-clipboard@^3.3.1: version "3.3.1" resolved "https://registry.npm.taobao.org/copy-to-clipboard/download/copy-to-clipboard-3.3.1.tgz#115aa1a9998ffab6196f93076ad6da3b913662ae" integrity sha1-EVqhqZmP+rYZb5MHatbaO5E2Yq4= dependencies: toggle-selection "^1.0.6" -copy-to-clipboard@^3.3.1: - version "3.3.1" - resolved "https://registry.npmmirror.com/copy-to-clipboard/-/copy-to-clipboard-3.3.1.tgz#115aa1a9998ffab6196f93076ad6da3b913662ae" - integrity sha512-i13qo6kIHTTpCm8/Wup+0b1mVWETvu2kIMzKoK8FpkLkFxlt0znUAHcMzox+T8sPlqtZXq3CulEjQHsYiGFJUw== - dependencies: - toggle-selection "^1.0.6" - core-js-compat@^3.6.2: version "3.6.5" resolved "https://registry.npm.taobao.org/core-js-compat/download/core-js-compat-3.6.5.tgz#2a51d9a4e25dfd6e690251aa81f99e3c05481f1c" @@ -4478,6 +4471,11 @@ eslint-plugin-import@^2.22.1: resolve "^1.17.0" tsconfig-paths "^3.9.0" +eslint-plugin-react-hooks@^4.6.0: + version "4.6.0" + resolved "https://registry.npmmirror.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz#4c3e697ad95b77e93f8646aaa1630c1ba607edd3" + integrity sha512-oFc7Itz9Qxh2x4gNHStv3BqJq54ExXmfC+a1NjAta66IAN87Wu0R/QArgIS9qKzX3dXKPI9H5crl9QchNMY9+g== + eslint-plugin-react@^7.7.0: version "7.19.0" resolved "https://registry.npm.taobao.org/eslint-plugin-react/download/eslint-plugin-react-7.19.0.tgz#6d08f9673628aa69c5559d33489e855d83551666"