Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react): add hooks rules #118

Merged
merged 2 commits into from Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -100,7 +100,7 @@ module.exports = {

**terminal**
```sh
yarn add eslint-plugin-react --dev
yarn add eslint-plugin-react eslint-plugin-react-hooks --dev
```

**.eslintrc.js**
Expand Down Expand Up @@ -139,7 +139,7 @@ module.exports = {

**terminal**
```sh
yarn add eslint-plugin-flowtype eslint-plugin-react --dev
yarn add eslint-plugin-flowtype eslint-plugin-react eslint-plugin-react-hooks --dev
```

**.eslintrc.js**
Expand Down Expand Up @@ -189,7 +189,7 @@ module.exports = {

**terminal**
```sh
yarn add @typescript-eslint/parser @typescript-eslint/eslint-plugin typescript eslint-plugin-react --dev
yarn add @typescript-eslint/parser @typescript-eslint/eslint-plugin typescript eslint-plugin-react eslint-plugin-react-hooks --dev
```

**.eslintrc.js**
Expand Down
2 changes: 1 addition & 1 deletion react.js
Expand Up @@ -6,5 +6,5 @@ module.exports = {
'./base.js',
'prettier/react',
],
plugins: ['react'],
plugins: ['react', 'react-hooks'],
};
2 changes: 2 additions & 0 deletions rules/react.js
Expand Up @@ -10,5 +10,7 @@ module.exports = {
allowArrowFunctions: true,
},
],
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
},
};
1 change: 1 addition & 0 deletions sample-project/package.json
Expand Up @@ -25,6 +25,7 @@
"eslint-plugin-jest": "21.27.2",
"eslint-plugin-prettier": "2.7.0",
"eslint-plugin-react": "7.7.0",
"eslint-plugin-react-hooks": "2.1.2",
"prettier": "1.18.2"
}
}
18 changes: 18 additions & 0 deletions sample-project/src/Component.js
@@ -0,0 +1,18 @@
import React, { useEffet } from 'react';
import PropTypes from 'prop-types';

export function Component({ value }) {
// Wrapping the effect with a condition triggers the ESLint plugin `react-hooks`
useEffet(() => {});

return (
<div>
<h1>React app</h1>
<p>{value}</p>
</div>
);
}

Component.propTypes = {
value: PropTypes.string,
};
5 changes: 5 additions & 0 deletions sample-project/yarn.lock
Expand Up @@ -463,6 +463,11 @@ eslint-plugin-prettier@2.7.0:
fast-diff "^1.1.1"
jest-docblock "^21.0.0"

eslint-plugin-react-hooks@2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-2.1.2.tgz#1358d2acb2c5e02b7e90c37e611ac258a488e3a7"
integrity sha512-ZR+AyesAUGxJAyTFlF3MbzeVHAcQTFQt1fFVe5o0dzY/HFoj1dgQDMoIkiM+ltN/HhlHBYX4JpJwYonjxsyQMA==

eslint-plugin-react@7.7.0:
version "7.7.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.7.0.tgz#f606c719dbd8a1a2b3d25c16299813878cca0160"
Expand Down