From 30c8afb0158bdda58a67a8a89428fa73d069e232 Mon Sep 17 00:00:00 2001 From: vndre Date: Thu, 11 Feb 2021 11:58:26 -0600 Subject: [PATCH 1/4] create: gitignore file --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..960be9a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +package-lock.json +yarn.lock \ No newline at end of file From 77063cbc959f6d87546bec76f69fcd40b2368a92 Mon Sep 17 00:00:00 2001 From: vndre Date: Thu, 11 Feb 2021 11:59:00 -0600 Subject: [PATCH 2/4] add: eslint-plugin-react-hooks --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 39ddf19..b93f58a 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "devDependencies": { "eslint": "^7.12.1", "eslint-plugin-react": "^7.21.5", + "eslint-plugin-react-hooks": "^4.2.0", "tape": "^5.0.1" }, "homepage": "https://github.com/feross/eslint-config-standard-react", From d0cca0d34bfb9bc9c53eec7ac6d6561c69f13d08 Mon Sep 17 00:00:00 2001 From: vndre Date: Thu, 11 Feb 2021 11:59:34 -0600 Subject: [PATCH 3/4] add: react-hooks plugin to config --- eslintrc.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/eslintrc.json b/eslintrc.json index 45f3b02..ab1f471 100644 --- a/eslintrc.json +++ b/eslintrc.json @@ -14,7 +14,8 @@ }, "plugins": [ - "react" + "react", + "react-hooks" ], "rules": { @@ -27,6 +28,8 @@ "react/no-unknown-property": "error", "react/no-unused-prop-types": "error", "react/prop-types": "error", - "react/react-in-jsx-scope": "error" + "react/react-in-jsx-scope": "error", + "react-hooks/rules-of-hooks": "error", + "react-hooks/exhaustive-deps": "error" } } From a798b76c443c38684f0db32e93bcc4c2f85263e5 Mon Sep 17 00:00:00 2001 From: vndre Date: Thu, 11 Feb 2021 11:59:42 -0600 Subject: [PATCH 4/4] update: tests --- TestComponent.jsx | 20 ++++++++++++++++++++ test/validate-config.js | 17 ++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 TestComponent.jsx diff --git a/TestComponent.jsx b/TestComponent.jsx new file mode 100644 index 0000000..bf91d1f --- /dev/null +++ b/TestComponent.jsx @@ -0,0 +1,20 @@ +import React, { useEffect, useState } from 'react' +import { string } from 'prop-types' + +const Component = ({ someProp }) => { + const [state, setState] = useState() + + useEffect(() => { + if (someProp) { + setState(someProp) + } + }, [someProp]) + + return

{state}

+} + +Component.propTypes = { + someProp: string +} + +export default Component diff --git a/test/validate-config.js b/test/validate-config.js index 39c7ce9..d5395af 100644 --- a/test/validate-config.js +++ b/test/validate-config.js @@ -1,16 +1,15 @@ -const eslint = require('eslint') +const { ESLint } = require('eslint') const test = require('tape') +const config = require('../eslintrc.json') +const path = require('path') -test('load config in eslint to validate all rule syntax is correct', function (t) { - const CLIEngine = eslint.CLIEngine - - const cli = new CLIEngine({ +test('load config in eslint to validate all rule syntax is correct', async function (t) { + const eslint = new ESLint({ useEslintrc: false, - configFile: 'eslintrc.json' + baseConfig: config }) + const results = await eslint.lintFiles(path.resolve(__dirname, '../TestComponent.jsx')) - const code = 'var foo = 1\nvar bar = function () {}\nbar(foo)\n' - - t.equal(cli.executeOnText(code).errorCount, 0) + t.equal(results[0].errorCount, 0) t.end() })